[Bug c/38537] New: -fstrict-aliasing and -Wstrict-aliasing do not work

2008-12-15 Thread anvoebugz at gmail dot com
It seems that -fstring-aliasing option doesn't work:

$ cat test.c

#include 
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)


-- 
   Summary: -fstrict-aliasing and -Wstrict-aliasing do not work
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: anvoebugz at gmail dot com
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64
GCC target triplet: x86_64


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38537



[Bug tree-optimization/39268] New: printf changes fstrict-aliasing behaviour

2009-02-22 Thread anvoebugz at gmail dot com
It is strange that using printf that doesn't use any variables disables abort.

$ cat test2.c
#include 
#include 
int
main (void)
{
  int a = 0x12345678;
  short *b = (short *) &a;
  b[1] = 0;
  printf("\n");
  if (a == 0x12345678)
  abort();
  exit(0);
}

$ gcc -fstrict-aliasing -O2 -Wall test2.c
test2.c: In function ‘main’:
test2.c:8: warning: likely type-punning may break strict-aliasing rules: object
‘*{unknown}’ of main type ‘short int’ is referenced at or around test2.c:8 and
may be aliased to object ‘a’ of main type ‘int’ which is referenced at or
around test2.c:6.

$ ./a.out
$


The conditional jump is activated when printf is using:

@@ -7,9 +7,16 @@
 .LFB20:
subq$24, %rsp
 .LCFI0:
+   movl$10, %edi
movl$305419896, 20(%rsp)
movw$0, 22(%rsp)
+   callputchar
+   cmpl$305419896, 20(%rsp)
+   jne .L2
callabort
+.L2:
+   xorl%edi, %edi
+   callexit
 .LFE20:
.size   main, .-main
.section.eh_frame,"a",@progbits


$ 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)


-- 
   Summary: printf changes fstrict-aliasing behaviour
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
    ReportedBy: anvoebugz at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39268