[Bug rtl-optimization/14319] incorrect optimization of union of structs with common initial sequences
jameskuyper at alumni dot caltech.edu
gcc-bugzilla@gcc.gnu.org
Wed Oct 21 13:45:47 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14319
--- Comment #18 from James Kuyper Jr. <jameskuyper at alumni dot caltech.edu> ---
(In reply to Vincent Lefèvre from comment #17)
> (In reply to Tim Rentsch from comment #10)
> > Four: Despite the last observation, the "one special guarantee" clause
> > (and hence also DR 257) is clearly not germane to this problem. The
> > reason for this is that the "one special guarantee" clause is concerned
> > with read access ("inspect" is the word used in the Standard),
> [...]
>
> In any case, the aliasing rule is only about read access: "An object shall
> have its stored value accessed only by [...]" (6.5#7). If you are accessing
> a stored value, this means that you are reading it. Thus the "yp->y = 1;"
> does not imply undefined behavior, in case this is what you were thinking
> about.
Agreed, the aliasing rule only produces undefined behavior for a read access,
not a write access. As Tim pointed out, when the "one special guarantee"
applies, it overrides the aliasing rules to give defined behavior for such a
read, and isn't relevant to the write. However, as I pointed out in comment 11
(and as was conceded by Tim in comment 13 and comment 14), the issue is not the
write access in
yp->y = 1;
it's the read access in
return xp->x;
The guarantee does apply to that read (though others have disagreed about
that), and therefore gives that read well-defined behavior, behavior that is
inconsistent with the actual behavior reported by Jeff Sturm.
More information about the Gcc-bugs
mailing list