-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Support] Recognise the '+' char for positive integers #135856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Fixes llvm#45326 Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
@llvm/pr-subscribers-llvm-support Author: Ebuka Ezike (da-viper) ChangesFixes #45326 Full diff: https://github.com/llvm/llvm-project/pull/135856.diff 2 Files Affected:
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;
|
@llvm/pr-subscribers-llvm-adt Author: Ebuka Ezike (da-viper) ChangesFixes #45326 Full diff: https://github.com/llvm/llvm-project/pull/135856.diff 2 Files Affected:
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;
|
could you check a few callers of this function to see if they'd generally be on-board with leading |
It will only be more permissive if the I did check the callers of the The only new change was in the |
Even if it doesn't mean anything else - if the consumer isn't intending to accept leading
That change seems fine - but yeah, still unsure about making everyone else accept leading Wouldn't mind a second or third opinion. |
Fixes #45326