Subject: Re: i386: miscompilaton or bogus C source?
To: Simon Burge <>
From: Todd Whitesel <>
List: tech-toolchain
Date: 06/08/1999 21:25:43
>Is this something that goes away without optimisation?  I had a case where some
>code was casting between two types, and this was the reply I got from egcs-bugs
> 	> It is incorrect to access the same hunk of memory using
> 	> different types like this.  Put them in an union or access
> 	> them with char * or void * pointers.

I think their reply is a little obtuse. We're trying to migrate to EGCS at
work and have begun educating the device driver folks about this issue:

Recent EGCS wants to do a lot more load/store optimization, and in doing so
they've decided to take advantage of the ANSI decree that dereferencing
casted pointers is really an implementation-defined operation.

I believe that casting to/from characters is okay, but casting between short
and larger types is dangerous, and will yield totally mangled code if the
optimizer level is high enough (either -O or -O2, forget which).

As a workaround there is supposed to be a new option -fno-strict-align or
something like that which gets back the old, less optimized but working code.

Behavior of storing through unions is also implementation defined, but the
gcc implementation definition of it is what we'd expect. So to the extent
that we can make our code less non-portable by using unions, I think it'd
be a good idea.

What worries me is all the anonymous buffer throwing that happens in the
various kernel layers, though it uses char * or void * and thus should be
protected. If anyone notices evidence that egcs is breaking that code, we
need to get the egcs folks on the horn, pronto, and work something out.

Todd Whitesel
toddpw @