diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index b344b71764868..60a0d5982afe9 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -78,8 +78,7 @@ Expected ExpressionFormat::getWildcardRegex() const { } Expected -ExpressionFormat::getMatchingString(ExpressionValue IntegerValue) const { - APInt IntValue = IntegerValue.getAPIntValue(); +ExpressionFormat::getMatchingString(APInt IntValue) const { if (Value != Kind::Signed && IntValue.isNegative()) return make_error(); @@ -135,7 +134,7 @@ static APInt toSigned(APInt AbsVal, bool Negative) { return Result; } -Expected +Expected ExpressionFormat::valueFromStringRepr(StringRef StrVal, const SourceMgr &SM) const { bool ValueIsSigned = Value == Kind::Signed; @@ -155,76 +154,59 @@ ExpressionFormat::valueFromStringRepr(StringRef StrVal, if (ParseFailure) return ErrorDiagnostic::get(SM, StrVal, "unable to represent numeric value"); - return ExpressionValue(toSigned(ResultValue, Negative)); + return toSigned(ResultValue, Negative); } -Expected llvm::exprAdd(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().sadd_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected llvm::exprAdd(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.sadd_ov(RightOperand, Overflow); } -Expected llvm::exprSub(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().ssub_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected llvm::exprSub(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.ssub_ov(RightOperand, Overflow); } -Expected llvm::exprMul(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().smul_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected llvm::exprMul(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.smul_ov(RightOperand, Overflow); } -Expected llvm::exprDiv(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected llvm::exprDiv(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { // Check for division by zero. - if (RightOperand.getAPIntValue().isZero()) + if (RightOperand.isZero()) return make_error(); - APInt Result = LeftOperand.getAPIntValue().sdiv_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); + return LeftOperand.sdiv_ov(RightOperand, Overflow); } -Expected llvm::exprMax(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected llvm::exprMax(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { Overflow = false; - return LeftOperand.getAPIntValue().slt(RightOperand.getAPIntValue()) - ? RightOperand - : LeftOperand; + return LeftOperand.slt(RightOperand) ? RightOperand : LeftOperand; } -Expected llvm::exprMin(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected llvm::exprMin(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { Overflow = false; - if (cantFail(exprMax(LeftOperand, RightOperand, Overflow)).getAPIntValue() == - LeftOperand.getAPIntValue()) + if (cantFail(exprMax(LeftOperand, RightOperand, Overflow)) == LeftOperand) return RightOperand; return LeftOperand; } -Expected NumericVariableUse::eval() const { - std::optional Value = Variable->getValue(); +Expected NumericVariableUse::eval() const { + std::optional Value = Variable->getValue(); if (Value) return *Value; return make_error(getExpressionStr()); } -Expected BinaryOperation::eval() const { - Expected MaybeLeftOp = LeftOperand->eval(); - Expected MaybeRightOp = RightOperand->eval(); +Expected BinaryOperation::eval() const { + Expected MaybeLeftOp = LeftOperand->eval(); + Expected MaybeRightOp = RightOperand->eval(); // Bubble up any error (e.g. undefined variables) in the recursive // evaluation. @@ -237,8 +219,8 @@ Expected BinaryOperation::eval() const { return std::move(Err); } - APInt LeftOp = MaybeLeftOp->getAPIntValue(); - APInt RightOp = MaybeRightOp->getAPIntValue(); + APInt LeftOp = *MaybeLeftOp; + APInt RightOp = *MaybeRightOp; bool Overflow; // Ensure both operands have the same bitwidth. unsigned LeftBitWidth = LeftOp.getBitWidth(); @@ -247,8 +229,7 @@ Expected BinaryOperation::eval() const { LeftOp = LeftOp.sext(NewBitWidth); RightOp = RightOp.sext(NewBitWidth); do { - Expected MaybeResult = - EvalBinop(ExpressionValue(LeftOp), ExpressionValue(RightOp), Overflow); + Expected MaybeResult = EvalBinop(LeftOp, RightOp, Overflow); if (!MaybeResult) return MaybeResult.takeError(); @@ -291,8 +272,7 @@ BinaryOperation::getImplicitFormat(const SourceMgr &SM) const { Expected NumericSubstitution::getResult() const { assert(ExpressionPointer->getAST() != nullptr && "Substituting empty expression"); - Expected EvaluatedValue = - ExpressionPointer->getAST()->eval(); + Expected EvaluatedValue = ExpressionPointer->getAST()->eval(); if (!EvaluatedValue) return EvaluatedValue.takeError(); ExpressionFormat Format = ExpressionPointer->getFormat(); @@ -1117,7 +1097,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer, TmpStr = RegExStr; if (LineNumber) Context->LineVariable->setValue( - ExpressionValue(APInt(sizeof(*LineNumber) * 8, *LineNumber))); + APInt(sizeof(*LineNumber) * 8, *LineNumber)); size_t InsertOffset = 0; // Substitute all string variables and expressions whose values are only @@ -1196,8 +1176,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer, StringRef MatchedValue = MatchInfo[CaptureParenGroup]; ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat(); - Expected Value = - Format.valueFromStringRepr(MatchedValue, SM); + Expected Value = Format.valueFromStringRepr(MatchedValue, SM); if (!Value) return MatchResult(TheMatch, Value.takeError()); DefinedNumericVariable->setValue(*Value, MatchedValue); @@ -2583,7 +2562,7 @@ Error FileCheckPatternContext::defineCmdlineVariables( // to, since the expression of a command-line variable definition should // only use variables defined earlier on the command-line. If not, this // is an error and we report it. - Expected Value = Expression->getAST()->eval(); + Expected Value = Expression->getAST()->eval(); if (!Value) { Errs = joinErrors(std::move(Errs), Value.takeError()); continue; diff --git a/llvm/lib/FileCheck/FileCheckImpl.h b/llvm/lib/FileCheck/FileCheckImpl.h index ff87a1eea40b9..f5f8ea2ab856b 100644 --- a/llvm/lib/FileCheck/FileCheckImpl.h +++ b/llvm/lib/FileCheck/FileCheckImpl.h @@ -32,8 +32,6 @@ namespace llvm { // Numeric substitution handling code. //===----------------------------------------------------------------------===// -class ExpressionValue; - /// Type representing the format an expression value should be textualized into /// for matching. Used to represent both explicit format specifiers as well as /// implicit format from using numeric variables. @@ -95,14 +93,14 @@ struct ExpressionFormat { /// \returns the string representation of \p Value in the format represented /// by this instance, or an error if conversion to this format failed or the /// format is NoFormat. - Expected getMatchingString(ExpressionValue Value) const; + Expected getMatchingString(APInt Value) const; /// \returns the value corresponding to string representation \p StrVal /// according to the matching format represented by this instance or an error /// with diagnostic against \p SM if \p StrVal does not correspond to a valid /// and representable value. - Expected valueFromStringRepr(StringRef StrVal, - const SourceMgr &SM) const; + Expected valueFromStringRepr(StringRef StrVal, + const SourceMgr &SM) const; }; /// Class to represent an overflow error that might result when manipulating a @@ -118,31 +116,14 @@ class OverflowError : public ErrorInfo { void log(raw_ostream &OS) const override { OS << "overflow error"; } }; -/// Class representing a numeric value. -class ExpressionValue { -private: - APInt Value; - -public: - ExpressionValue(APInt Val) : Value(Val) {} - - APInt getAPIntValue() const { return Value; } -}; - /// Performs operation and \returns its result or an error in case of failure, /// such as if an overflow occurs. -Expected exprAdd(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); -Expected exprSub(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); -Expected exprMul(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); -Expected exprDiv(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); -Expected exprMax(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); -Expected exprMin(const ExpressionValue &Lhs, - const ExpressionValue &Rhs, bool &Overflow); +Expected exprAdd(const APInt &Lhs, const APInt &Rhs, bool &Overflow); +Expected exprSub(const APInt &Lhs, const APInt &Rhs, bool &Overflow); +Expected exprMul(const APInt &Lhs, const APInt &Rhs, bool &Overflow); +Expected exprDiv(const APInt &Lhs, const APInt &Rhs, bool &Overflow); +Expected exprMax(const APInt &Lhs, const APInt &Rhs, bool &Overflow); +Expected exprMin(const APInt &Lhs, const APInt &Rhs, bool &Overflow); /// Base class representing the AST of a given expression. class ExpressionAST { @@ -158,7 +139,7 @@ class ExpressionAST { /// Evaluates and \returns the value of the expression represented by this /// AST or an error if evaluation fails. - virtual Expected eval() const = 0; + virtual Expected eval() const = 0; /// \returns either the implicit format of this AST, a diagnostic against /// \p SM if implicit formats of the AST's components conflict, or NoFormat @@ -174,14 +155,14 @@ class ExpressionAST { class ExpressionLiteral : public ExpressionAST { private: /// Actual value of the literal. - ExpressionValue Value; + APInt Value; public: explicit ExpressionLiteral(StringRef ExpressionStr, APInt Val) : ExpressionAST(ExpressionStr), Value(Val) {} /// \returns the literal's value. - Expected eval() const override { return Value; } + Expected eval() const override { return Value; } }; /// Class to represent an undefined variable error, which quotes that @@ -240,7 +221,7 @@ class NumericVariable { ExpressionFormat ImplicitFormat; /// Value of numeric variable, if defined, or std::nullopt otherwise. - std::optional Value; + std::optional Value; /// The input buffer's string from which Value was parsed, or std::nullopt. /// See comments on getStringValue for a discussion of the std::nullopt case. @@ -267,7 +248,7 @@ class NumericVariable { ExpressionFormat getImplicitFormat() const { return ImplicitFormat; } /// \returns this variable's value. - std::optional getValue() const { return Value; } + std::optional getValue() const { return Value; } /// \returns the input buffer's string from which this variable's value was /// parsed, or std::nullopt if the value is not yet defined or was not parsed @@ -279,7 +260,7 @@ class NumericVariable { /// Sets value of this numeric variable to \p NewValue, and sets the input /// buffer string from which it was parsed to \p NewStrValue. See comments on /// getStringValue for a discussion of when the latter can be std::nullopt. - void setValue(ExpressionValue NewValue, + void setValue(APInt NewValue, std::optional NewStrValue = std::nullopt) { Value = NewValue; StrValue = NewStrValue; @@ -308,7 +289,7 @@ class NumericVariableUse : public ExpressionAST { NumericVariableUse(StringRef Name, NumericVariable *Variable) : ExpressionAST(Name), Variable(Variable) {} /// \returns the value of the variable referenced by this instance. - Expected eval() const override; + Expected eval() const override; /// \returns implicit format of this numeric variable. Expected @@ -318,9 +299,7 @@ class NumericVariableUse : public ExpressionAST { }; /// Type of functions evaluating a given binary operation. -using binop_eval_t = Expected (*)(const ExpressionValue &, - const ExpressionValue &, - bool &); +using binop_eval_t = Expected (*)(const APInt &, const APInt &, bool &); /// Class representing a single binary operation in the AST of an expression. class BinaryOperation : public ExpressionAST { @@ -347,7 +326,7 @@ class BinaryOperation : public ExpressionAST { /// using EvalBinop on the result of recursively evaluating the operands. /// \returns the expression value or an error if an undefined numeric /// variable is used in one of the operands. - Expected eval() const override; + Expected eval() const override; /// \returns the implicit format of this AST, if any, a diagnostic against /// \p SM if the implicit formats of the AST's components conflict, or no diff --git a/llvm/unittests/FileCheck/FileCheckTest.cpp b/llvm/unittests/FileCheck/FileCheckTest.cpp index eb7c4dab301f8..15036660b816b 100644 --- a/llvm/unittests/FileCheck/FileCheckTest.cpp +++ b/llvm/unittests/FileCheck/FileCheckTest.cpp @@ -188,8 +188,7 @@ struct ExpressionFormatParameterisedFixture template void checkMatchingString(T Val, StringRef ExpectedStr) { APInt Value(LiteralsBitWidth, Val, std::is_signed_v); - Expected MatchingString = - Format.getMatchingString(ExpressionValue(Value)); + Expected MatchingString = Format.getMatchingString(Value); ASSERT_THAT_EXPECTED(MatchingString, Succeeded()) << "No matching string for " << Val; EXPECT_EQ(*MatchingString, ExpectedStr); @@ -197,34 +196,33 @@ struct ExpressionFormatParameterisedFixture template void checkMatchingStringFailure(T Val) { APInt Value(LiteralsBitWidth, Val, std::is_signed_v); - Expected MatchingString = - Format.getMatchingString(ExpressionValue(Value)); - // Error message tested in ExpressionValue unit tests. + Expected MatchingString = Format.getMatchingString(Value); + // Error message tested in ExpressionFormat unit tests. EXPECT_THAT_EXPECTED(MatchingString, Failed()); } - Expected getValueFromStringReprFailure(StringRef Str) { + Expected getValueFromStringReprFailure(StringRef Str) { StringRef BufferizedStr = bufferize(SM, Str); return Format.valueFromStringRepr(BufferizedStr, SM); } template void checkValueFromStringRepr(StringRef Str, T ExpectedVal) { - Expected ResultValue = getValueFromStringReprFailure(Str); + Expected ResultValue = getValueFromStringReprFailure(Str); ASSERT_THAT_EXPECTED(ResultValue, Succeeded()) << "Failed to get value from " << Str; - APInt ResValue = ResultValue->getAPIntValue(); - ASSERT_EQ(ResValue.isNegative(), ExpectedVal < 0) + ASSERT_EQ(ResultValue->isNegative(), ExpectedVal < 0) << "Value for " << Str << " is not " << ExpectedVal; - if (ResValue.isNegative()) - EXPECT_EQ(ResValue.getSExtValue(), static_cast(ExpectedVal)); + if (ResultValue->isNegative()) + EXPECT_EQ(ResultValue->getSExtValue(), static_cast(ExpectedVal)); else - EXPECT_EQ(ResValue.getZExtValue(), static_cast(ExpectedVal)); + EXPECT_EQ(ResultValue->getZExtValue(), + static_cast(ExpectedVal)); } void checkValueFromStringReprFailure( StringRef Str, StringRef ErrorStr = "unable to represent numeric value") { - Expected ResultValue = getValueFromStringReprFailure(Str); + Expected ResultValue = getValueFromStringReprFailure(Str); expectDiagnosticError(ErrorStr, ResultValue.takeError()); } }; @@ -363,7 +361,7 @@ TEST_F(FileCheckTest, NoFormatProperties) { NoFormat.getWildcardRegex().takeError()); expectError( "trying to match value with invalid format", - NoFormat.getMatchingString(ExpressionValue(APInt(64, 18u))).takeError()); + NoFormat.getMatchingString(APInt(64, 18u)).takeError()); EXPECT_FALSE(bool(NoFormat)); } @@ -397,12 +395,9 @@ TEST_F(FileCheckTest, FormatKindEqualityOperators) { static void expectOperationValueResult(binop_eval_t Operation, APInt LeftValue, APInt RightValue, APInt ExpectedValue) { bool Overflow; - ExpressionValue LeftVal(LeftValue); - ExpressionValue RightVal(RightValue); - Expected OperationResult = - Operation(LeftVal, RightVal, Overflow); + Expected OperationResult = Operation(LeftValue, RightValue, Overflow); ASSERT_THAT_EXPECTED(OperationResult, Succeeded()); - EXPECT_EQ(OperationResult->getAPIntValue(), ExpectedValue); + EXPECT_EQ(*OperationResult, ExpectedValue); } template @@ -421,10 +416,8 @@ template static void expectOperationValueResult(binop_eval_t Operation, T1 LeftValue, T2 RightValue) { bool Overflow; - ExpressionValue LeftVal( - APInt(LiteralsBitWidth, LeftValue, std::is_signed_v)); - ExpressionValue RightVal( - APInt(LiteralsBitWidth, RightValue, std::is_signed_v)); + APInt LeftVal(LiteralsBitWidth, LeftValue, std::is_signed_v); + APInt RightVal(LiteralsBitWidth, RightValue, std::is_signed_v); expectError( "overflow error", Operation(LeftVal, RightVal, Overflow).takeError()); } @@ -565,9 +558,9 @@ TEST_F(FileCheckTest, Literal) { // Eval returns the literal's value. ExpressionLiteral Ten(bufferize(SM, "10"), APInt(64, 10u)); - Expected Value = Ten.eval(); + Expected Value = Ten.eval(); ASSERT_THAT_EXPECTED(Value, Succeeded()); - EXPECT_EQ(10, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(10, Value->getSExtValue()); Expected ImplicitFormat = Ten.getImplicitFormat(SM); ASSERT_THAT_EXPECTED(ImplicitFormat, Succeeded()); EXPECT_EQ(*ImplicitFormat, ExpressionFormat::Kind::NoFormat); @@ -577,14 +570,14 @@ TEST_F(FileCheckTest, Literal) { APInt(64, MinInt64, /*IsSigned=*/true)); Value = Min.eval(); ASSERT_TRUE(bool(Value)); - EXPECT_EQ(MinInt64, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(MinInt64, Value->getSExtValue()); // Max value can be correctly represented. ExpressionLiteral Max(bufferize(SM, std::to_string(MaxUint64)), APInt(64, MaxUint64)); Value = Max.eval(); ASSERT_THAT_EXPECTED(Value, Succeeded()); - EXPECT_EQ(MaxUint64, Value->getAPIntValue().getZExtValue()); + EXPECT_EQ(MaxUint64, Value->getZExtValue()); } TEST_F(FileCheckTest, Expression) { @@ -626,33 +619,33 @@ TEST_F(FileCheckTest, NumericVariable) { ASSERT_THAT_EXPECTED(ImplicitFormat, Succeeded()); EXPECT_EQ(*ImplicitFormat, ExpressionFormat::Kind::Unsigned); EXPECT_FALSE(FooVar.getValue()); - Expected EvalResult = FooVarUse.eval(); + Expected EvalResult = FooVarUse.eval(); expectUndefErrors({"FOO"}, EvalResult.takeError()); // Defined variable without string: only getValue and eval return value set. - FooVar.setValue(ExpressionValue(APInt(64, 42u))); - std::optional Value = FooVar.getValue(); + FooVar.setValue(APInt(64, 42u)); + std::optional Value = FooVar.getValue(); ASSERT_TRUE(Value); - EXPECT_EQ(42, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(42, Value->getSExtValue()); EXPECT_FALSE(FooVar.getStringValue()); EvalResult = FooVarUse.eval(); ASSERT_THAT_EXPECTED(EvalResult, Succeeded()); - EXPECT_EQ(42, EvalResult->getAPIntValue().getSExtValue()); + EXPECT_EQ(42, EvalResult->getSExtValue()); // Defined variable with string: getValue, eval, and getStringValue return // value set. StringRef StringValue = "925"; - FooVar.setValue(ExpressionValue(APInt(64, 925u)), StringValue); + FooVar.setValue(APInt(64, 925u), StringValue); Value = FooVar.getValue(); ASSERT_TRUE(Value); - EXPECT_EQ(925, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(925, Value->getSExtValue()); // getStringValue should return the same memory not just the same characters. EXPECT_EQ(StringValue.begin(), FooVar.getStringValue()->begin()); EXPECT_EQ(StringValue.end(), FooVar.getStringValue()->end()); EvalResult = FooVarUse.eval(); ASSERT_THAT_EXPECTED(EvalResult, Succeeded()); - EXPECT_EQ(925, EvalResult->getAPIntValue().getSExtValue()); - EXPECT_EQ(925, EvalResult->getAPIntValue().getSExtValue()); + EXPECT_EQ(925, EvalResult->getSExtValue()); + EXPECT_EQ(925, EvalResult->getSExtValue()); // Clearing variable: getValue and eval fail. Error returned by eval holds // the name of the cleared variable. @@ -670,13 +663,13 @@ TEST_F(FileCheckTest, Binop) { StringRef FooStr = ExprStr.take_front(3); NumericVariable FooVar(FooStr, ExpressionFormat(ExpressionFormat::Kind::Unsigned), 1); - FooVar.setValue(ExpressionValue(APInt(64, 42u))); + FooVar.setValue(APInt(64, 42u)); std::unique_ptr FooVarUse = std::make_unique(FooStr, &FooVar); StringRef BarStr = ExprStr.take_back(3); NumericVariable BarVar(BarStr, ExpressionFormat(ExpressionFormat::Kind::Unsigned), 2); - BarVar.setValue(ExpressionValue(APInt(64, 18u))); + BarVar.setValue(APInt(64, 18u)); std::unique_ptr BarVarUse = std::make_unique(BarStr, &BarVar); BinaryOperation Binop(ExprStr, exprAdd, std::move(FooVarUse), @@ -684,29 +677,28 @@ TEST_F(FileCheckTest, Binop) { // Defined variables with same bitwidth and no overflow: eval returns right // value; implicit formas is as expected. - Expected Value = Binop.eval(); + Expected Value = Binop.eval(); ASSERT_THAT_EXPECTED(Value, Succeeded()); - EXPECT_EQ(60, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(60, Value->getSExtValue()); Expected ImplicitFormat = Binop.getImplicitFormat(SM); ASSERT_THAT_EXPECTED(ImplicitFormat, Succeeded()); EXPECT_EQ(*ImplicitFormat, ExpressionFormat::Kind::Unsigned); // Defined variables with different bitwidth and no overflow: eval succeeds // and return the right value. - BarVar.setValue(ExpressionValue(APInt(32, 18u))); + BarVar.setValue(APInt(32, 18u)); Value = Binop.eval(); ASSERT_THAT_EXPECTED(Value, Succeeded()); - EXPECT_EQ(60, Value->getAPIntValue().getSExtValue()); + EXPECT_EQ(60, Value->getSExtValue()); // Defined variables with same bitwidth and wider result (i.e. overflow): // eval succeeds and return the right value in a wider APInt. - BarVar.setValue(ExpressionValue(APInt(64, AbsoluteMaxInt64))); + BarVar.setValue(APInt(64, AbsoluteMaxInt64)); Value = Binop.eval(); ASSERT_THAT_EXPECTED(Value, Succeeded()); - EXPECT_EQ(128u, Value->getAPIntValue().getBitWidth()); - EXPECT_EQ(APInt(128, AbsoluteMaxInt64 + - FooVar.getValue()->getAPIntValue().getZExtValue()), - Value->getAPIntValue()); + EXPECT_EQ(128u, Value->getBitWidth()); + EXPECT_EQ(APInt(128, AbsoluteMaxInt64 + FooVar.getValue()->getZExtValue()), + *Value); // 1 undefined variable: eval fails, error contains name of undefined // variable. @@ -1463,7 +1455,7 @@ TEST_F(FileCheckTest, Substitution) { // substituted for the variable's value. NumericVariable NVar("N", ExpressionFormat(ExpressionFormat::Kind::Unsigned), 1); - NVar.setValue(ExpressionValue(APInt(64, 10u))); + NVar.setValue(APInt(64, 10u)); auto NVarUse = std::make_unique("N", &NVar); auto ExpressionN = std::make_unique( std::move(NVarUse), ExpressionFormat(ExpressionFormat::Kind::HexUpper)); @@ -1573,24 +1565,23 @@ TEST_F(FileCheckTest, FileCheckContext) { Expected EmptyVar = Cxt.getPatternVarValue(EmptyVarStr); Expected UnknownVar = Cxt.getPatternVarValue(UnknownVarStr); ASSERT_THAT_EXPECTED(ExpressionPointer, Succeeded()); - Expected ExpressionVal = - (*ExpressionPointer)->getAST()->eval(); + Expected ExpressionVal = (*ExpressionPointer)->getAST()->eval(); ASSERT_THAT_EXPECTED(ExpressionVal, Succeeded()); - EXPECT_EQ(ExpressionVal->getAPIntValue().getSExtValue(), 18); + EXPECT_EQ(ExpressionVal->getSExtValue(), 18); ExpressionPointer = P.parseNumericSubstitutionBlock( LocalNumVar2Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, LineNumber, &Cxt, SM); ASSERT_THAT_EXPECTED(ExpressionPointer, Succeeded()); ExpressionVal = (*ExpressionPointer)->getAST()->eval(); ASSERT_THAT_EXPECTED(ExpressionVal, Succeeded()); - EXPECT_EQ(ExpressionVal->getAPIntValue().getSExtValue(), 20); + EXPECT_EQ(ExpressionVal->getSExtValue(), 20); ExpressionPointer = P.parseNumericSubstitutionBlock( LocalNumVar3Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, LineNumber, &Cxt, SM); ASSERT_THAT_EXPECTED(ExpressionPointer, Succeeded()); ExpressionVal = (*ExpressionPointer)->getAST()->eval(); ASSERT_THAT_EXPECTED(ExpressionVal, Succeeded()); - EXPECT_EQ(ExpressionVal->getAPIntValue().getSExtValue(), 12); + EXPECT_EQ(ExpressionVal->getSExtValue(), 12); ASSERT_THAT_EXPECTED(EmptyVar, Succeeded()); EXPECT_EQ(*EmptyVar, ""); expectUndefErrors({std::string(UnknownVarStr)}, UnknownVar.takeError()); @@ -1640,7 +1631,7 @@ TEST_F(FileCheckTest, FileCheckContext) { ASSERT_THAT_EXPECTED(ExpressionPointer, Succeeded()); ExpressionVal = (*ExpressionPointer)->getAST()->eval(); ASSERT_THAT_EXPECTED(ExpressionVal, Succeeded()); - EXPECT_EQ(ExpressionVal->getAPIntValue().getSExtValue(), 36); + EXPECT_EQ(ExpressionVal->getSExtValue(), 36); // Clear local variables and check global variables remain defined. Cxt.clearLocalVars(); @@ -1652,7 +1643,7 @@ TEST_F(FileCheckTest, FileCheckContext) { ASSERT_THAT_EXPECTED(ExpressionPointer, Succeeded()); ExpressionVal = (*ExpressionPointer)->getAST()->eval(); ASSERT_THAT_EXPECTED(ExpressionVal, Succeeded()); - EXPECT_EQ(ExpressionVal->getAPIntValue().getSExtValue(), 36); + EXPECT_EQ(ExpressionVal->getSExtValue(), 36); } TEST_F(FileCheckTest, CapturedVarDiags) {