Re: strict aliasing (was: const correctness)

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Kevin Grittner <kevin(dot)grittner(at)wicourts(dot)gov>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Thomas Munro <munro(at)ip9(dot)org>, Florian Pflug <fgp(at)phlo(dot)org>
Subject: Re: strict aliasing (was: const correctness)
Date: 2011-11-14 23:28:02
Message-ID: 201111150028.03040.andres@anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Monday, November 14, 2011 10:25:19 PM Alvaro Herrera wrote:
> Excerpts from Kevin Grittner's message of lun nov 14 17:30:50 -0300 2011:
> > Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > > "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> writes:
> > >> Also, is there something I should do to deal with the warnings
> > >> before this would be considered a meaningful test?
> > >
> > > Dunno ... where were the warnings exactly?
> >
> > All 10 were like this:
> > warning: dereferencing type-punned pointer will break
> >
> > strict-aliasing rules
>
> Uhm, shouldn't we expect there to be one warning for each use of a Node
> using some specific node pointer type as well as something generic such
> as inside a ListCell etc?
The case with Node's being accessed by SomethingNode is legal to my knowledge
as the individual memory locations are accessed by variables of the same type.
That follows from the rules "an aggregate or union type that includes one of
the aforementioned types among its members (including, recursively, a member
of a subaggregate or contained union)" and "a type compatible with the
effective type of the object".

And the ListCell case is ok as well unless there is a wrong cast in code using
the ListCell somewhere.

E.g. its afaics safe to do something like:

void do_something_int(int);

int bla;
void* foo = &bla;
...
do_something_int(*(int*)foo);

but

do_something_short(*(short*)foo);
is illegal.

The compiler obviously cant be able to prove all misusage of the void*
pointers in e.g. ListCell's though...

Andres

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2011-11-14 23:33:13 Re: strict aliasing (was: const correctness)
Previous Message Ross Reedstrom 2011-11-14 23:05:20 Re: feature request: auto savepoint for interactive psql when in transaction.