This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
gcc-head bug? feature?
- From: Bernhard Fischer <rep dot nop at aon dot at>
- To: gcc-help at gcc dot gnu dot org
- Cc: Bernhard Fischer <rep dot nop at aon dot at>
- Date: Sun, 2 Oct 2005 01:56:22 +0200
- Subject: gcc-head bug? feature?
[please keep me CC'd]
Hi,
Is this a user error (thus an optimisation feature) or a glitch in gcc?
$ for o in '' -O2; do echo "# o='$o'";gcc-4.1-HEAD -W -Wall -Wextra
-pedantic $o -g -Wall -I. -o bar41.$o foo.c ;./bar41.$o;done
# o=''
var1=1020308
var1=1020809
# o='-O2'
foo.c: In function 'main':
foo.c:7: warning: dereferencing type-punned pointer will break
strict-aliasing rules
var1=1020308
var1=1020308
with O2, the second assignment is "optimized out"?
gcc-4.0.1, gcc-3.4, gcc-3.3, gcc-2.95 all yield 1020308 and 1020809 for
Odefault and O2, as opposed to gcc-4.1.
$ cat foo.c
#include <stdio.h>
int main(void)
{
int var1 = 0x01020304;
*(char *)&var1 = 0x08;
printf("var1=%x\n", var1);
*(short *)&var1 = 0x0809;
printf("var1=%x\n", var1);
return 0;
}