https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115
Bug ID: 107115 Summary: Wrong codegen from TBAA under stores that change effective type? Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: bugdal at aerifal dot cx Target Milestone: --- Created attachment 53648 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53648&action=edit original test case by supercat The attached test case is from user supercat on Stack Overflow (original source: https://stackoverflow.com/questions/42178179/will-casting-around-sockaddr-storage-and-sockaddr-in-break-strict-aliasing/42178347?noredirect=1#comment130510083_42178347, https://godbolt.org/z/jfv1Ge6v4) and demonstrates what appears to be wrong TBAA optimization on an object with allocated storage whose effective type changes under stores. It was first presented as another example of this kind of problem alongside the example that became https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107107, but it seems likely that the root cause is distinct. Reportedly clang/LLVM also transforms this example wrong. On 64-bit targets, the test program outputs 2/1 with optimization levels that enable -fstrict-aliasing. The expected output is 2/2. Using -fno-strict-aliasing fixes it.