This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/9840: Incorrect optimization for floating-point aliasing to int


>Number:         9840
>Category:       optimization
>Synopsis:       Incorrect optimization for floating-point aliasing to int
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 21:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Alex Gontmakher
>Release:        gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-2mdk)
>Organization:
>Environment:
machine: Athlon MP 1800
>Description:
The following code worked with previous versions of GCC, producing either 1 or 0. Now it produces 2.

A workaround is to uncomment the printf() line - obviously causes it to perform the initialization of the float prior to executing the ifs.

The problem happens only at optimization level O2 or higher.
>How-To-Repeat:
#include <iostream>

int f()
{
  int *p;
  double x = 1.0;
  /*fprintf(stderr,"");*/
  /* NOTE: this check assumes IEEE floating point format */
  p = (int *)&x;
  if (*p == 0)
    return 0;
  else if (*p == 0x3ff00000)
    return 1;
  else
    return 2;
}

int main()
{
  std::cout << f() << std::endl;
}
>Fix:
I didn't read the optimization code for this, but it should probably notice that p aliases &x, and perform the initialization of x prior to reading *p.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]