Bug 38588 - strict-aliasing error
Summary: strict-aliasing error
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-21 01:43 UTC by smith bai
Modified: 2008-12-21 01:58 UTC (History)
28 users (show)

See Also:
Host:
Target:
Build:
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 smith bai 2008-12-21 01:43:27 UTC
Hi:
  use gcc4.1.2 on x86_64/linux, for example:
 main()
{
   long long int a;
   double b;
   a=4607182418800017408;
   b=*(double *)&a;
   printf("%f\n",b);
}
if using -O0/-O1 optimization, the result is 1.000000;
but if using -O2/-O3 optimization,the result is 0.000000.
i have try to close -fno-strict-aliasing in -O2/-O3, the result will be same as -O0/-O1.

so i think the strict-aliasing may have some bug!!!
Comment 1 Andrew Pinski 2008-12-21 01:58:59 UTC
No this is working as designed.  GCC does warn about this case.
t.c:6: warning: dereferencing type-punned pointer will break strict-aliasing rules


Now in 4.4.0 and above, the same result will happen at -O1 and -O2 because of another optimization that allows for the compiler to remove the alias violation in the IR.

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