public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/66164] New: Strange behaviour calling functions with float as parameter
@ 2015-05-15 19:24 d.a.gonzalez.marquez at gmail dot com
  2015-05-15 21:57 ` [Bug middle-end/66164] " msebor at gcc dot gnu.org
  2015-05-16  2:03 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: d.a.gonzalez.marquez at gmail dot com @ 2015-05-15 19:24 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/66164] Strange behaviour calling functions with float as parameter
  2015-05-15 19:24 [Bug middle-end/66164] New: Strange behaviour calling functions with float as parameter d.a.gonzalez.marquez at gmail dot com
@ 2015-05-15 21:57 ` msebor at gcc dot gnu.org
  2015-05-16  2:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-05-15 21:57 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The program calls functions (__sinf and __ieee754_rem_pio2f) without declaring
them first.  Compiling with the -Wall option highlights the problem.  Once the
functions are declared before called the program runs succesffully to
completion.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/66164] Strange behaviour calling functions with float as parameter
  2015-05-15 19:24 [Bug middle-end/66164] New: Strange behaviour calling functions with float as parameter d.a.gonzalez.marquez at gmail dot com
  2015-05-15 21:57 ` [Bug middle-end/66164] " msebor at gcc dot gnu.org
@ 2015-05-16  2:03 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-05-16  2:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-05-16
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Try compiling with -W -Wall because I think you are getting some undefined
behavior due to not having prototypes for some of the functions.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-16  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 19:24 [Bug middle-end/66164] New: Strange behaviour calling functions with float as parameter d.a.gonzalez.marquez at gmail dot com
2015-05-15 21:57 ` [Bug middle-end/66164] " msebor at gcc dot gnu.org
2015-05-16  2:03 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).