gcc 4.3 on alpha generates wrong code when -foptimize-sibling-calls is
used (which is enabled at -O2). It was not the case with gcc 4.2, and
this is still reproducible with gcc from trunk from 20090106. This is
the reason why most of the complex tests of the glibc testsuite are
failing with gcc 4.3.

Here is a reduced testcase:

$ cat main.c
#include <math.h>
#include <complex.h>

__complex__ float my_print_complex (__complex__ float x);

int main()
{
  __complex__ float a;
  __real__ a = 9;
  __imag__ a = 42;

  my_print_complex(a);

  return 0;
}
$ cat print.c
#include <complex.h>
#include <math.h>
#include <stdio.h>

__complex__ float internal_print_complex (__complex__ float x)
{

  printf("%f+%fi\n", __real__ x, __imag__ x);

  if (__real__ x < 0)
  {
     __real__ x = -__real__ x;
  }

  return x;
}

__complex__ float my_print_complex (__complex__ float x)
{
  return internal_print_complex (x);
}
$ gcc-4.3 -Wall -c main.c -o main.o
$ gcc-4.3 -O1 -foptimize-sibling-calls -Wall -c print.c -o print.o
$ gcc-4.3 -o test main.o print.o
$ ./test
0.000000+0.000000i

When print.o is not compiled with -foptimize-sibling-calls, the result
is:
$./test
9.000000+42.000000i
$


-- 
           Summary: -foptimize-sibling-calls generates wrong code
                    on alpha
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: aurelien at aurel32 dot net
 GCC build triplet: alphaev68-unknown-linux-gnu
  GCC host triplet: alphaev68-unknown-linux-gnu
GCC target triplet: alphaev68-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38969

Reply via email to