Fix UB in APInt::ashr
i64 -1, whose sign bit is the 0th one, can't be left shifted without invoking UB.
https://reviews.llvm.org/D23362
llvm-svn: 278280
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 8c921ce..31ffffc 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1042,11 +1042,7 @@
if (isSingleWord()) {
if (shiftAmt == BitWidth)
return APInt(BitWidth, 0); // undefined
- else {
- unsigned SignBit = APINT_BITS_PER_WORD - BitWidth;
- return APInt(BitWidth,
- (((int64_t(VAL) << SignBit) >> SignBit) >> shiftAmt));
- }
+ return APInt(BitWidth, SignExtend64(VAL, BitWidth) >> shiftAmt);
}
// If all the bits were shifted out, the result is, technically, undefined.