public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34109]  New: Incorrect code for tail calls with a structure as 4th argument
@ 2007-11-15 15:59 narge-gcc at derrin dot id dot au
  2007-11-15 18:53 ` [Bug middle-end/34109] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: narge-gcc at derrin dot id dot au @ 2007-11-15 15:59 UTC (permalink / raw)
  To: gcc-bugs

In the following code, the tail call in g() is compiled incorrectly on ARM with
-O2 or higher (and -fno-inline):

#include <stdio.h>

struct s {
    int x, y, z;
};

int f(int a, int b, int c, struct s d, int e) {
    printf("%d %d %d\n", d.x, d.y, d.z);
    return 0;
}

int g(int a, int b, int c, int d, struct s e, int h) {
        return f(a, b, c, e, h);
}

int main(void) {
    f(0, 0, 0, (struct s){ 42, 69, 105 }, 7);
    g(0, 0, 0, 0, (struct s){ 42, 69, 105 }, 7);
    return 0;
}

With -O1 and lower, the result is correct:

42 69 105
42 69 105

With -O2 and higher, it prints:

42 69 105
69 69 7

Inspecting the output of gcc -O3 -fno-inline -S shows that gcc is shifting the
arguments on the stack downwards for the tail call. However, it starts at the
top, rather than at the bottom. So it writes over two arguments (e.z and e.x)
before loading them.

This has been broken since 4.1.1 (possibly earlier), and is still broken in
4.2.2.


-- 
           Summary: Incorrect code for tail calls with a structure as 4th
                    argument
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: narge-gcc at derrin dot id dot au
GCC target triplet: arm-elf


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


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

* [Bug middle-end/34109] Incorrect code for tail calls with a structure as 4th argument
  2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
@ 2007-11-15 18:53 ` pinskia at gcc dot gnu dot org
  2008-02-05 11:15 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-11-15 18:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-11-15 18:53 -------
I think this is already fixed in 4.3.0.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |wrong-code


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


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

* [Bug middle-end/34109] Incorrect code for tail calls with a structure as 4th argument
  2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
  2007-11-15 18:53 ` [Bug middle-end/34109] " pinskia at gcc dot gnu dot org
@ 2008-02-05 11:15 ` rguenth at gcc dot gnu dot org
  2009-03-17 14:41 ` ramana dot r at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-05 11:15 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


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

* [Bug middle-end/34109] Incorrect code for tail calls with a structure as 4th argument
  2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
  2007-11-15 18:53 ` [Bug middle-end/34109] " pinskia at gcc dot gnu dot org
  2008-02-05 11:15 ` rguenth at gcc dot gnu dot org
@ 2009-03-17 14:41 ` ramana dot r at gmail dot com
  2009-03-18 11:49 ` rearnsha at gcc dot gnu dot org
  2009-03-20 11:09 ` mikpe at it dot uu dot se
  4 siblings, 0 replies; 6+ messages in thread
From: ramana dot r at gmail dot com @ 2009-03-17 14:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ramana dot r at gmail dot com  2009-03-17 14:40 -------
This appears to be fixed on mainline on gcc version 4.4.0 20090317
(experimental) (GCC). 

output obtained
42 69 105
42 69 105


-- 

ramana dot r at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rearnsha at gcc dot gnu dot
                   |                            |org, ramana dot r at gmail
                   |                            |dot com


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


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

* [Bug middle-end/34109] Incorrect code for tail calls with a structure as 4th argument
  2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
                   ` (2 preceding siblings ...)
  2009-03-17 14:41 ` ramana dot r at gmail dot com
@ 2009-03-18 11:49 ` rearnsha at gcc dot gnu dot org
  2009-03-20 11:09 ` mikpe at it dot uu dot se
  4 siblings, 0 replies; 6+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-03-18 11:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rearnsha at gcc dot gnu dot org  2009-03-18 11:49 -------
No feedback in over a year.  Presumed fixed in 4.3.0.


-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


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


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

* [Bug middle-end/34109] Incorrect code for tail calls with a structure as 4th argument
  2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
                   ` (3 preceding siblings ...)
  2009-03-18 11:49 ` rearnsha at gcc dot gnu dot org
@ 2009-03-20 11:09 ` mikpe at it dot uu dot se
  4 siblings, 0 replies; 6+ messages in thread
From: mikpe at it dot uu dot se @ 2009-03-20 11:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from mikpe at it dot uu dot se  2009-03-20 11:08 -------
(In reply to comment #3)
> No feedback in over a year.  Presumed fixed in 4.3.0.

I can confirm that this test case works when compiled with a vanilla gcc-4.3.3
built for armv5tel eabi.


-- 


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


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

end of thread, other threads:[~2009-03-20 11:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-15 15:59 [Bug c/34109] New: Incorrect code for tail calls with a structure as 4th argument narge-gcc at derrin dot id dot au
2007-11-15 18:53 ` [Bug middle-end/34109] " pinskia at gcc dot gnu dot org
2008-02-05 11:15 ` rguenth at gcc dot gnu dot org
2009-03-17 14:41 ` ramana dot r at gmail dot com
2009-03-18 11:49 ` rearnsha at gcc dot gnu dot org
2009-03-20 11:09 ` mikpe at it dot uu dot se

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).