[LLVMbugs] [Bug 23263] New: clang miscompiles atomics by using optimized libcalls for underaligned storage
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Apr 16 23:21:24 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=23263
Bug ID: 23263
Summary: clang miscompiles atomics by using optimized libcalls
for underaligned storage
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: richard-llvm at metafoo.co.uk
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Per https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary, "All the optimized routines
expect that the object will be properly aligned for a data type of the
specified size".
However, Clang and GCC get this wrong:
struct X { int a, b; };
X f(X *p) { X r; __atomic_load(p, &r, 5); return r; }
... calls __atomic_load_8. And GCC's libatomic implements __atomic_load_8 on
x86_64 with a single 8-byte mov, which is only atomic for a correctly-aligned
operand.
We should instead emit a call to __atomic_load(8, p, &r, 5) because we have no
reason to think that p is 8 byte aligned.
The same happens for __atomic_store and probably all the other atomic libcalls.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150417/36a1afa5/attachment.html>
More information about the llvm-bugs
mailing list