Bug 18156 - Wrong code in gcc-3.3.5 and gcc-3.4.2 (4.0 not checked)
Summary: Wrong code in gcc-3.3.5 and gcc-3.4.2 (4.0 not checked)
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.5
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-26 11:03 UTC by Krzysztof Strasburger
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i386-pc-linux
Target: i386-pc-linux
Build: i386-pc-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***