[llvm] 13eb298 - Turn unreachable error into assert

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 05:52:28 PDT 2023


Author: Thomas Preud'homme
Date: 2023-05-23T13:52:22+01:00
New Revision: 13eb298d5c3c31550fee0c889d3fd3a265450e3d

URL: https://github.com/llvm/llvm-project/commit/13eb298d5c3c31550fee0c889d3fd3a265450e3d
DIFF: https://github.com/llvm/llvm-project/commit/13eb298d5c3c31550fee0c889d3fd3a265450e3d.diff

LOG: Turn unreachable error into assert

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.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D150797

Added: 
    

Modified: 
    llvm/lib/FileCheck/FileCheck.cpp
    llvm/unittests/FileCheck/FileCheckTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index ebebe0573b0b9..f02e630ec81c4 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -146,14 +146,11 @@ ExpressionFormat::valueFromStringRepr(StringRef StrVal,
   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);
 }
 

diff  --git a/llvm/unittests/FileCheck/FileCheckTest.cpp b/llvm/unittests/FileCheck/FileCheckTest.cpp
index 6f154b181d381..142c4289dcf68 100644
--- a/llvm/unittests/FileCheck/FileCheckTest.cpp
+++ b/llvm/unittests/FileCheck/FileCheckTest.cpp
@@ -311,7 +311,6 @@ TEST_P(ExpressionFormatParameterisedFixture, FormatValueFromStringRepr) {
     checkValueFromStringRepr("-5", -5);
     checkValueFromStringReprFailure(MaxUint64Str);
   } else {
-    checkValueFromStringReprFailure("-" + addBasePrefix("5"));
     checkValueFromStringRepr(addBasePrefix(MaxUint64Str), MaxUint64);
   }
 
@@ -321,9 +320,6 @@ TEST_P(ExpressionFormatParameterisedFixture, FormatValueFromStringRepr) {
   // 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) {


        


More information about the llvm-commits mailing list