[PATCH] D54456: [libcxx] Allow use of <atomic> in baremetal systems when threading is disabled.

Ian Tessier via Phabricator reviews at reviews.llvm.org
Mon Nov 12 17:24:48 PST 2018


itessier updated this revision to Diff 173794.
Herald added a subscriber: christof.

https://reviews.llvm.org/D54456

Files:
  CMakeLists.txt
  include/atomic
  test/libcxx/atomic_baremetal.sh.cpp


Index: test/libcxx/atomic_baremetal.sh.cpp
===================================================================
--- /dev/null
+++ test/libcxx/atomic_baremetal.sh.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that we can include <atomic> with no threads while targeting baremetal.
+
+// RUN: %build -D_LIBCPP_HAS_NO_THREADS -D_LIBCPP_BAREMETAL
+// RUN: %run
+
+#include <atomic>
+
+int main()
+{
+}
Index: include/atomic
===================================================================
--- include/atomic
+++ include/atomic
@@ -550,7 +550,7 @@
 #pragma GCC system_header
 #endif
 
-#ifdef _LIBCPP_HAS_NO_THREADS
+#if defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_BAREMETAL)
 #error <atomic> is not supported on this single threaded system
 #endif
 #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -242,6 +242,7 @@
 option(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY
     "Build libc++ with an externalized threading library.
      This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON" OFF)
+option(LIBCXX_BAREMETAL "Build libc++ for baremetal targets." OFF)
 
 # Misc options ----------------------------------------------------------------
 # FIXME: Turn -pedantic back ON. It is currently off because it warns
@@ -708,6 +709,7 @@
 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
+config_define_if(LIBCXX_BAREMETAL _LIBCPP_BAREMETAL)
 
 if (LIBCXX_ABI_DEFINES)
   set(abi_defines)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54456.173794.patch
Type: text/x-patch
Size: 2069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181113/f1748494/attachment-0001.bin>


More information about the libcxx-commits mailing list