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

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 13 02:46:29 PDT 2018


t.p.northover updated this revision to Diff 142364.
t.p.northover added a comment.

Sorry to update the patch after you've reviewed it, but I'm afraid as a result of https://llvm.org/PR34347 it's turned out that misaligned x86 atomics actually need the lock-free implementation, which makes this even messier than I thought.

It adds 3 problems:

1. As far as I know there's no way Clang communicates this, in fact I don't think it's even aware of it. So the updated patch has bare __x86_64__ and __i386__ checks.
2. There is no way to make Clang inline a misaligned atomic operation that I could find, and even if it could the LLVM IR would be dubious (the LangRef is sprinkled with warnings about such things being undefined and they get converted back to libcalls anyway).
3. x86 movs aren't atomic when misaligned, so load & store need a separate path for that case.

Because of the second, misaligned pointers in the new patch go down an aligned codepath with all the technical UB implications you might fear. It works, though. As far as I can tell this fixes everything except 128-bit x86 atomics in practice.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45321

Files:
  compiler-rt/lib/builtins/atomic.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45321.142364.patch
Type: text/x-patch
Size: 5855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/18f5369f/attachment.bin>


More information about the llvm-commits mailing list