Re: compile warning

From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Postgresql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: compile warning
Date: 2003-10-10 20:39:34
Message-ID: 3F871906.3090101@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2003-10-10 21:34:53 Foreign Key bug -- 7.4b4
Previous Message Bruce Momjian 2003-10-10 19:43:44 Re: [Fwd: [Python-Dev] HP Test Drive systems]