[PATCH] D154431: [FileCheck] Turn errors into assert in valueFromStringRepr()
Thomas Preud'homme via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 4 04:09:51 PDT 2023
thopre created this revision.
thopre added reviewers: jdenny, jhenderson, probinson, arichardson, grimar.
Herald added a subscriber: hiraditya.
Herald added a project: All.
thopre requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 <https://reviews.llvm.org/D154430>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154431
Files:
llvm/lib/FileCheck/FileCheck.cpp
llvm/unittests/FileCheck/FileCheckTest.cpp
Index: llvm/unittests/FileCheck/FileCheckTest.cpp
===================================================================
--- llvm/unittests/FileCheck/FileCheckTest.cpp
+++ llvm/unittests/FileCheck/FileCheckTest.cpp
@@ -321,7 +321,10 @@
// Wrong casing is not tested because valueFromStringRepr() relies on
// StringRef's getAsInteger() which does not allow to restrict casing.
- checkValueFromStringReprFailure(addBasePrefix("G"));
+
+ // Likewise, wrong letter digit for hex value is not tested because it is
+ // only caught by an assert in FileCheck due to getWildcardRegex()
+ // guaranteeing only valid letter digits are used.
}
TEST_P(ExpressionFormatParameterisedFixture, FormatBoolOperator) {
Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -150,10 +150,9 @@
(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);
+ assert(!ParseFailure && "unable to represent numeric value");
return toSigned(ResultValue, Negative);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154431.537046.patch
Type: text/x-patch
Size: 1451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230704/1f74809b/attachment.bin>
More information about the llvm-commits
mailing list