Aliasing brokenness (Was: Re: [patch RFC] SH: Use FRAME_GROWS_DOWNWARD)

Ian Lance Taylor ian@airs.com
Wed Jul 20 19:49:00 GMT 2005


Mark Mitchell <mark@codesourcery.com> writes:

> Mark Mitchell wrote:
> 
> > That's the rule we've tried to use in GCC, as well; that if "p" and
> > "q" pointer to distinct types (not part of the same alias set) then
> > modifying "*p" cannot change the value of "*q", unless both accesses
> > are directly through a union.  I don't know that the front ends and
> > optimizers are careful about preserving the user's access through
> > unions, but they could in theory be appropriately careful.
> 
> I didn't have C99 sufficiently swapped in.  In C99, 6.5.2.3/5 suggest
> that this is not true, and that you explicitly don't have to use the
> union when dealing with structures with common initial sequences.  So,
> when you see a union of types A and B with a common initial sequence,
> you should put A and B in the same alias set.

I don't see anything in 6.5.2.3 which says that you access the structs
with common initial sequences *outside* the union.  I think that all
it says is that within the union you can safely access any of the
initial fields of any of the structs with common initial sequences,
assuming of course that the union currently contains a value with the
type of one of the structs.

That is, I think 6.5.2.3 is an explicit statement of a restricted form
of the rule you describe in the first paragraph.  It does not go
beyond what you described already.

Ian



More information about the Gcc-patches mailing list