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

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andi Kleen from comment #9)
> Any progress on fixing the test case, so that this can be finally fixed?

I have no idea how to do that without making the testcase test sth different.
We could of course simply turn off SRA for it ...

That said, the difference the optimization may cause might be surprising to
people.  That is, that the following may abort()

struct f { char c; int i; };
struct f2 { int i; int j; };
int main()
{
  struct f f;
  struct f2 f2;
  memset(&f, 0, sizeof (f));
  memcpy(&f2, f, sizeof (f));
  if (memcmp (&f, &f2) != 0)
   abort ();
  return 0;
}

because suddenly the semantics of a memset and a memcpy depend on the
type (_what_ type?!) of the pointed-to type.

Note we can "simply" circumvent the issue by using a char[n] typed
CONSTRUCTOR / type for the copy.  Sth I wanted to followup with
now that the folding happens always on GIMPLE.

It seems to me that SRA may not simply omit padding for aggregate
copies if it cannot prove that the padding is not used.  At least
on GIMPLE the semantics of an aggregate assignment is that of a
memmove, not of a field-wise copy.  Martin - can you look into this
wrong-code bug?  Basically if SRA decides it needs to re-materialize
the object (here before the memcmp call) then it has to re-materialize
padding as well.

Reply via email to