Skip to content

Commit

Permalink
APInt: update asserts for base-36
Browse files Browse the repository at this point in the history
Hexatridecimal was added in r139695.

And fix the unittest that now triggers the assert.

llvm-svn: 146754
  • Loading branch information
nobled committed Dec 16, 2011
1 parent 13f6718 commit 1c419ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion llvm/lib/Support/APInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
bool Signed, bool formatAsCLiteral) const {
assert((Radix == 10 || Radix == 8 || Radix == 16 || Radix == 2 ||
Radix == 36) &&
"Radix should be 2, 8, 10, or 16!");
"Radix should be 2, 8, 10, 16, or 36!");

const char *Prefix = "";
if (formatAsCLiteral) {
Expand All @@ -2202,9 +2202,13 @@ void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,
case 8:
Prefix = "0";
break;
case 10:
break; // No prefix
case 16:
Prefix = "0x";
break;
default:
llvm_unreachable("Invalid radix!");
}
}

Expand Down
6 changes: 3 additions & 3 deletions llvm/unittests/ADT/APIntTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ TEST(APIntTest, toString) {
APInt(8, 0).toString(S, 16, true, true);
EXPECT_EQ(S.str().str(), "0x0");
S.clear();
APInt(8, 0).toString(S, 36, true, true);
APInt(8, 0).toString(S, 36, true, false);
EXPECT_EQ(S.str().str(), "0");
S.clear();

Expand All @@ -371,7 +371,7 @@ TEST(APIntTest, toString) {
APInt(8, 255, isSigned).toString(S, 16, isSigned, true);
EXPECT_EQ(S.str().str(), "0xFF");
S.clear();
APInt(8, 255, isSigned).toString(S, 36, isSigned, true);
APInt(8, 255, isSigned).toString(S, 36, isSigned, false);
EXPECT_EQ(S.str().str(), "73");
S.clear();

Expand All @@ -388,7 +388,7 @@ TEST(APIntTest, toString) {
APInt(8, 255, isSigned).toString(S, 16, isSigned, true);
EXPECT_EQ(S.str().str(), "-0x1");
S.clear();
APInt(8, 255, isSigned).toString(S, 36, isSigned, true);
APInt(8, 255, isSigned).toString(S, 36, isSigned, false);
EXPECT_EQ(S.str().str(), "-1");
S.clear();
}
Expand Down

0 comments on commit 1c419ff

Please sign in to comment.