public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions
@ 2005-07-26 23:52 Harald van Dijk
  2005-07-27  2:37 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Harald van Dijk @ 2005-07-26 23:52 UTC (permalink / raw)
  To: gcc-help

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-07-27 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-26 23:52 -fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions Harald van Dijk
2005-07-27  2:37 ` Ian Lance Taylor
2005-07-27 21:17   ` Harald van Dijk
2005-07-27 22:23     ` Ian Lance Taylor
2005-07-27 23:53       ` Harald van Dijk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).