[llvm] r366398 - [RISCV] Avoid signed integer overflow UB in RISCVMatInt::generateInstSeq
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 17 21:02:58 PDT 2019
Author: asb
Date: Wed Jul 17 21:02:58 2019
New Revision: 366398
URL: http://llvm.org/viewvc/llvm-project?rev=366398&view=rev
Log:
[RISCV] Avoid signed integer overflow UB in RISCVMatInt::generateInstSeq
Found by UBSan.
Modified:
llvm/trunk/lib/Target/RISCV/Utils/RISCVMatInt.cpp
Modified: llvm/trunk/lib/Target/RISCV/Utils/RISCVMatInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/Utils/RISCVMatInt.cpp?rev=366398&r1=366397&r2=366398&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/Utils/RISCVMatInt.cpp (original)
+++ llvm/trunk/lib/Target/RISCV/Utils/RISCVMatInt.cpp Wed Jul 17 21:02:58 2019
@@ -64,7 +64,7 @@ void generateInstSeq(int64_t Val, bool I
// 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);
More information about the llvm-commits
mailing list