Re: strict aliasing (was: const correctness)

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: strict aliasing (was: const correctness)
Дата
Msg-id 201111150028.03040.andres@anarazel.de
обсуждение исходный текст
Ответ на Re: strict aliasing (was: const correctness)  (Alvaro Herrera <alvherre@commandprompt.com>)
Список 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@sss.pgh.pa.us> wrote:
> > > "Kevin Grittner" <Kevin.Grittner@wicourts.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ross Reedstrom
Дата:
Сообщение: Re: feature request: auto savepoint for interactive psql when in transaction.
Следующее
От: Andres Freund
Дата:
Сообщение: Re: strict aliasing (was: const correctness)