Subject: Re: gcc optimizer bug in netbsd-1-6 on alpha (gcc 2.95.3 20010315 (release) (NetBSD nb3))
To: Martin Husemann <email@example.com>
From: David Laight <firstname.lastname@example.org>
Date: 08/15/2003 15:37:28
On Fri, Aug 15, 2003 at 08:27:56AM +0200, Martin Husemann wrote:
> On Thu, Aug 14, 2003 at 02:40:22PM -0400, Greg A. Woods wrote:
> > unsigned long inet = 0; /* an IPv4 address */
> > printf("parse_address(): inet addr given: [%s]\n",
> > inet_ntoa(*((struct in_addr *) &inet)));
> Example (on sparc64, gcc 3.3.1, with inet = 0 replaced by
> inet = 0x0102030405060708):
> Compiled with -O (does not include -fstrict-alias):
> parse_address(): inet addr given: [126.96.36.199]
> Compiled with -O2:
> parse_address(): inet addr given: [188.8.131.52]
> This is *not* a compiler bug. According to the C standard you are invoking
> undefined behaviour.
I suspexcct what is hapening is that specifying '&inet' isn't enough to
cause the assignment 'inet = 0x0102030405060708;' to happen.
I'd say this is a bug! regardless of the presence of the cast.
The rule about strict-aliasing is there to alow compilers to track
values across assignments that use pointers, otherwise all tracked
values (except auto variables whose address is never taken) have to be
flushed and discarded every time a write is done via a pointer.
extern int a;
a = 1;
*p = 0
if (a) ...
the compiler must re-read 'a' because '*p' might reference 'a'.
gcc is goint OTT.
David Laight: email@example.com