-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118395 where this was first reported.
Everything below only applies when _LIBCPP_HAS_NO_TREE_BARRIER is undefined, but that seems to be always true? I'm not sure, see
llvm-project/libcxx/test/tools/clang_tidy_checks/internal_ftm_use.cpp
Lines 29 to 30 in 3def49c
| // TODO: Why does this macro even exist? | |
| "_LIBCPP_HAS_NO_TREE_BARRIER", |
The std::barrier(ptrdiff_t, CompletionFunction) is supposed to be constexpr. It can't be, because it calls a non-inline function which allocates memory.
Also std::barrier<>(std::barrier<>::max()) should be valid, but max() just returns numeric_limits<ptrdiff_t>::max() and then the non-inline allocating function does:
llvm-project/libcxx/src/barrier.cpp
Lines 28 to 29 in 3def49c
| size_t const __count = (__expected + 1) >> 1; | |
| __state_ = unique_ptr<__state_t[]>(new __state_t[__count]); |
so if __expected == max() then __expected + 1 overflows, with undefined behaviour.
Yay.