https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106389
Bug ID: 106389 Summary: IPA modref breaks Safe Bitfields in C++ Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: mpolacek at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- The following test is miscompiled since r11-3308-gd119f34c952f87 (so the problem goes away with -fno-ipa-modref). void __assert_fail(const char *, const char *, int, const char *) { __builtin_abort(); } typedef int uint32_t; template <int Offset> struct BitFieldMember { int value; operator int() { return value & 1; } BitFieldMember operator=(int v) { value = value | v << Offset; return *this; } BitFieldMember operator-=(int v) { *this ? void() : __assert_fail("", "", 9, __PRETTY_FUNCTION__); value -= v << Offset; return *this; } }; union Status { struct { uint32_t value; } wrapper; Status(uint32_t v = 0) { wrapper.value = v; } operator uint32_t() { return wrapper.value; } BitFieldMember<0> readers; BitFieldMember<10> waitToRead; BitFieldMember<20> writers; }; uint32_t u; struct N { uint32_t m_status; void foo () { Status oldStatus = m_status, newStatus = oldStatus; u = oldStatus.waitToRead; newStatus.writers -= u; newStatus.readers = u; m_status = newStatus; } }; int main() { Status status; status.writers = status = 1; N lock; lock.m_status = status; lock.foo (); if (lock.m_status != 1) __builtin_abort(); }