https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66164

            Bug ID: 66164
           Summary: Strange behaviour calling functions with float as
                    parameter
           Product: gcc
           Version: 4.8.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d.a.gonzalez.marquez at gmail dot com
  Target Milestone: ---

Created attachment 35550
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35550&action=edit
Source code for reproduce the bug

The following bug is for x86 architecture on a i386 compilation: -m32

I took a code that is part of an implementation of the libc. In order to obtain
a new one with some changes. The problem was that I found a bug. The code is
easy to follow:

It makes calls in this order: main ---> AUXsin ---> __sinf  --->
__ieee754_rem_pio2f

int main() {
float ra = AUXsin(100); 
return 0;
}

float AUXsin(float x) {
  return __sinf(x);
}

float __sinf(float x)
{
        float y[2],z=0.0;
        int32_t n, ix;
        n = __ieee754_rem_pio2f(x,y);
        return (float)n;
}

int32_t __ieee754_rem_pio2f(float x, float *y)
{
        y[0] = 0.0;
        return 0;
}

When the function __ieee754_rem_pio2f tries to read the parameter y, it finds
that the stack is:

esp - 4 | ........ 
esp + 0 | return addr 
esp + 4 | value x
esp + 8 | value x
esp + 12 | pointer to y

The problem was that the function __sinf store a double on the stack for the x
value. And, when the function tries to read the pointer to y, it reads a wrong
value.

I attached a zip with the code to test.

Thanks in advance,
David

Reply via email to