-fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

int main() {
    int a = 1;
    short *b = (short *) (char *) &a;
    *b = 2;
    return a;
}

This simple program returns 1 when compiled with -O2 -fstrict-aliasing, and 2 when compiled with -O2 -fno-strict-aliasing. It does not produce any warnings with -Wstrict-aliasing=2. According to the documentation:

`-Wstrict-aliasing=2'
     This option is only active when `-fstrict-aliasing' is active.  It
     warns about all code which might break the strict aliasing rules
     that the compiler is using for optimization.  This warning catches
     all cases, but it will also give a warning for some ambiguous
     cases that are safe.

Is this a bug? If so, what is the bug? Is the warning missing, or is the optimization invalid? And are there any alternative options that really catch every aliasing problem?

I'm using gcc 4.0.1 on i686-pc-linux-gnu.

Thanks in advance for any replies.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux