mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-18 17:55:18 +00:00
Fix PR4040: APInt's string constructor is too strict
patch by Jeff Yasskin! llvm-svn: 70058
This commit is contained in:
parent
b47e34ac59
commit
d68b203337
@ -1918,9 +1918,9 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen,
|
||||
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 @@ void APInt::fromString(unsigned numbits, const char *str, unsigned slen,
|
||||
}
|
||||
|
||||
// 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())
|
||||
|
@ -176,4 +176,13 @@ TEST(APIntTest, i1) {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user