public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/42910]  New: invalid memcpy() in trivial tail-call with large struct
@ 2010-01-30 23:28 mikpe at it dot uu dot se
  2010-05-03 20:26 ` [Bug target/42910] " schwab at linux-m68k dot org
  0 siblings, 1 reply; 2+ messages in thread
From: mikpe at it dot uu dot se @ 2010-01-30 23:28 UTC (permalink / raw)
  To: gcc-bugs

This is related to PR42909. When a tail-call does a trivial pass-through of a
large struct, gcc generates a redundant block copy with identical source and
destination addresses. On machines like x86 it inlines that as a rep;mov, but
on others like m68k it generates a call to libc's memcpy():

> cat bug2.c
struct s1 { int x[32]; };
extern void g1(struct s1);
void f1(struct s1 s1) { g1(s1); }
> m68k-unknown-linux-gcc -O2 -fomit-frame-pointer -S bug2.c
> cat bug2.s
#NO_APP
        .file   "bug2.c"
        .text
        .align  2
        .globl  f1
        .type   f1, @function
f1:
        move.l %sp,%d0
        addq.l #4,%d0
        pea 128.w
        move.l %d0,-(%sp)
        move.l %d0,-(%sp)
        jsr memcpy
        lea (12,%sp),%sp
        jra g1
        .size   f1, .-f1
        .ident  "GCC: (GNU) 4.5.0 20100128 (experimental)"
        .section        .note.GNU-stack,"",@progbits

However, formally speaking this triggers undefined behaviour as the memcpy's
source and destination areas overlap. (Although the C standard does distinguish
between inexact and exact overlap in assignments, there's no such distinction
for library routines like memcpy.)


-- 
           Summary: invalid memcpy() in trivial tail-call with large struct
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikpe at it dot uu dot se
GCC target triplet: m68k-unknown-linux


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


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

* [Bug target/42910] invalid memcpy() in trivial tail-call with large struct
  2010-01-30 23:28 [Bug target/42910] New: invalid memcpy() in trivial tail-call with large struct mikpe at it dot uu dot se
@ 2010-05-03 20:26 ` schwab at linux-m68k dot org
  0 siblings, 0 replies; 2+ messages in thread
From: schwab at linux-m68k dot org @ 2010-05-03 20:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at linux-m68k dot org  2010-05-03 20:26 -------
This isn't really a different bug.

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


-- 

schwab at linux-m68k dot org changed:

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


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


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

end of thread, other threads:[~2010-05-03 20:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-30 23:28 [Bug target/42910] New: invalid memcpy() in trivial tail-call with large struct mikpe at it dot uu dot se
2010-05-03 20:26 ` [Bug target/42910] " schwab at linux-m68k 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).