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