public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/65358] New: parameter passing bug with tail call optimization on arm
@ 2015-03-09  5:56 hong.gyu.kim at lge dot com
  2015-03-09  6:05 ` [Bug target/65358] " hong.gyu.kim at lge dot com
                   ` (25 more replies)
  0 siblings, 26 replies; 27+ messages in thread
From: hong.gyu.kim at lge dot com @ 2015-03-09  5:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65358
           Summary: parameter passing bug with tail call optimization on
                    arm
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hong.gyu.kim at lge dot com

struct pack
{
    int fine;
    int victim;
    int killer;
};
int bar(int a, int b, struct pack p);
int foo(int arg1, int arg2, int arg3, struct pack p)
{
    return bar(arg2, arg3, p);
}

When I cross compile the above code with "-O2" option for arm, one variable in
"struct pack" is lost.

The "vitcim" value is overwritten by "killer" value while passing arguments in
"struct pack" from "foo" to "bar".

Initially the arguments are passed this way right after foo invoked.
r0: arg1
r1: arg2
r2: arg3
r3: p.fine
MEM[sp]: p.victim
MEM[sp-4]: p.killer

Parameter setting for bar must be this way right before bar invoked.
r0: arg2
r1: arg3
r2: p.fine
r3: p.victim
MEM[sp]: p.killer

But parameter passing is structured as follows:
(p.victim is overwritten by p.killer)
r0: arg2
r1: arg3
r2: p.fine
r3: p.killer (*)
MEM[sp]: p.killer


The assembly code of "foo" generated is as follows:

foo:
        @ args = 16, pretend = 8, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        sub     sp, sp, #8
        mov     r0, r1
        str     lr, [sp, #-4]!
        add     ip, sp, #8
(1)     ldr     lr, [sp, #16]
        mov     r1, r2
        str     r3, [sp, #8]
(2)     str     lr, [sp, #12]
        ldr     lr, [sp], #4
        ldmia   ip, {r2, r3}
        add     sp, sp, #8
        b       bar

The point is that (1) loads "p.killer", then (2) overwrites "p.victim" value.
Until this point, "p.victim" is never copied anyway, which makes the value
disappear.

This bug is not shown when compiled with "-fno-optimize-sibling-calls".

This bug is shown in gcc-4.9.2 and also in gcc-5.0.0.
I also compiled the same program for x86 and x86_64 and those do not generate
this kind of buggy code. This bug is only shown in arm code.

I found that this bug is detected right after the RTL expand phase. (with
-fdump-rtl-expand)


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

end of thread, other threads:[~2015-08-15 16:11 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09  5:56 [Bug target/65358] New: parameter passing bug with tail call optimization on arm hong.gyu.kim at lge dot com
2015-03-09  6:05 ` [Bug target/65358] " hong.gyu.kim at lge dot com
2015-03-09  6:23 ` [Bug target/65358] wrong parameter passing code " hong.gyu.kim at lge dot com
2015-03-09  8:10 ` mikpelinux at gmail dot com
2015-03-09  8:21 ` hong.gyu.kim at lge dot com
2015-03-09  8:29 ` hong.gyu.kim at lge dot com
2015-03-10 13:55 ` jgreenhalgh at gcc dot gnu.org
2015-03-13  2:11 ` hong.gyu.kim at lge dot com
2015-03-13  2:14 ` hong.gyu.kim at lge dot com
2015-03-16 11:59 ` ktkachov at gcc dot gnu.org
2015-03-16 13:55 ` ktkachov at gcc dot gnu.org
2015-03-17  0:04 ` hong.gyu.kim at lge dot com
2015-03-17  0:19 ` hong.gyu.kim at lge dot com
2015-03-17 11:01 ` ktkachov at gcc dot gnu.org
2015-03-19  9:17 ` ktkachov at gcc dot gnu.org
2015-03-19 10:38 ` hong.gyu.kim at lge dot com
2015-03-19 10:44 ` ktkachov at gcc dot gnu.org
2015-03-19 15:19 ` [Bug middle-end/65358] " ktkachov at gcc dot gnu.org
2015-04-02 10:08 ` hong.gyu.kim at lge dot com
2015-04-02 10:20 ` jgreenhalgh at gcc dot gnu.org
2015-04-02 10:38 ` ktkachov at gcc dot gnu.org
2015-04-02 11:52 ` rguenth at gcc dot gnu.org
2015-05-27 13:25 ` ktkachov at gcc dot gnu.org
2015-05-27 13:33 ` ktkachov at gcc dot gnu.org
2015-05-28  1:49 ` hong.gyu.kim at lge dot com
2015-06-24 21:27 ` ramana at gcc dot gnu.org
2015-08-15 16:11 ` mikpelinux at gmail dot com

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