Skip to content

Commit

Permalink
[libc++] ADL-proof vector<bool> by adding _VSTD:: qualification on ca…
Browse files Browse the repository at this point in the history
…lls.

This affects only vectors with weird/malicious allocators,
the same corner case covered in D91708, but for `vector<bool>` this time.

Also ADL-proof <__tree>, which affects only sets and maps with weird/malicious
allocators where the ADL trap is in the *fancy pointer type*.

Also drive-by _VSTD:: qualification in the guts of std::bind,
std::packaged_task, std::condition_variable.

Differential Revision: https://reviews.llvm.org/D93424
  • Loading branch information
Arthur O'Dwyer committed Jan 6, 2021
1 parent 6d94eea commit 781c476
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 77 deletions.
28 changes: 14 additions & 14 deletions libcxx/include/__bit_reference
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ __bit_iterator<_Cp, _IsConst>
find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
{
if (static_cast<bool>(__value_))
return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return __find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
return _VSTD::__find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return _VSTD::__find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
}

// count
Expand Down Expand Up @@ -313,8 +313,8 @@ typename __bit_iterator<_Cp, _IsConst>::difference_type
count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
{
if (static_cast<bool>(__value_))
return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
return _VSTD::__count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return _VSTD::__count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
}

// fill_n
Expand Down Expand Up @@ -387,9 +387,9 @@ fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __v
if (__n > 0)
{
if (__value_)
__fill_n_true(__first, __n);
_VSTD::__fill_n_true(__first, __n);
else
__fill_n_false(__first, __n);
_VSTD::__fill_n_false(__first, __n);
}
}

Expand Down Expand Up @@ -538,8 +538,8 @@ __bit_iterator<_Cp, false>
copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
if (__first.__ctz_ == __result.__ctz_)
return __copy_aligned(__first, __last, __result);
return __copy_unaligned(__first, __last, __result);
return _VSTD::__copy_aligned(__first, __last, __result);
return _VSTD::__copy_unaligned(__first, __last, __result);
}

// copy_backward
Expand Down Expand Up @@ -685,8 +685,8 @@ __bit_iterator<_Cp, false>
copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
if (__last.__ctz_ == __result.__ctz_)
return __copy_backward_aligned(__first, __last, __result);
return __copy_backward_unaligned(__first, __last, __result);
return _VSTD::__copy_backward_aligned(__first, __last, __result);
return _VSTD::__copy_backward_unaligned(__first, __last, __result);
}

// move
Expand Down Expand Up @@ -868,8 +868,8 @@ swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __
__bit_iterator<__C2, false> __first2)
{
if (__first1.__ctz_ == __first2.__ctz_)
return __swap_ranges_aligned(__first1, __last1, __first2);
return __swap_ranges_unaligned(__first1, __last1, __first2);
return _VSTD::__swap_ranges_aligned(__first1, __last1, __first2);
return _VSTD::__swap_ranges_unaligned(__first1, __last1, __first2);
}

// rotate
Expand Down Expand Up @@ -1083,8 +1083,8 @@ bool
equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2)
{
if (__first1.__ctz_ == __first2.__ctz_)
return __equal_aligned(__first1, __last1, __first2);
return __equal_unaligned(__first1, __last1, __first2);
return _VSTD::__equal_aligned(__first1, __last1, __first2);
return _VSTD::__equal_unaligned(__first1, __last1, __first2);
}

template <class _Cp, bool _IsConst,
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/__mutex_base
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ condition_variable::wait_until(unique_lock<mutex>& __lk,
if (__t <= __now)
return cv_status::timeout;

__clock_tp_ns __t_ns = __clock_tp_ns(__safe_nanosecond_cast(__t.time_since_epoch()));
__clock_tp_ns __t_ns = __clock_tp_ns(_VSTD::__safe_nanosecond_cast(__t.time_since_epoch()));

__do_timed_wait(__lk, __t_ns);
return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
Expand Down Expand Up @@ -451,13 +451,13 @@ condition_variable::wait_for(unique_lock<mutex>& __lk,

#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
__ns_rep __now_count_ns = __safe_nanosecond_cast(__c_now.time_since_epoch()).count();
__ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(__c_now.time_since_epoch()).count();
#else
using __clock_tp_ns = time_point<system_clock, nanoseconds>;
__ns_rep __now_count_ns = __safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
__ns_rep __now_count_ns = _VSTD::__safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
#endif

__ns_rep __d_ns_count = __safe_nanosecond_cast(__d).count();
__ns_rep __d_ns_count = _VSTD::__safe_nanosecond_cast(__d).count();

if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) {
__do_timed_wait(__lk, __clock_tp_ns::max());
Expand Down
Loading

0 comments on commit 781c476

Please sign in to comment.