On Mon, 19 Mar 2007, Matthew R. Dempsky wrote:

> On Mon, Mar 19, 2007 at 09:55:04PM -0400, Paul D. Ouderkirk wrote:
> > And because I love to reply to myself, if I compile it with -O3, I can
> > reproduce your results:
> 
> -O3 enables -fstrict-aliasing, which this program violates.  The man
> page explains in more detail.

Yep, it's a bit sad to see all the attempts at explaining the bug. But
this one hits the mark.

Additionally, while stock gcc enables -fstrict-aliasing with -O2, on
OpenBSD -fstrict-aliasing is not enabled with -O2, since experience
shows violations of pointer aliasing rules are seen a lot in the wild.

See man gcc-local:

-   The -O2 option does not include -fstrict-aliasing, as this option
    causes issues on some legacy code.  -fstrict-aliasing is very unsafe
    with code that plays tricks with casts, bypassing the already weak
    type system of C.

So don't play tricks like that unless you really understand the issues
involved. 

        -Otto

Reply via email to