Re: warning: dereferencing type-punned pointer - Mailing list pgsql-hackers

From Tom Lane
Subject Re: warning: dereferencing type-punned pointer
Date
Msg-id 1256314.1721845785@sss.pgh.pa.us
Whole thread Raw
In response to Re: warning: dereferencing type-punned pointer  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
BTW, I tried the same experiment of building without
-fno-strict-aliasing using gcc 11.4.1 (from RHEL9).
I see one more warning than Tatsuo-san did:

In file included from verify_heapam.c:18:
verify_heapam.c: In function ‘check_tuple_attribute’:
../../src/include/access/toast_internals.h:37:11: warning: dereferencing type-punned pointer will break strict-aliasing
rules[-Wstrict-aliasing] 
   37 |         (((toast_compress_header *) (ptr))->tcinfo >> VARLENA_EXTSIZE_BITS)
      |          ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
verify_heapam.c:1693:24: note: in expansion of macro ‘TOAST_COMPRESS_METHOD’
 1693 |                 cmid = TOAST_COMPRESS_METHOD(&toast_pointer);
      |                        ^~~~~~~~~~~~~~~~~~~~~

This looks a bit messy to fix: we surely don't want to pierce
the abstraction TOAST_COMPRESS_METHOD provides.  Perhaps
the toast_pointer local variable could be turned into a union
of struct varatt_external and toast_compress_header, but that
would impose a good deal of notational overhead on the rest
of this function.

The good news is that we get through check-world (although
I didn't try very many build options).

            regards, tom lane



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: warning: dereferencing type-punned pointer
Next
From: Tom Lane
Date:
Subject: Re: warning: dereferencing type-punned pointer