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 PR tree-optimization/21407


> I can, in compilation unit A declare a bunch of separate structures that
> I freely use.  In compilation unit B I can declare a union of all of
> those structures defined in compilation unit A.  Any pointer passing
> accross the boundary between compilation units A and B can this freely
> scramble any variable defined in compilation unit A.
>
> Thus, our current type based aliasing (and I would argue any type based
> aliasing) that does not assume the worst case for any variable whose
> address may leave the compilation unit is invalid.

I though the guarantee for unions only applied when the access was actually 
done through the union type.

ie. the following code has undefined behaviour:

union
{
  int a;
  float b;
} u;

int foo (float f)
{
  u v;
  int *p;
  float *q;
  p = &v.a;
  q = &v.b;
  *q = f;
  return *p;
}

Paul


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