On Thu, Nov 23, 2017 at 04:32:43PM +0100, Martin Jambor wrote:
> > struct A { short s; long i; long j; };
> > struct A a, b;
> > void foo ()
> > {
> >   struct A c;
> >   __builtin_memcpy (&c, &b, sizeof (struct A));
> >   __builtin_memcpy (&a, &c, sizeof (struct A));
> > }
> > int main()
> > {
> >   __builtin_memset (&b, 0, sizeof (struct A));
> >   b.s = 1;
> >   __builtin_memcpy ((char *)&b+2, &b, 2);
> >   foo ();
> >   __builtin_memcpy (&a, (char *)&a+2, 2);
> >   if (a.s != 1)
> >     __builtin_abort ();
> >   return 0;
> > }

Note the testcase would need to be guarded with sizeof (short) == 2
and offsetof (struct A, i) >= 4.

> Thanks for the testcase, I agree that is a fairly big problem.  Do you
> think that the following (untested) patch is an appropriate way of
> fixing it and generally of extending gimple to capture that a statement
> is a bit-copy?

Can you bail out just if the type contains any padding?  If there is no
padding, then perhaps SRA still might do its stuff (though, e.g. if it
contains bitfields, we'd need to hope store-merging merges it all back
again).

        Jakub

Reply via email to