Return early if it fails to parse a hex string.

This patch doesn't change the behavior of the program because it
would eventually return None at end of the function. But it is
better to return None early if we know it will eventually happen.

llvm-svn: 315495
This commit is contained in:
Rui Ueyama 2017-10-11 19:30:39 +00:00
parent c530f497b8
commit 4092016b7b
1 changed files with 8 additions and 2 deletions

View File

@ -867,10 +867,16 @@ static Optional<uint64_t> parseInt(StringRef Tok) {
// Hexadecimal
uint64_t Val;
if (Tok.startswith_lower("0x") && to_integer(Tok.substr(2), Val, 16))
if (Tok.startswith_lower("0x")) {
if (!to_integer(Tok.substr(2), Val, 16))
return None;
return Val;
if (Tok.endswith_lower("H") && to_integer(Tok.drop_back(), Val, 16))
}
if (Tok.endswith_lower("H")) {
if (!to_integer(Tok.drop_back(), Val, 16))
return None;
return Val;
}
// Decimal
if (Tok.endswith_lower("K")) {