Bug 44198 - Constant floating point values are mutable (with '-O1')
Summary: Constant floating point values are mutable (with '-O1')
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2010-05-19 18:00 UTC by Alek Makovec
Modified: 2010-05-19 18:05 UTC (History)
68 users (show)

See Also:
Host: Linux hld-lx 2.6.18-128.7.1.el5 #1 SMP Mon Aug 24 08:20:55 EDT 2
Target: same as above
Build: gcc version 4.4.0 20090514 (Red Hat 4.4.0-6) (GCC)
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 Alek Makovec 2010-05-19 18:00:34 UTC
The example code below, compiled on x86 with gcc versions 4.1.2 through 4.4.0, aborts when executed.

#include <stdlib.h>
#include <assert.h>

int main(void)__attribute__ ((optimize("O1")));  // Also with '-O2'
int main(void)
   const float a = rand(); // Any function call that returns 1804289383 will do
   volatile float tmp=a;

   assert(tmp==a); // This one aborts
   assert(tmp==a); // This one passes (if line above is replaced with printf)

If you replace assert() with two consecutive printf("%f ", a), two different values are displayed for the constant variable a.
Comment 1 Andrew Pinski 2010-05-19 18:01:42 UTC
I think this is a dup of bug 323.
Comment 2 Andrew Pinski 2010-05-19 18:05:09 UTC
And it is as it works correctly with -std=c99 in 4.5.0 and above and it works correctly on x86_64 or with -mfpmath=sse.

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