https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88223
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jsm28 at gcc dot gnu.org --- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Richard Biener from comment #6) > Hmm, and with unions we can break the TBAA rule. > > union U { > struct X { int a : 3; int b : 8; } a; > struct Y { int a : 4; int b : 8; } b; > }; > > union U u; > int __attribute__((noinline)) bar () > { > int x = u.a.b; > u.b.b = x; > return u.a.b; > } > > int main() > { > u.a.b = 1; > if (bar () != 3) > abort (); > return 0; > } > > testcase is specific on bitfield layout of course and to the GCC extension > allowing type-punning via unions. Hmm, OTOH the C standard specifies that the store to u.b.b makes it the u.b the active member and it makes the old contents undefined. That would mean when loading u.a.b after the store we cannot rely on the exact value we get but at least the bits touched by u.b.b should be up-to-date (which is enough to show breakage). I thought about using u.a.b = 1; union U x; x.a.b = 1; x.b.b = 1; if (bar () != x.a.b) abort (); to make the test portable across bitfield layout but I guess I need to somehow compute a mask to ignore the bit... The C standard says the values are unspecified. And it talks about bytes, not bits...