public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43904]  New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64
@ 2010-04-26 23:45 tavianator at gmail dot com
  2010-04-26 23:47 ` [Bug c/43904] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tavianator at gmail dot com @ 2010-04-26 23:45 UTC (permalink / raw)
  To: gcc-bugs

On x86_64, gcc 4.5.0, this code generates bad assembly:

--- C code ---
typedef unsigned long size_t;
void *memcpy(void *dest, const void *src, size_t n);

void
buggy_init(void *ptr, size_t size)
{
  const char *str = "Hello world!";
  memcpy(ptr, &str, size);
}
--------------

Compiled with gcc -O -foptimize-sibling-calls, the generated assembly looks
like this:

--------------
buggy_init:
        movq    %rsi, %rdx
        movq    $.LC0, -16(%rsp)
        leaq    -16(%rsp), %rsi
        jmp     memcpy
--------------

which passes rsp-16 as memcpy's second argument.  memcpy overwrites this part
of the stack, and copies the wrong value, which causes a crash later.


-- 
           Summary: Wrong code with -foptimize-sibling-calls and memcpy on
                    x86_64
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tavianator at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug c/43904] Wrong code with -foptimize-sibling-calls and memcpy on x86_64
  2010-04-26 23:45 [Bug c/43904] New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64 tavianator at gmail dot com
@ 2010-04-26 23:47 ` pinskia at gcc dot gnu dot org
  2010-04-26 23:48 ` tavianator at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-04-26 23:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-04-26 23:47 -------


*** This bug has been marked as a duplicate of 43572 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

* [Bug c/43904] Wrong code with -foptimize-sibling-calls and memcpy on x86_64
  2010-04-26 23:45 [Bug c/43904] New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64 tavianator at gmail dot com
  2010-04-26 23:47 ` [Bug c/43904] " pinskia at gcc dot gnu dot org
@ 2010-04-26 23:48 ` tavianator at gmail dot com
  2010-04-27  0:26 ` [Bug tree-optimization/43904] " hjl at gcc dot gnu dot org
  2010-04-27  0:30 ` hjl at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: tavianator at gmail dot com @ 2010-04-26 23:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tavianator at gmail dot com  2010-04-26 23:47 -------
Created an attachment (id=20497)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20497&action=view)
Full testcase

Proper output:

Stored: 0x40071c
Got:    0x40071c
Hello world!

Output with -O -foptimize-sibling-calls:

Stored: 0x40070c
Got:    0x1
[1]    15940 segmentation fault (core dumped)  ./a.out


-- 


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


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

* [Bug tree-optimization/43904] Wrong code with -foptimize-sibling-calls and memcpy on x86_64
  2010-04-26 23:45 [Bug c/43904] New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64 tavianator at gmail dot com
  2010-04-26 23:47 ` [Bug c/43904] " pinskia at gcc dot gnu dot org
  2010-04-26 23:48 ` tavianator at gmail dot com
@ 2010-04-27  0:26 ` hjl at gcc dot gnu dot org
  2010-04-27  0:30 ` hjl at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: hjl at gcc dot gnu dot org @ 2010-04-27  0:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from hjl at gcc dot gnu dot org  2010-04-27 00:25 -------
Subject: Bug 43904

Author: hjl
Date: Tue Apr 27 00:25:18 2010
New Revision: 158757

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158757
Log:
Add a run-time testcase for PR tree-optimization/43904.

2010-04-26  H.J. Lu  <hongjiu.lu@intel.com>

        PR tree-optimization/43904
        * gcc.dg/tree-ssa/tailcall-6.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/tailcall-6.c
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug tree-optimization/43904] Wrong code with -foptimize-sibling-calls and memcpy on x86_64
  2010-04-26 23:45 [Bug c/43904] New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64 tavianator at gmail dot com
                   ` (2 preceding siblings ...)
  2010-04-27  0:26 ` [Bug tree-optimization/43904] " hjl at gcc dot gnu dot org
@ 2010-04-27  0:30 ` hjl at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: hjl at gcc dot gnu dot org @ 2010-04-27  0:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hjl at gcc dot gnu dot org  2010-04-27 00:30 -------
Subject: Bug 43904

Author: hjl
Date: Tue Apr 27 00:30:00 2010
New Revision: 158758

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158758
Log:
Backport testcase from mainline.

2010-04-26  H.J. Lu  <hongjiu.lu@intel.com>

        Backport from mainline
        2010-04-26  H.J. Lu  <hongjiu.lu@intel.com>

        PR tree-optimization/43904
        * gcc.dg/tree-ssa/tailcall-6.c: New.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/tree-ssa/tailcall-6.c
      - copied unchanged from r158757,
trunk/gcc/testsuite/gcc.dg/tree-ssa/tailcall-6.c
Modified:
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2010-04-27  0:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-26 23:45 [Bug c/43904] New: Wrong code with -foptimize-sibling-calls and memcpy on x86_64 tavianator at gmail dot com
2010-04-26 23:47 ` [Bug c/43904] " pinskia at gcc dot gnu dot org
2010-04-26 23:48 ` tavianator at gmail dot com
2010-04-27  0:26 ` [Bug tree-optimization/43904] " hjl at gcc dot gnu dot org
2010-04-27  0:30 ` hjl at gcc dot gnu dot 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).