http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36602
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-06-06 14:11:07 UTC --- Created attachment 27563 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27563 proposed patch Not as easy when the initialized struct contains padding ... The following testcase is reduced from a fail of gcc.target/x86_64/abi/test_struct_returning.c where SRA messes up information in the padding. With s = {} being a memset SRA would not do anything. The question in general would be whether memcpy/memset affect padding in a well-defined way, thus, if memset (&s, 0, sizeof (s)) is equivalent to s = {} and if memcpy (&s, &r, sizeof (s)) is equivalent to s = r. We at least assume that in the way we currently fold memcpy. struct S { char c; long long i; }; struct S __attribute__((noinline,noclone)) foo (void) { struct S s = {}; s.c = 42; return s; } void __attribute__((noinline,noclone)) keepit (struct S *s) { __builtin_memset (s, -1, sizeof (struct S)); } void __attribute__((noinline,noclone)) clobberstack () { struct S s; keepit (&s); } int main () { struct S s1, s2 = { 42, 0 }; clobberstack(); s1 = foo(); if (__builtin_memcmp (&s1, &s2, sizeof (struct S)) != 0) __builtin_abort (); return 0; }