[llvm] r282170 - Speculative fix for build failures due to consumeInteger.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 08:55:05 PDT 2016
Author: zturner
Date: Thu Sep 22 10:55:05 2016
New Revision: 282170
URL: http://llvm.org/viewvc/llvm-project?rev=282170&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Support/StringRef.cpp
llvm/trunk/unittests/ADT/StringRefTest.cpp
Modified: llvm/trunk/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=282170&r1=282169&r2=282170&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Thu Sep 22 10:55:05 2016
@@ -351,6 +351,9 @@ size_t StringRef::count(StringRef Str) c
}
static unsigned GetAutoSenseRadix(StringRef &Str) {
+ if (Str.empty())
+ return 10;
+
if (Str.startswith("0x") || Str.startswith("0X")) {
Str = Str.substr(2);
return 16;
Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=282170&r1=282169&r2=282170&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Thu Sep 22 10:55:05 2016
@@ -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
More information about the llvm-commits
mailing list