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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to