Bug 23077 - Invalid code with O2 flag (bad alias analysis?)
Summary: Invalid code with O2 flag (bad alias analysis?)
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2005-07-26 14:35 UTC by nicos
Modified: 2005-07-26 14:36 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description nicos 2005-07-26 14:35:05 UTC
Source code:
#include <stdio.h>

int main (int argc, char * argv[])
   unsigned int t[2] = {1, 1};  
   *((double *)t) = 0.0;   
   printf("%d\n", t[1]);   

This code prints "1" insted of "0" when with: gcc foo.c -o foo -O2
Output of gcc -v foo.c -o foo2 -O2:
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: /var/tmp/portage/gcc-3.4.4/work/gcc-3.4.4/configure
--enable-version-specific-runtime-libs --prefix=/usr
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --disable-libunwind-exceptions --disable-multilib
--disable-libgcj --enable-languages=c,c++,f77 --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8)
 /usr/libexec/gcc/i686-pc-linux-gnu/3.4.4/cc1 -quiet -v foo.c -quiet -dumpbase
foo.c -mtune=pentiumpro -auxbase foo -O2 -version -o /tmp/ccFePbg2.s
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
#include "..." search starts here:
#include <...> search starts here:
End of search list.
GNU C version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8) (i686-pc-linux-gnu)
        compiled by GNU C version 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8).
GGC heuristics: --param ggc-min-expand=90 --param ggc-min-heapsize=113127
 /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../i686-pc-linux-gnu/bin/as -V
-Qy -o /tmp/ccokr9zW.o /tmp/ccFePbg2.s
GNU assembler version 2.16.1 (i686-pc-linux-gnu) using BFD version 2.16.1
 /usr/libexec/gcc/i686-pc-linux-gnu/3.4.4/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o foo2
-L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4 -L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4
-L/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/../../.. /tmp/ccokr9zW.o -lgcc -lgcc_eh
-lc -lgcc -lgcc_eh /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/crtend.o

I suspect that the alias analysis use an incorrect size for double.
Comment 1 Andrew Pinski 2005-07-26 14:36:59 UTC
No this is not bad alias analysis,   You are invoking undefined code by violating aliasing rules in C/C++.

This is a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***