Bug 69496

Summary: strange floating point exceptions in trivial C programs
Product: [Retired] Red Hat Linux Reporter: Need Real Name <komarek>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: high Docs Contact:
Priority: medium    
Version: 7.1CC: komarek
Target Milestone: ---   
Target Release: ---   
Hardware: alpha   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-07-22 21:07:45 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:

Description Need Real Name 2002-07-22 20:30:26 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020618

Description of problem:
It is possible to write a trivial C program which causes a floating point
exception using one summation.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
Compile and link these programs with "gcc -o foo foo.c".  I've tried many other
optimization and debug settings, with no change in results.

This C code works correctly:
#include <stdio.h>
int main(void)
{
  printf("sum=%g\n", 1.21678e-308 + 1.07381e-308);
  return 0;
}

This C code dies with a floating point exception:
#include <stdio.h>
int main(void)
{
  double hi, lo, sum;
  hi = 1.21678e-308;
  lo = 1.07381e-308;
  sum = (hi + lo);            /* Produces bad result. */
  printf( "sum=%g\n", sum);   /* Dies here. */
  return 0;
}


Actual Results:  The first program works correctly.  The second does not.

Expected Results:  Both should have worked correctly. =-)

Additional info:

For both of these programs, compiling with Compaq's ccc produces underflow
warnings but the executable works correctly (no fp exceptions and prints the
expected "sum=2.29059e-308".

gcc2.96 fails, as does gcc3.1 (built from sources).

We've messed with this on 3 Alpha machines.  Two have dual 667MHz 21264 cpus
(DS-20 clones from Microway, 4MB cache), and one is a single cpu Compaq ES-40
(8MB cache).

We've fought with and tried to work around this for quite a while, and have
finally distilled it to this form.  Any help (workarounds, bug fixes, etc) would
be greatly appreciated, as this has cost us a lot of time.  I'd be happy to
provide assembly dumps or run experiments as needed.

Comment 1 Jakub Jelinek 2002-07-22 21:07:41 UTC
Have you tried -mieee?

Comment 2 Need Real Name 2002-07-22 21:19:27 UTC
Nope, we haven't.  Things appear work properly when we do.  I apologize for
wasting your bug time on us lusers.  I only wish we had wasted your time in
January instead of waiting until July. ;-)