Bug 21188

Summary: gcc over-optimizes volatile double
Product: [Retired] Red Hat Linux Reporter: Plummer, Martyn <plummer>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-11-27 16:28:09 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 21191    
Attachments:
Description Flags
Example C program to highlight bug none

Description Plummer, Martyn 2000-11-21 16:58:16 UTC
gcc 2.96 ignores the volatile keyword when optimizing C code.

This bug came to light in the R language (see http://www.r-project.org and
the R-base RPM on powertools), which uses a routine called "machar" to
determine the machine characteristics at runtime.  As a result of the bug,
machar reports double precision to be 2^-63 instead of the correct value
2^-52 on an i686.

A search of the gcc mailing list archives shows that this bug was found
independently by Tom Truscott and reported by him on 2 August, but
without any follow-up. See
http://gcc.gnu.org/ml/gcc-bugs/2000-08/msg00037.html
He includes a short program which aborts when the bug is triggered.
See also
http://gcc.gnu.org/ml/gcc-bugs/2000-08/msg00038.html
for an obviously related bug.

The machar routine from the R language is too long to include here, but you
can grab a copy from
http://calvin.iarc.fr/gcc/machar.c
This includes a main() function that prints the value of the double
precision. Compare with and without optimization.

Comment 1 Plummer, Martyn 2000-11-21 17:00:06 UTC
Created attachment 5622 [details]
Example C program to highlight bug

Comment 2 Jakub Jelinek 2000-11-22 12:27:45 UTC
I've posted a fix for this at
http://gcc.gnu.org/ml/gcc-patches/2000-11/msg01227.html
and am waiting now for feedback on it. If it is accepted, it will make it
into next gcc rpms.

Comment 3 Jakub Jelinek 2000-11-27 16:28:06 UTC
It was not accepted, but it will take quite some time before Richard Kenner
writes a fix he wants to see, so I'll be putting this patch into gcc-2.96-65
and above.