Skip to content

Commit 73fc956

Browse files
committed
[Support] Recognise the '+' char for positive integers
Fixes #45326 Signed-off-by: Ebuka Ezike <[email protected]>
1 parent 9a6c001 commit 73fc956

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

llvm/lib/Support/StringRef.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ static unsigned GetAutoSenseRadix(StringRef &Str) {
409409

410410
bool llvm::consumeUnsignedInteger(StringRef &Str, unsigned Radix,
411411
unsigned long long &Result) {
412+
// Consume the + value
413+
Str.consume_front("+");
414+
412415
// Autosense radix if not specified.
413416
if (Radix == 0)
414417
Radix = GetAutoSenseRadix(Str);

llvm/unittests/ADT/StringRefTest.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,19 +622,21 @@ TEST(StringRefTest, Hashing) {
622622
struct UnsignedPair {
623623
const char *Str;
624624
uint64_t Expected;
625-
} Unsigned[] =
626-
{ {"0", 0}
627-
, {"255", 255}
628-
, {"256", 256}
629-
, {"65535", 65535}
630-
, {"65536", 65536}
631-
, {"4294967295", 4294967295ULL}
632-
, {"4294967296", 4294967296ULL}
633-
, {"18446744073709551615", 18446744073709551615ULL}
634-
, {"042", 34}
635-
, {"0x42", 66}
636-
, {"0b101010", 42}
637-
};
625+
} Unsigned[] = {{"0", 0},
626+
{"255", 255},
627+
{"256", 256},
628+
{"65535", 65535},
629+
{"65536", 65536},
630+
{"4294967295", 4294967295ULL},
631+
{"4294967296", 4294967296ULL},
632+
{"18446744073709551615", 18446744073709551615ULL},
633+
{"042", 34},
634+
{"0x42", 66},
635+
{"0b101010", 42},
636+
{"+42", 42},
637+
{"+042", 34},
638+
{"+0x42", 66},
639+
{"+0b101010", 42}};
638640

639641
struct SignedPair {
640642
const char *Str;

0 commit comments

Comments
 (0)