Skip to content

Commit

Permalink
Fix UBSAN in __ubsan::Value::getSIntValue
Browse files Browse the repository at this point in the history
/home/marxin/Programming/gcc2/libsanitizer/ubsan/ubsan_value.cpp:77:25: runtime error: left shift of 0x0000000000000000fffffffffffffffb by 96 places cannot be represented in type '__int128'
    #0 0x7ffff754edfe in __ubsan::Value::getSIntValue() const /home/marxin/Programming/gcc2/libsanitizer/ubsan/ubsan_value.cpp:77
    #1 0x7ffff7548719 in __ubsan::Value::isNegative() const /home/marxin/Programming/gcc2/libsanitizer/ubsan/ubsan_value.h:190
    rust-lang#2 0x7ffff7542a34 in handleShiftOutOfBoundsImpl /home/marxin/Programming/gcc2/libsanitizer/ubsan/ubsan_handlers.cpp:338
    rust-lang#3 0x7ffff75431b7 in __ubsan_handle_shift_out_of_bounds /home/marxin/Programming/gcc2/libsanitizer/ubsan/ubsan_handlers.cpp:370
    rust-lang#4 0x40067f in main (/home/marxin/Programming/testcases/a.out+0x40067f)
    rust-lang#5 0x7ffff72c8b24 in __libc_start_main (/lib64/libc.so.6+0x27b24)
    rust-lang#6 0x4005bd in _start (/home/marxin/Programming/testcases/a.out+0x4005bd)

Differential Revision: https://reviews.llvm.org/D97263
  • Loading branch information
marxin committed Feb 23, 2021
1 parent ebca13c commit 16ede09
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compiler-rt/lib/ubsan/ubsan_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SIntMax Value::getSIntValue() const {
// to SIntMax.
const unsigned ExtraBits =
sizeof(SIntMax) * 8 - getType().getIntegerBitWidth();
return SIntMax(Val) << ExtraBits >> ExtraBits;
return SIntMax(UIntMax(Val) << ExtraBits) >> ExtraBits;
}
if (getType().getIntegerBitWidth() == 64)
return *reinterpret_cast<s64*>(Val);
Expand Down

0 comments on commit 16ede09

Please sign in to comment.