[PATCH] D23719: [libc++] Use C11 for atomics check

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 10:37:57 PDT 2016


smeenai created this revision.
smeenai added reviewers: beanz, compnerd, EricWF, mclow.lists.
smeenai added a subscriber: cfe-commits.

The purpose of the check is to see if atomics are present and if they
require an explicit -latomic to link. We can achieve this equally well
by testing for C11 atomics.

The main motivation is to ease bootstrapping slightly, by cutting down
on the number of configuration steps which require an existing C++
library. It also eases cross compilation against non-standard C++
libraries, which would otherwise require passing a -nostdlib to the
driver and adjusting CMAKE_REQUIRED_LIBRARIES accordingly.

https://reviews.llvm.org/D23719

Files:
  cmake/Modules/CheckLibcxxAtomic.cmake

Index: cmake/Modules/CheckLibcxxAtomic.cmake
===================================================================
--- cmake/Modules/CheckLibcxxAtomic.cmake
+++ cmake/Modules/CheckLibcxxAtomic.cmake
@@ -1,4 +1,4 @@
-INCLUDE(CheckCXXSourceCompiles)
+INCLUDE(CheckCSourceCompiles)
 
 # Sometimes linking against libatomic is required for atomic ops, if
 # the platform doesn't support lock-free atomics.
@@ -9,17 +9,16 @@
 
 function(check_cxx_atomics varname)
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include")
+  set(CMAKE_REQUIRED_FLAGS "-std=c11")
   if (${LIBCXX_GCC_TOOLCHAIN})
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
   endif()
-  check_cxx_source_compiles("
-#include <cstdint>
-#include <atomic>
-std::atomic<uintptr_t> x;
-std::atomic<uintmax_t> y;
+  check_c_source_compiles("
+#include <stdatomic.h>
+atomic_uintptr_t x;
+atomic_uintmax_t y;
 int main() {
-  return x + y;
+  return atomic_load(&x) + atomic_load(&y);
 }
 " ${varname})
   set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23719.68711.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160819/16f5dcc9/attachment-0001.bin>


More information about the cfe-commits mailing list