public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/106389] New: IPA modref breaks Safe Bitfields in C++
@ 2022-07-21 17:21 mpolacek at gcc dot gnu.org
  2022-07-21 17:23 ` [Bug ipa/106389] [11/12/13 Regression] " mpolacek at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-21 17:21 UTC (permalink / raw)
  To: gcc-bugs

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();
}

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-30 20:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21 17:21 [Bug ipa/106389] New: IPA modref breaks Safe Bitfields in C++ mpolacek at gcc dot gnu.org
2022-07-21 17:23 ` [Bug ipa/106389] [11/12/13 Regression] " mpolacek at gcc dot gnu.org
2022-07-21 17:26 ` mpolacek at gcc dot gnu.org
2022-07-22  7:09 ` [Bug c++/106389] " rguenth at gcc dot gnu.org
2022-07-22 12:53 ` mpolacek at gcc dot gnu.org
2022-07-24  9:05 ` hubicka at gcc dot gnu.org
2022-07-25  6:20 ` rguenth at gcc dot gnu.org
2023-05-29 10:07 ` [Bug c++/106389] [11/12/13/14 " jakub at gcc dot gnu.org
2023-07-08  1:45 ` pinskia at gcc dot gnu.org
2023-10-30 20:09 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).