[llvm] [Support] Recognise the '+' char for positive integers (PR #135856)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 14:09:36 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Ebuka Ezike (da-viper)

<details>
<summary>Changes</summary>

Fixes https://github.com/llvm/llvm-project/issues/45326


---
Full diff: https://github.com/llvm/llvm-project/pull/135856.diff


2 Files Affected:

- (modified) llvm/lib/Support/StringRef.cpp (+3) 
- (modified) llvm/unittests/ADT/StringRefTest.cpp (+15-13) 


``````````diff
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 4f5fcb4857e80..bdf7a9aa5c7e0 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -409,6 +409,9 @@ static unsigned GetAutoSenseRadix(StringRef &Str) {
 
 bool llvm::consumeUnsignedInteger(StringRef &Str, unsigned Radix,
                                   unsigned long long &Result) {
+  // Consume the + value
+  Str.consume_front("+");
+
   // Autosense radix if not specified.
   if (Radix == 0)
     Radix = GetAutoSenseRadix(Str);
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index ec9cdc197597d..55d222a915ab5 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -622,19 +622,21 @@ TEST(StringRefTest, Hashing) {
 struct UnsignedPair {
   const char *Str;
   uint64_t Expected;
-} Unsigned[] =
-  { {"0", 0}
-  , {"255", 255}
-  , {"256", 256}
-  , {"65535", 65535}
-  , {"65536", 65536}
-  , {"4294967295", 4294967295ULL}
-  , {"4294967296", 4294967296ULL}
-  , {"18446744073709551615", 18446744073709551615ULL}
-  , {"042", 34}
-  , {"0x42", 66}
-  , {"0b101010", 42}
-  };
+} Unsigned[] = {{"0", 0},
+                {"255", 255},
+                {"256", 256},
+                {"65535", 65535},
+                {"65536", 65536},
+                {"4294967295", 4294967295ULL},
+                {"4294967296", 4294967296ULL},
+                {"18446744073709551615", 18446744073709551615ULL},
+                {"042", 34},
+                {"0x42", 66},
+                {"0b101010", 42},
+                {"+42", 42},
+                {"+042", 34},
+                {"+0x42", 66},
+                {"+0b101010", 42}};
 
 struct SignedPair {
   const char *Str;

``````````

</details>


https://github.com/llvm/llvm-project/pull/135856


More information about the llvm-commits mailing list