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
This commit is contained in:
Thomas Preud'homme 2023-05-16 09:22:01 +00:00
parent c37ced7d02
commit 13eb298d5c
2 changed files with 2 additions and 9 deletions

View File

@ -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);
}

View File

@ -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) {