]> granicus.if.org Git - llvm/commitdiff
Speculative fix for build failures due to consumeInteger.
authorZachary Turner <zturner@google.com>
Thu, 22 Sep 2016 15:55:05 +0000 (15:55 +0000)
committerZachary Turner <zturner@google.com>
Thu, 22 Sep 2016 15:55:05 +0000 (15:55 +0000)
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

lib/Support/StringRef.cpp
unittests/ADT/StringRefTest.cpp

index 7503fac240ad084458e78a4a5bf7fd576d9800eb..51e0394d8bd50ac7eae8eb17452037bb4744c1ab 100644 (file)
@@ -351,6 +351,9 @@ size_t StringRef::count(StringRef Str) const {
 }
 
 static unsigned GetAutoSenseRadix(StringRef &Str) {
+  if (Str.empty())
+    return 10;
+
   if (Str.startswith("0x") || Str.startswith("0X")) {
     Str = Str.substr(2);
     return 16;
index 4249f231481d91ff2a606b9bb362b668cb7227b1..40ab4e038b82e06ef5496d867081080a67008e8e 100644 (file)
@@ -571,7 +571,8 @@ TEST(StringRefTest, getAsInteger) {
 
 
 static const char* BadStrings[] = {
-    "18446744073709551617"  // value just over max
+    ""                      // empty string
+  , "18446744073709551617"  // value just over max
   , "123456789012345678901" // value way too large
   , "4t23v"                 // illegal decimal characters
   , "0x123W56"              // illegal hex characters