aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@arm.com>2023-06-30 23:29:12 +0100
committerThomas Preud'homme <thomas.preudhomme@arm.com>2023-08-07 21:27:44 +0100
commitb743c19360a67af4a709bd839e8c80ad17f71a1c (patch)
tree007b6c470db338ae93ab2fe079c245a19e938a18 /llvm/lib/FileCheck/FileCheck.cpp
parent4dce6d3061358dae6f61f1aa0b578e19c9a95151 (diff)
downloadllvm-b743c19360a67af4a709bd839e8c80ad17f71a1c.zip
llvm-b743c19360a67af4a709bd839e8c80ad17f71a1c.tar.gz
llvm-b743c19360a67af4a709bd839e8c80ad17f71a1c.tar.bz2
[FileCheck] Turn errors into assert in valueFromStringRepr()
getWildcardRegex() guarantees that only valid hex numbers are matched by FileCheck numeric expressions. This commit therefore only asserts the lack of parsing failure in valueFromStringRepr(). Depends On D154430 Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D154431
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 60a0d59..49fda8f 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -134,15 +134,9 @@ static APInt toSigned(APInt AbsVal, bool Negative) {
return Result;
}
-Expected<APInt>
-ExpressionFormat::valueFromStringRepr(StringRef StrVal,
- const SourceMgr &SM) const {
+APInt ExpressionFormat::valueFromStringRepr(StringRef StrVal,
+ const SourceMgr &SM) const {
bool ValueIsSigned = Value == Kind::Signed;
- // Both the FileCheck utility and library only call this method with a valid
- // value in StrVal. This is guaranteed by the regex returned by
- // getWildcardRegex() above. Only underflow and overflow errors can thus
- // occur. However new uses of this method could be added in the future so
- // the error message does not make assumptions about StrVal.
bool Negative = StrVal.consume_front("-");
bool Hex = Value == Kind::HexUpper || Value == Kind::HexLower;
bool MissingFormPrefix =
@@ -150,10 +144,12 @@ ExpressionFormat::valueFromStringRepr(StringRef StrVal,
(void)MissingFormPrefix;
assert(!MissingFormPrefix && "missing alternate form prefix");
APInt ResultValue;
- bool ParseFailure = StrVal.getAsInteger(Hex ? 16 : 10, ResultValue);
- if (ParseFailure)
- return ErrorDiagnostic::get(SM, StrVal,
- "unable to represent numeric value");
+ [[maybe_unused]] bool ParseFailure =
+ StrVal.getAsInteger(Hex ? 16 : 10, ResultValue);
+ // Both the FileCheck utility and library only call this method with a valid
+ // value in StrVal. This is guaranteed by the regex returned by
+ // getWildcardRegex() above.
+ assert(!ParseFailure && "unable to represent numeric value");
return toSigned(ResultValue, Negative);
}
@@ -1176,10 +1172,8 @@ Pattern::MatchResult Pattern::match(StringRef Buffer,
StringRef MatchedValue = MatchInfo[CaptureParenGroup];
ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat();
- Expected<APInt> Value = Format.valueFromStringRepr(MatchedValue, SM);
- if (!Value)
- return MatchResult(TheMatch, Value.takeError());
- DefinedNumericVariable->setValue(*Value, MatchedValue);
+ APInt Value = Format.valueFromStringRepr(MatchedValue, SM);
+ DefinedNumericVariable->setValue(Value, MatchedValue);
}
return MatchResult(TheMatch, Error::success());