https://bugs.llvm.org/show_bug.cgi?id=34498
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: unassignedclangb...@nondot.org
Reporter: pe...@cordes.ca
CC: llvm-bugs@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
ret
Two separate stores are obviously not atomic!!
This might actually be a libc++ bug. The asm output is different with
-stdlib=libstdc++:
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
ret
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
ret
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs