https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109945
--- Comment #27 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #25) > > Since it's unspecified, the program cannot rely on any particular behaviour. > The 'global' pointer might point to w, or it might point to a temporary > which has gone out of scope, and in the latter case, dereferencing it in g() > is UB. > > So inconsistent behaviour with different optimization settings and/or noipa > attributes seems fine. Either global == &w or the program has UB. Hmm, so GCC thinks that global != &w does always hold and would optimize an explicit compare that way. Whether or not it actually creates a temporary. Is that invalid optimization? That is, do we need to consider that global _might_ point to w? We currently think it can never point to w. > I think this is INVALID.