[llvm-commits] [llvm] r70058 - in /llvm/trunk: lib/Support/APInt.cpp unittests/ADT/APIntTest.cpp
Chris Lattner
sabre at nondot.org
Sat Apr 25 11:34:04 PDT 2009
Author: lattner
Date: Sat Apr 25 13:34:04 2009
New Revision: 70058
URL: http://llvm.org/viewvc/llvm-project?rev=70058&view=rev
Log:
Fix PR4040: APInt's string constructor is too strict
patch by Jeff Yasskin!
Modified:
llvm/trunk/lib/Support/APInt.cpp
llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=70058&r1=70057&r2=70058&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Sat Apr 25 13:34:04 2009
@@ -1918,9 +1918,9 @@
if (isNeg)
str++, slen--;
assert((slen <= numbits || radix != 2) && "Insufficient bit width");
- assert((slen*3 <= numbits || radix != 8) && "Insufficient bit width");
- assert((slen*4 <= numbits || radix != 16) && "Insufficient bit width");
- assert(((slen*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
+ assert(((slen-1)*3 <= numbits || radix != 8) && "Insufficient bit width");
+ assert(((slen-1)*4 <= numbits || radix != 16) && "Insufficient bit width");
+ assert((((slen-1)*64)/22 <= numbits || radix != 10) && "Insufficient bit width");
// Allocate memory
if (!isSingleWord())
@@ -1961,10 +1961,12 @@
}
// Shift or multiply the value by the radix
- if (shift)
- *this <<= shift;
- else
- *this *= apradix;
+ if (slen > 1) {
+ if (shift)
+ *this <<= shift;
+ else
+ *this *= apradix;
+ }
// Add in the digit we just interpreted
if (apdigit.isSingleWord())
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=70058&r1=70057&r2=70058&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Sat Apr 25 13:34:04 2009
@@ -176,4 +176,13 @@
EXPECT_EQ(zero, one.srem(neg_one));
}
+TEST(APIntTest, fromString) {
+ EXPECT_EQ(APInt(1, 0), APInt(1, "0", 1, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "-1", 2, 10));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 2));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 8));
+ EXPECT_EQ(APInt(1, 1), APInt(1, "1", 1, 16));
+}
+
}
More information about the llvm-commits
mailing list