[PATCH] D150797: Turn unreachable error into assert

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 09:16:12 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.

Function valueFromStringRepr() throws an error on missing 0x prefix when
parsing a number string into a value. However, getWildcardRegex() already
ensures that only text with the 0x prefix will match and be parsed,
making that error throwing code dead code. This commit turn the code
into an assert and remove the unit tests exercising that test
accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150797

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
@@ -311,7 +311,6 @@
     checkValueFromStringRepr("-5", -5);
     checkValueFromStringReprFailure(MaxUint64Str);
   } else {
-    checkValueFromStringReprFailure("-" + addBasePrefix("5"));
     checkValueFromStringRepr(addBasePrefix(MaxUint64Str), MaxUint64);
   }
 
@@ -321,9 +320,6 @@
   // Wrong casing is not tested because valueFromStringRepr() relies on
   // StringRef's getAsInteger() which does not allow to restrict casing.
   checkValueFromStringReprFailure(addBasePrefix("G"));
-
-  if (AlternateForm)
-    checkValueFromStringReprFailure("9", "missing alternate form prefix");
 }
 
 TEST_P(ExpressionFormatParameterisedFixture, FormatBoolOperator) {
Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -146,14 +146,11 @@
   bool Hex = Value == Kind::HexUpper || Value == Kind::HexLower;
   uint64_t UnsignedValue;
   bool MissingFormPrefix = AlternateForm && !StrVal.consume_front("0x");
+  (void)MissingFormPrefix;
+  assert(!MissingFormPrefix && "missing alternate form prefix");
   if (StrVal.getAsInteger(Hex ? 16 : 10, UnsignedValue))
     return ErrorDiagnostic::get(SM, StrVal, IntegerParseErrorStr);
 
-  // Error out for a missing prefix only now that we know we have an otherwise
-  // valid integer.  For example, "-0x18" is reported above instead.
-  if (MissingFormPrefix)
-    return ErrorDiagnostic::get(SM, StrVal, "missing alternate form prefix");
-
   return ExpressionValue(UnsignedValue);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150797.523079.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230517/10897c63/attachment.bin>


More information about the llvm-commits mailing list