Bug 7642 - [3.2 regression] optimization problem with signbit()
[3.2 regression] optimization problem with signbit()
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.2
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-08-19 23:06 UTC by anonymous
Modified: 2003-07-25 17:33 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test1.i (63.21 KB, text/x-c)
2003-05-21 15:17 UTC, anonymous
Details

Note You need to log in before you can comment on or make changes to this bug.
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.