Bug 38537 - -fstrict-aliasing and -Wstrict-aliasing do not work
Summary: -fstrict-aliasing and -Wstrict-aliasing do not work
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2008-12-15 23:52 UTC by Nina Evseenko
Modified: 2012-02-02 18:04 UTC (History)
2 users (show)

See Also:
Host: x86_64
Target: x86_64
Build: x86_64-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2012-02-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nina Evseenko 2008-12-15 23:52:03 UTC
It seems that -fstring-aliasing option doesn't work:

$ cat test.c

#include <stdlib.h>
int
main (void)
{
  int a = 0x12345678;
  short *b = (short *) &a;
  b[1] = 0;
  if (a == 0x12345678)
      abort();
  exit(0);
}




$ gcc -fstrict-aliasing test.c
$ ./a.out
$ gcc -O2 test.c
$  ./a.out 
Aborted


There are no any warnings with -Wstrict-analising=3 for the testcase above:

$ gcc -Wstrict-aliasing=3 test.c
$


These options are tested for:

 gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)


gcc34 -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)
Comment 1 Andrew Pinski 2008-12-15 23:54:20 UTC
-fstring-aliasing is only used when optimizing ..
Comment 2 Andrew Pinski 2008-12-15 23:55:51 UTC
On the trunk we do get a warning:
t.c: In function ‘main’:
t.c:7: warning: dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules
t.c:7: note: initialized from here

Though it seems like the warning itself could be improved.
Comment 3 Andrew Pinski 2008-12-15 23:57:58 UTC
Richard, seems like the variable is going to anonymous and it is defined via a POINTER_PLUS_EXPR, we should go back one more on def-use chain.
Comment 4 Andrew Pinski 2012-02-02 18:04:08 UTC
Hmm, on the trunk we don't get any warnings for -W -Wall -O2 or -O2 -Wstrict-aliasing=3.
Confirmed then.