aliasing issue after automatic inlining

Ian Lance Taylor iant@google.com
Wed Apr 20 14:58:00 GMT 2011


"Felix J. Ogris" <fjo-lists@ogris.de> writes:

> On Apr 20, 2011, at 2:29 AM, Ian Lance Taylor wrote:
>
> [...]
>
>> This code is accessing values of type int using a pointer of type
>> short*.  That is invalid aliasing and your program uses undefined
>> behaviour.  Your suggested workarounds are the right one.
>> 
>> To get a warning, you could try the -Wstrict-aliasing option.  I don't
>> think it exists in gcc 4.2, though.
>
> I tried with -Wstrict-aliasing, -Wstrict-aliasing=1..2 and -Wstrict-aliasing=3 with gcc 4.6, but didn't get a warning. This is a little bit annoying as it just happens after the implicit optimization/inlining. Declaring struct s as volatile or compiling with -fno-inline-functions helps, too. However, I'll stick with -fno-strict-aliasing.

I'm sorry that -Wstrict-aliasing does not detect this case.  You may
want to report that as a bug.

For your program, you could also consider rewriting it in valid C.

Ian



More information about the Gcc-help mailing list