From bb27a14e4d41ee775d44dc8cb3957b9394d4f71a Mon Sep 17 00:00:00 2001 From: Alex Bradbury Date: Thu, 18 Jul 2019 04:02:58 +0000 Subject: [PATCH] [RISCV] Avoid signed integer overflow UB in RISCVMatInt::generateInstSeq Found by UBSan. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366398 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/RISCV/Utils/RISCVMatInt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Target/RISCV/Utils/RISCVMatInt.cpp b/lib/Target/RISCV/Utils/RISCVMatInt.cpp index 2504df5ef9b..f390ddb89e3 100644 --- a/lib/Target/RISCV/Utils/RISCVMatInt.cpp +++ b/lib/Target/RISCV/Utils/RISCVMatInt.cpp @@ -64,7 +64,7 @@ void generateInstSeq(int64_t Val, bool IsRV64, InstSeq &Res) { // performed when the recursion returns. int64_t Lo12 = SignExtend64<12>(Val); - int64_t Hi52 = (Val + 0x800) >> 12; + int64_t Hi52 = ((uint64_t)Val + 0x800ull) >> 12; int ShiftAmount = 12 + findFirstSet((uint64_t)Hi52); Hi52 = SignExtend64(Hi52 >> (ShiftAmount - 12), 64 - ShiftAmount); -- 2.40.0