aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorJonathan Roelofs <jonathan@codesourcery.com>2016-08-10 19:50:14 +0000
committerJonathan Roelofs <jonathan@codesourcery.com>2016-08-10 19:50:14 +0000
commit851b79dc4d96c6331093d273fdc51eb3c65cb72b (patch)
tree052d07c3ecce65c22c82242632b0412deaf5e343 /llvm/lib/Support/APInt.cpp
parent9ef6b6b4f4e4004f260563e312036d7be132cfbf (diff)
downloadllvm-851b79dc4d96c6331093d273fdc51eb3c65cb72b.zip
llvm-851b79dc4d96c6331093d273fdc51eb3c65cb72b.tar.gz
llvm-851b79dc4d96c6331093d273fdc51eb3c65cb72b.tar.bz2
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
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp6
1 files changed, 1 insertions, 5 deletions
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 @@ APInt APInt::ashr(unsigned shiftAmt) const {
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.