volatile writes are merged for volatile base class subobjects · Issue #127683 · llvm/llvm-project (original) (raw)

https://godbolt.org/z/ozEexb66j

struct Base { int c; };

struct Obj : Base { };

volatile Obj o;

void awoo() { o.c = 1; o.c = 2; o.c = 3; }

Expected output (GCC)

awoo(): mov DWORD PTR o[rip], 1 mov DWORD PTR o[rip], 2 mov DWORD PTR o[rip], 3 ret

Actual output (Clang)

awoo(): mov dword ptr [rip + o], 3 ret

Note: o.c is a volatile object, so why are its writes getting coalesced? This doesn't happen when Base is a data member of Obj, so this is almost certainly unintentional.