[llvm-bugs] [Bug 34498] New: x86-64: std::atomic<T> is not atomic for a 16 byte object with -mno-cx16

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 6 02:48:45 PDT 2017


            Bug ID: 34498
           Summary: x86-64: std::atomic<T> is not atomic for a 16 byte
                    object with -mno-cx16
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: peter at cordes.ca
                CC: llvm-bugs at lists.llvm.org

struct A{
    int a;
    int b;
    double c;

#include <atomic>
std::atomic<A> shared_struct;

void update_shared2(A tmp) {
    shared_struct.store(tmp, std::memory_order_relaxed);
    // shared_struct = tmp;  // same buggy asm with libc++

Godbolt compiler explorer: https://godbolt.org/g/drmtAe

clang 6.0.0 (trunk 312520) -std=c++11 -stdlib=libc++ -Wall -Wextra -O3
-march=skylake -mno-cx16

update_shared2(A):                   # @update_shared2(A)
        mov     qword ptr [rip + shared_struct], rdi
        vmovsd  qword ptr [rip + shared_struct+8], xmm0

Two separate stores are obviously not atomic!!
This might actually be a libc++ bug. The asm output is different with

        sub     rsp, 24
        mov     qword ptr [rsp + 8], rdi
        vmovsd  qword ptr [rsp + 16], xmm0
        lea     rdx, [rsp + 8]
        mov     edi, 16
        mov     esi, shared_struct
        xor     ecx, ecx
        call    __atomic_store
        add     rsp, 24
        mov     rdi, rax
        call    __clang_call_terminate


correct clang4.0 output with libc++ (same options)

update_shared2(A):                   # @update_shared2(A)
        push    rax
        mov     rax, rdi
        vmovq   rdx, xmm0
        mov     edi, shared_struct
        mov     rsi, rax
        call    __sync_lock_test_and_set_16
        pop     rax

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/20170906/ef6ded0a/attachment.html>

More information about the llvm-bugs mailing list