Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 20bb032

Browse files
author
Zachary Turner
committed
Speculative fix for build failures due to consumeInteger.
A recent patch added support for consumeInteger() and made getAsInteger delegate to this function. A few buildbots are failing as a result with an assertion failure. On a hunch, I tested what happens if I call getAsInteger() on an empty string, and sure enough it crashes the same way that the buildbots are crashing. I confirmed that getAsInteger() on an empty string did not crash before my patch, so I suspect this to be the cause. I also added a unit test for the empty string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282170 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3e55f3d commit 20bb032

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/Support/StringRef.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ size_t StringRef::count(StringRef Str) const {
351351
}
352352

353353
static unsigned GetAutoSenseRadix(StringRef &Str) {
354+
if (Str.empty())
355+
return 10;
356+
354357
if (Str.startswith("0x") || Str.startswith("0X")) {
355358
Str = Str.substr(2);
356359
return 16;

unittests/ADT/StringRefTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ TEST(StringRefTest, getAsInteger) {
571571

572572

573573
static const char* BadStrings[] = {
574-
"18446744073709551617" // value just over max
574+
"" // empty string
575+
, "18446744073709551617" // value just over max
575576
, "123456789012345678901" // value way too large
576577
, "4t23v" // illegal decimal characters
577578
, "0x123W56" // illegal hex characters

0 commit comments

Comments
 (0)