forked from OSchip/llvm-project
[sanitizer] Fix shift UB in LEB128 test
If u64 and uptr have the same size, then this will perform a shift by the bitwidth, which is UB. We only need this code if uptr is smaller than u64.
This commit is contained in:
parent
bf21cda7f2
commit
38ad963cc9
|
@ -25,10 +25,12 @@ static uptr BitsNeeded(u64 v) {
|
|||
if (!v)
|
||||
return 1;
|
||||
uptr r = 0;
|
||||
uptr uptr_bits = 8 * sizeof(uptr);
|
||||
while (v >> uptr_bits) {
|
||||
r += uptr_bits;
|
||||
v >>= uptr_bits;
|
||||
if (sizeof(uptr) != sizeof(u64)) {
|
||||
uptr uptr_bits = 8 * sizeof(uptr);
|
||||
while (v >> uptr_bits) {
|
||||
r += uptr_bits;
|
||||
v >>= uptr_bits;
|
||||
}
|
||||
}
|
||||
return r + MostSignificantSetBitIndex(v) + 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue