diff options
author | Louis Dionne <ldionne.2@gmail.com> | 2025-08-28 18:07:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-28 18:07:59 -0400 |
commit | 2ae4b92a1cf01b7d09f70ccc919eca2b5d02b080 (patch) | |
tree | f2df05fc9d9ea1aa7431ac734fe910a0a660df96 /llvm/tools/llvm-lto2/llvm-lto2.cpp | |
parent | 6b4506009a0f90243b7a1a5ca619cbe52532ab86 (diff) | |
download | llvm-2ae4b92a1cf01b7d09f70ccc919eca2b5d02b080.zip llvm-2ae4b92a1cf01b7d09f70ccc919eca2b5d02b080.tar.gz llvm-2ae4b92a1cf01b7d09f70ccc919eca2b5d02b080.tar.bz2 |
[libc++] Fix broken precondition of __bit_log2 (#155476)
In #135303, we started using `__bit_log2` instead of `__log2i` inside
`std::sort`. However, `__bit_log2` has a precondition that `__log2i`
didn't have, which is that the input is non-zero. While it technically
makes no sense to request the logarithm of 0, `__log2i` handled that
case and returned 0 without issues.
After switching to `__bit_log2`, passing 0 as an input results in an
unsigned integer overflow which can trigger
`-fsanitize=unsigned-integer-overflow`. While not technically UB in
itself, it's clearly not intended either.
To fix this, we add an internal assertion to `__bit_log2` which catches
the issue in our test suite, and we make sure not to violate
`__bit_log2`'s preconditions before we call it from `std::sort`.
Diffstat (limited to 'llvm/tools/llvm-lto2/llvm-lto2.cpp')
0 files changed, 0 insertions, 0 deletions