[libcxx] r330828 - Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou for the report and test case.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 25 07:27:30 PDT 2018
Author: marshall
Date: Wed Apr 25 07:27:29 2018
New Revision: 330828
URL: http://llvm.org/viewvc/llvm-project?rev=330828&view=rev
Log:
Fix static initialization of std::atomic_flag; Fixes PR#37226. Thanks to Ricky Zhou for the report and test case.
Modified:
libcxx/trunk/include/atomic
libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp
Modified: libcxx/trunk/include/atomic
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=330828&r1=330827&r2=330828&view=diff
==============================================================================
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Wed Apr 25 07:27:29 2018
@@ -1741,7 +1741,7 @@ typedef struct atomic_flag
atomic_flag() _NOEXCEPT : __a_() {}
#endif // _LIBCPP_CXX03_LANG
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
#ifndef _LIBCPP_CXX03_LANG
Modified: libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp?rev=330828&r1=330827&r2=330828&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/atomics/atomics.flag/init_bool.pass.cpp Wed Apr 25 07:27:29 2018
@@ -18,8 +18,15 @@
#include <atomic>
#include <cassert>
+ // Ensure that static initialization happens; this is PR#37226
+extern std::atomic_flag global;
+struct X { X() { global.test_and_set(); }};
+X x;
+std::atomic_flag global = ATOMIC_FLAG_INIT;
+
int main()
{
+ assert(global.test_and_set() == 1);
{
std::atomic_flag f(false);
assert(f.test_and_set() == 0);
More information about the cfe-commits
mailing list