Skip to content

Commit e586607

Browse files
committed
[libc++] Build the dylib with C++17 to allow aligned new/delete
This allows simplifying the implementation of barriers. This is a re-commit of 1ac403b, which had to be reverted in 64a9c94 because the minimum CMake version wasn't high enough. Now that we've upgraded, we can do this. Differential Revision: https://reviews.llvm.org/D75243
1 parent f3e667b commit e586607

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

libcxx/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
519519
# Required flags ==============================================================
520520
function(cxx_add_basic_build_flags target)
521521

522-
# Require C++14 for all targets. C++14 is needed to ensure constant
523-
# initialization for certain globals (ex global memory resources).
522+
# Require C++17 for all targets. C++17 is needed to use aligned allocation
523+
# in the dylib.
524524
set_target_properties(${target} PROPERTIES
525-
CXX_STANDARD 14
525+
CXX_STANDARD 17
526526
CXX_STANDARD_REQUIRED YES
527527
CXX_EXTENSIONS NO)
528528

libcxx/src/barrier.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ class __barrier_algorithm_base {
2626
} __tickets[64];
2727
};
2828

29-
ptrdiff_t& __expected;
30-
unique_ptr<char[]> __state_allocation;
31-
__state_t* __state;
29+
ptrdiff_t& __expected;
30+
unique_ptr<__state_t[]> __state;
3231

3332
_LIBCPP_HIDDEN
3433
__barrier_algorithm_base(ptrdiff_t& __expected)
3534
: __expected(__expected)
3635
{
3736
size_t const __count = (__expected + 1) >> 1;
38-
size_t const __size = sizeof(__state_t) * __count;
39-
size_t __allocation_size = __size + alignof(__state_t);
40-
__state_allocation = unique_ptr<char[]>(new char[__allocation_size]);
41-
void* __allocation = __state_allocation.get();
42-
void* const __state_ = align(alignof(__state_t), __size, __allocation, __allocation_size);
43-
__state = new (__state_) __barrier_algorithm_base::__state_t[__count];
37+
__state = unique_ptr<__state_t[]>(new __state_t[__count]);
4438
}
4539
_LIBCPP_HIDDEN
4640
bool __arrive(__barrier_phase_t __old_phase)

0 commit comments

Comments
 (0)