Re: compile warning

Поиск
Список
Период
Сортировка
От Manfred Spraul
Тема Re: compile warning
Дата
Msg-id 3F871906.3090101@colorfullife.com
обсуждение исходный текст
Ответ на Re: compile warning  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
Andrew Dunstan wrote:

> Bruce Momjian wrote:
>
>> This seems to be a bug in gcc-3.3.1.  -fstrict-aliasing is enabled by
>> -O2 or higher optimization in gcc 3.3.1.
>
According to the C standard, it's illegal to access a data with a 
pointer of the wrong type. The only exception is "char *".
This can be used by compilers to pipeline loops, or to reorder instructions.
For example

void dummy(double *out, int *in, int len)
{   int j;   for (j=0;j<len;j++)      out[j] = 1.0/in[j];
}

Can be pipelined if a compiler relies on strict aliasing: it's 
guaranteed that writing to out[5] won't overwrite in[6].

I think MemSet violates strict aliasing: it writes to the given address 
with (int32*). gcc might move the instructions around.
I would disable strict aliasing with -fno-strict-aliasing.

>   In the Linux kernel, you can see this in include/linux/tcp.h:
>
>    /*
>     *  The union cast uses a gcc extension to avoid aliasing problems
>     *  (union is compatible to any of its members)
>     *  This means this part of the code is -fstrict-aliasing safe now.
>     */

The kernel is still compiled with -fno-strict-aliasing - I'm not sure if 
there are outstanding problems, or if it's just a safety precaution.

--   Manfred



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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [Fwd: [Python-Dev] HP Test Drive systems]
Следующее
От: Rod Taylor
Дата:
Сообщение: Foreign Key bug -- 7.4b4