This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix C++ strict-aliasing issues with memcpy folding


On 04/14/2010 05:23 PM, Richard Guenther wrote:
A C testcase would look like

union A {
     int alignme;
     char a[4];
};
extern void abort (void);
int main()
{
   union A a, b;
   *(float *)&a.a[0] = 1.0;
   b = a;
   if (*(float *)&b.a[0] != 1.0)
     abort ();
   return 0;
}

it actually works, as I have added some code to the alias-oracle
to avoid "miscompiling" it (I simply avoid applying TBAA rules
here).  Some obfuscating will cause it to "miscompile".

Earlier you were arguing that storing the float into the union
is ok because there's a character array member inside.

As in this testcase? Yes, I believe so. And the float-ness transfers to 'b' because union assignment is equivalent to memcpy.


Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]