Re: Detecting pointer misalignment (was Re: pgsql: Implementation of subscripting for jsonb)

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>, Alexander Korotkov <akorotkov@postgresql.org>, pgsql-hackers@lists.postgresql.org
Date: 2021-02-08T16:49:41Z
Lists: pgsql-hackers

Attachments

I wrote:
> After digging in gcc's release history, it seems they invented
> "-fsanitize=alignment" in GCC 5, so we can make this work for gcc
> by writing
> #if __GNUC__ >= 5
> (the likely() macro already uses a similar approach).  Can't say
> if that's close enough for clang too.

Ugh, no it isn't: even pretty recent clang releases only define
__GNUC__ as 4.  It looks like we need a separate test on clang's
version.  I looked at their version history and sanitizers seem
to have come in around clang 7, so I propose the attached (where
I worked a bit harder on the comment, too).

			regards, tom lane

Commits

  1. pg_attribute_no_sanitize_alignment() macro

  2. Tweak compiler version cutoff for no_sanitize("alignment") support.

  3. Implementation of subscripting for jsonb