[PATCH] D45321: [atomics] Fix runtime calls for misaligned atomics

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 07:36:21 PDT 2018


t.p.northover added a comment.

> Also, on the LLVM side there are even fewer restrictions and load atomic i32, i32* %ptr monotonic, align 1 is perfectly valid IR that gets lowered to these calls.

I've just checked the LangRef and realised this is false. LLVM does make such loads & stores UB, though I still think the Clang use is valid (if unfortunate).

> Even non-atomic accesses can fail and be miscompiled for unaligned variables, no?



> For example, I would assume that "(uintptr_t)ptr % 4 == 0" where ptr come from an unmarked int will be evaluated to a compile-time true.

For an unmarked int that's true, but there are ways to get integer types with lowered alignment requirements. Mostly revolving around applying some kind of packed attribute or pragma to either a struct or the type directly.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45321





More information about the llvm-commits mailing list