https://llvm.org/bugs/show_bug.cgi?id=30675
Bug ID: 30675 Summary: atomic::compare_exchange returns wrong value Product: libc++ Version: unspecified Hardware: PC OS: Linux Status: NEW Severity: release blocker Priority: P Component: All Bugs Assignee: unassignedclangb...@nondot.org Reporter: dvyu...@google.com CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com Classification: Unclassified llvm/clang/libc++ are on rev 271514. Test is: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <atomic> template<int kSize> struct MyStruct { char data[kSize]; explicit MyStruct(char v = 0) noexcept { memset(&data[0], v, sizeof(data)); } bool operator == (const MyStruct &other) const { return memcmp(&data[0], &other.data[0], sizeof(data)) == 0; } bool operator != (const MyStruct &other) const { return !(*this == other); } operator int() const { return data[0]; } }; int main() { typedef MyStruct<6> T; std::atomic<T> a(T(0)); T cmp(17); if (a.compare_exchange_strong(cmp, T(18), std::memory_order_acquire)) { fprintf(stderr, "%d: bad atomic value %d\n", __LINE__, (int)cmp); exit(1); } if (cmp != T(0)) { fprintf(stderr, "%d: bad atomic value %d\n", __LINE__, (int)cmp); exit(1); } } The test works with libstdc++: $ bin/clang++ /tmp/atomic.cc -std=c++11 -latomic && ./a.out But fails with libc++: $ bin/clang++ /tmp/atomic.cc -std=c++11 -stdlib=libc++ -latomic && LD_LIBRARY_PATH=./lib/ ./a.out 36: bad atomic value 17 -- 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