aboutsummaryrefslogtreecommitdiff
path: root/gcc/expr.cc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-01-09 21:50:31 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2025-01-30 11:22:28 +0000
commit34d8c842b8d12c69b9335f1b63453920f056e6e1 (patch)
tree928ee0897530962029f22972278f5af2392b33a2 /gcc/expr.cc
parentbea86e82146b9b3655e8073eef37723832862ed4 (diff)
downloadgcc-34d8c842b8d12c69b9335f1b63453920f056e6e1.zip
gcc-34d8c842b8d12c69b9335f1b63453920f056e6e1.tar.gz
gcc-34d8c842b8d12c69b9335f1b63453920f056e6e1.tar.bz2
libstdc++: Use safe integer comparisons in std::latch [PR98749]
The std::latch::max() function assumes that the returned value can be represented by ptrdiff_t, which is true when __platform_wait_t is int (e.g. on Linux) but not when it's unsigned long, which is the case for most other 64-bit targets. We should use the smaller of PTRDIFF_MAX and std::numeric_limits<__platform_wait_t>::max(). Use std::cmp_less to do a safe comparison that works for all types. We can also use std::cmp_less and std::cmp_equal in std::latch::count_down so that we don't need to deal with comparisons between signed and unsigned. Also add a missing precondition check to constructor and fix the existing check in count_down which was duplicated by mistake. libstdc++-v3/ChangeLog: PR libstdc++/98749 * include/std/latch (latch::max()): Ensure the return value is representable as the return type. (latch::latch(ptrdiff_t)): Add assertion. (latch::count_down): Fix copy & pasted duplicate assertion. Use std::cmp_equal to compare __platform_wait_t and ptrdiff_t values. (latch::_M_a): Use defined constant for alignment. * testsuite/30_threads/latch/1.cc: Check max(). Check constant initialization works for values in the valid range. Check alignment.
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions