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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
With union punning we've basically opened up a way to change the dynamic type
of storage in a way that expects us from generating no code from a "virtual"
read-write cycle involving the previous and the next dynamic type of the
storage.

Now the checks we're currently performing try to assess whether such a
change takes place but given we don't really know the current dynamic type
we're guessing based on the "read" which constrains that dynamic type.
And we're willing to elide changes to a type that is strictly more
restrictive as to what followon accesses it allows.

What goes wrong here is our guessing of the current dynamic type based on
the observed read, that's because the read picks up *py but the reads
alias-set is not equal to or a subset of the *py stores alias-set (but
it conflicts since the subset relation is the other way around).

What we know from the union read is that the dynamic type is either the
union type (so the read can pun) or the dynamic type is the union member
type (then the read cannot pun).  6.5/7 allows accesses using
"an aggregate or union type that includes [a type compatible with the effective
type of the object]".  Though the 'aggregate' case appears quite odd to me,
does it really allow 'int i; struct { float f; int i; } *p = &i; float x =
p->f;'?  GCC doesn't allow this already based on the fact that sizeof (*p)
is larger than 'i', thus would even disallow it in case the 'f' member was
'int' as well.

Reply via email to