Bug 18156

Summary: Wrong code in gcc-3.3.5 and gcc-3.4.2 (4.0 not checked)
Product: gcc Reporter: Krzysztof Strasburger <strasbur>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: critical CC: gcc-bugs
Priority: P2    
Version: 3.3.5   
Target Milestone: ---   
Host: i386-pc-linux Target: i386-pc-linux
Build: i386-pc-linux Known to work:
Known to fail: Last reconfirmed:

Description Krzysztof Strasburger 2004-10-26 11:03:35 UTC
This code gives "0 0" at first call to printf (wrong)
and "4 4" at second call (good). Works correctly with -O1, errors occur with -Os or -O2 or above.
void read8(int *x) { x[0] = 4; x[1] = 4;}
int main() { static double equiv[1]; double r;
read8(&r); *(equiv) = r;
printf("%d %d\n",((int *)equiv)[0],((int *)equiv)[1]);
printf("%d %d\n",((int *)equiv)[0],((int *)equiv)[1]);
return 0; }
Comment 1 Eric Botcazou 2004-10-26 11:16:04 UTC
Wrong code indeed, but on your side: your C code violates the aliasing rules of
the ISO C language.  Either fix it or pass -fno-strict-aliasing to the compiler.

See the entry of -fstrict-aliasing in the manual for more detailed info.
Comment 2 Krzysztof Strasburger 2004-10-26 11:26:03 UTC
Subject: Re:  Wrong code in gcc-3.3.5 and gcc-3.4.2 (4.0 not checked)

Thanks a lot!
This error occured originally in the f2c-translated FORTRAN code. It works 
flawlessly with -fno-strict-aliasing.
Krzysztof
PS who says, there is no support with free software ???
Comment 3 Andrew Pinski 2005-06-05 09:03:01 UTC
Reopning to ...
Comment 4 Andrew Pinski 2005-06-05 09:03:17 UTC
Mark as a dup of bug 21920.

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