[libcxx-commits] [libcxx] 64a9c94 - Revert "[libc++] Build the dylib with C++17 to allow aligned new/delete"

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 24 19:54:27 PDT 2020


Author: Louis Dionne
Date: 2020-03-24T22:53:47-04:00
New Revision: 64a9c944fc459475b3eefed423e3b593353c0cca

URL: https://github.com/llvm/llvm-project/commit/64a9c944fc459475b3eefed423e3b593353c0cca
DIFF: https://github.com/llvm/llvm-project/commit/64a9c944fc459475b3eefed423e3b593353c0cca.diff

LOG: Revert "[libc++] Build the dylib with C++17 to allow aligned new/delete"

This reverts commit 1ac403bd145dadfa1004af29bd6c77f871caf42c, which
broke some non-libc++ build bots because they use an ancient CMake.

Added: 
    

Modified: 
    libcxx/CMakeLists.txt
    libcxx/src/barrier.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index fa194d4bffd9..8bdb24e5fd2a 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -520,10 +520,10 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 # Required flags ==============================================================
 function(cxx_add_basic_build_flags target)
 
-  # Require C++17 for all targets. C++17 is needed to use aligned allocation
-  # in the dylib.
+  # Require C++14 for all targets. C++14 is needed to ensure constant
+  # initialization for certain globals (ex global memory resources).
   set_target_properties(${target} PROPERTIES
-    CXX_STANDARD 17
+    CXX_STANDARD 14
     CXX_STANDARD_REQUIRED YES
     CXX_EXTENSIONS NO)
 

diff  --git a/libcxx/src/barrier.cpp b/libcxx/src/barrier.cpp
index 9ee476993b81..c5e33cbba3bd 100644
--- a/libcxx/src/barrier.cpp
+++ b/libcxx/src/barrier.cpp
@@ -26,15 +26,21 @@ class __barrier_algorithm_base {
         } __tickets[64];
     };
 
-    ptr
diff _t&              __expected;
-    unique_ptr<__state_t[]> __state;
+    ptr
diff _t&         __expected;
+    unique_ptr<char[]> __state_allocation;
+    __state_t*         __state;
 
     _LIBCPP_HIDDEN
     __barrier_algorithm_base(ptr
diff _t& __expected)
         : __expected(__expected)
     {
         size_t const __count = (__expected + 1) >> 1;
-        __state = unique_ptr<__state_t[]>(new __state_t[__count]);
+        size_t const __size = sizeof(__state_t) * __count;
+        size_t __allocation_size = __size + alignof(__state_t);
+        __state_allocation = unique_ptr<char[]>(new char[__allocation_size]);
+        void* __allocation = __state_allocation.get();
+        void* const __state_ = align(alignof(__state_t), __size, __allocation, __allocation_size);
+        __state = new (__state_) __barrier_algorithm_base::__state_t[__count];
     }
     _LIBCPP_HIDDEN
     bool __arrive(__barrier_phase_t __old_phase)


        


More information about the libcxx-commits mailing list