Re: warning: dereferencing type-punned pointer

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

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: Tatsuo Ishii <ishii@postgresql.org>, pgsql-hackers@postgresql.org
Date: 2024-07-24T18:09:49Z
Lists: pgsql-hackers
Peter Eisentraut <peter@eisentraut.org> writes:
> On 24.07.24 16:05, Tom Lane wrote:
>> I'm not very thrilled with these changes.  It's not apparent why
>> your compiler is warning about these usages of IsA and not any other
>> ones,

> I think one difference is that normally IsA is called on a Node * (since 
> you call IsA to decide what to cast it to), but in this case it's called 
> on a pointer that is already of type ErrorSaveContext *.

Hmm.  But there are boatloads of places where we call IsA on a
pointer of type Expr *, or sometimes other things.  Why aren't
those triggering the same warning?

> I think here you could just bypass the SOFT_ERROR_OCCURRED macro:
> -       if (SOFT_ERROR_OCCURRED(&jsestate->escontext))
> +       if (jsestate->escontext.error_occurred)

Perhaps.  That's a bit sad because it's piercing a layer of
abstraction.  I do not like compiler warnings that can't be
gotten rid of without making the code objectively worse.

			regards, tom lane



Commits

  1. Fix a strict aliasing violation

  2. Add input function for data type pg_ndistinct