summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-20 02:03:09 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-20 02:03:09 +0000
commite49252cea12515d059b9a62ac458826498638ea3 (patch)
tree6d114997c29d2fb12982b767b420d8dc05d105ab /llvm
parent36162d0ffb683e809cdfd7c0dd9316dba806b2de (diff)
downloadbcm5719-llvm-e49252cea12515d059b9a62ac458826498638ea3.tar.gz
bcm5719-llvm-e49252cea12515d059b9a62ac458826498638ea3.zip
[APInt] Add back the asserts that check that the APInt shift methods aren't called with values larger than BitWidth.
The underlying tcShiftRight/tcShiftLeft functions support the larger bit widths but the APInt interface shouldn't rely on that. llvm-svn: 300811
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/APInt.h6
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp4
2 files changed, 6 insertions, 4 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index b87cf89bba5..2fafeafb6ad 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -844,8 +844,9 @@ public:
///
/// \returns *this after shifting left by ShiftAmt
APInt &operator<<=(unsigned ShiftAmt) {
+ assert(ShiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) {
- if (ShiftAmt >= BitWidth)
+ if (ShiftAmt == BitWidth)
VAL = 0;
else
VAL <<= ShiftAmt;
@@ -890,8 +891,9 @@ public:
/// Logical right-shift this APInt by ShiftAmt in place.
void lshrInPlace(unsigned ShiftAmt) {
+ assert(ShiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) {
- if (ShiftAmt >= BitWidth)
+ if (ShiftAmt == BitWidth)
VAL = 0;
else
VAL >>= ShiftAmt;
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 0f1d2d6d8f9..7d451836ad9 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -2021,7 +2021,7 @@ TEST(APIntTest, LogicalRightShift) {
// Ensure we handle large shifts of multi-word.
const APInt neg_one(128, static_cast<uint64_t>(-1), true);
- EXPECT_EQ(0, neg_one.lshr(257));
+ EXPECT_EQ(0, neg_one.lshr(128));
}
TEST(APIntTest, LeftShift) {
@@ -2054,7 +2054,7 @@ TEST(APIntTest, LeftShift) {
// Ensure we handle large shifts of multi-word.
const APInt neg_one(128, static_cast<uint64_t>(-1), true);
- EXPECT_EQ(0, neg_one.shl(257));
+ EXPECT_EQ(0, neg_one.shl(128));
}
} // end anonymous namespace
OpenPOWER on IntegriCloud