[libcxx-commits] [PATCH] D126384: [libc++] Fix the dectection of lockfree atomics

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 25 08:06:06 PDT 2022


ldionne created this revision.
Herald added a subscriber: arichardson.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

We were only building the program, however on some systems building will
work, but the program will fail to run due to a dynamic linker error.
When this happens, we will incorrectly think that lockfree atomics are
available when they aren't.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126384

Files:
  libcxx/utils/libcxx/test/features.py


Index: libcxx/utils/libcxx/test/features.py
===================================================================
--- libcxx/utils/libcxx/test/features.py
+++ libcxx/utils/libcxx/test/features.py
@@ -50,20 +50,38 @@
   Feature(name='verify-support',                when=lambda cfg: hasCompileFlag(cfg, '-Xclang -verify-ignore-unexpected')),
 
   Feature(name='non-lockfree-atomics',
-          when=lambda cfg: sourceBuilds(cfg, """
-            #include <atomic>
-            struct Large { int storage[100]; };
-            std::atomic<Large> x;
-            int main(int, char**) { (void)x.load(); return 0; }
+          when=lambda cfg: programSucceeds(cfg, """
+            #include <stddef.h>
+            #if defined(_LIBCPP_HAS_NO_THREADS)
+              int main(int, char**) { return 1; }
+            #else
+              #include <atomic>
+              struct Large { int storage[100]; };
+              int main(int, char**) {
+                Large l;
+                std::atomic<Large> x(l);
+                (void)x.load();
+                return 0;
+              }
+            #endif
           """)),
   # TODO: Remove this feature once compiler-rt includes __atomic_is_lockfree()
   # on all supported platforms.
   Feature(name='is-lockfree-runtime-function',
-          when=lambda cfg: sourceBuilds(cfg, """
-            #include <atomic>
-            struct Large { int storage[100]; };
-            std::atomic<Large> x;
-            int main(int, char**) { return x.is_lock_free(); }
+          when=lambda cfg: programSucceeds(cfg, """
+            #include <stddef.h>
+            #if defined(_LIBCPP_HAS_NO_THREADS)
+              int main(int, char**) { return 1; }
+            #else
+              #include <atomic>
+              struct Large { int storage[100]; };
+              int main(int, char**) {
+                Large l;
+                std::atomic<Large> x(l);
+                (void)x.is_lock_free();
+                return 0;
+              }
+            #endif
           """)),
 
   # Some tests rely on creating shared libraries which link in the C++ Standard Library. In some


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126384.432000.patch
Type: text/x-patch
Size: 2131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220525/b9ff84e7/attachment.bin>


More information about the libcxx-commits mailing list