Bug 7642

Summary: [3.2 regression] optimization problem with signbit()
Product: gcc Reporter: anonymous
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: ebotcazou, gcc-bugs, jbuck
Priority: P3 Keywords: wrong-code
Version: 3.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: Test1.i

Description anonymous 2002-08-19 23:06:00 UTC
The following program illustrates an optimization problem with signbit() of a
long double NAN:

  #include <math.h>
  #include <stdio.h>
  #include <stdlib.h>
  int main(int argc, char* argv[])
  {
    long double n = NAN;
    if (signbit(n))
    {
      fprintf(stdout, "n is negative\n");
    }
    else
    {
      fprintf(stdout, "n is positive\n");
   }
    exit(0);
  }

When compiled with

  gcc -D_XOPEN_SOURCE=600 -o Test1 Test1.c

the resulting Test1 correctly prints "n is positive".  When compiled with

  gcc -D_XOPEN_SOURCE=600 -O -o Test1 Test1.c

or

  gcc -D_XOPEN_SOURCE=600 -O2 -o Test1 Test1.c

the resulting Test1 incorrectly prints "n is negative".  I am using gcc 3.2
on SuSE Linux/x86 7.1 (Linux kernel 2.4.0 and glibc 2.2).

Release:
gcc 3.2

Environment:
gcc 3.2 on SuSE Linux/x86 7.1 (kernel 2.4.0 and glibc 2.2)
Comment 1 Eric Botcazou 2003-02-19 08:50:10 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed on 3.2 branch. 3.3 and mainline are not affected.
Comment 2 Joe Buck 2003-04-25 21:18:49 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for 3.3.