diff --git a/llvm/docs/CommandGuide/FileCheck.rst b/llvm/docs/CommandGuide/FileCheck.rst --- a/llvm/docs/CommandGuide/FileCheck.rst +++ b/llvm/docs/CommandGuide/FileCheck.rst @@ -691,9 +691,22 @@ * a numeric operand, or * an expression followed by an operator and a numeric operand. - A numeric operand is a previously defined numeric variable, or an integer - literal. The supported operators are ``+`` and ``-``. Spaces are accepted - before, after and between any of these elements. + A numeric operand is a previously defined numeric variable, an integer + literal, or a function call. The supported operators are ``+`` and ``-``. + Spaces are accepted before, after and between any of these elements. + +The syntax of a function call is ``!()`` where: + +* ``name`` is a predefined string literal. Acceptable values are: + + * add - Returns the sum of its two operands. + * mul - Returns the product of its two operands. + * sub - Returns the difference of its two operands. + * udiv - Returns the unsigned quotient of its two operands. + * umax - Returns the largest of its two unsigned operands. + * umin - Returns the smallest of its two unsigned operands. + +* ```` is a comma seperated list of expressions. For example: diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp --- a/llvm/lib/Support/FileCheck.cpp +++ b/llvm/lib/Support/FileCheck.cpp @@ -185,6 +185,9 @@ // FileCheck input canonicalization. constexpr StringLiteral SpaceChars = " \t"; +// StringRef holding the prefix used to identify the name of a function. +constexpr StringLiteral CallPrefix = "!"; + // Parsing helper function that strips the first character in S and returns it. static char popFront(StringRef &S) { char C = S.front(); @@ -273,6 +276,14 @@ Expected> Pattern::parseNumericOperand( StringRef &Expr, AllowedOperand AO, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { + // Try to parse a function call. + if (Expr.startswith(CallPrefix)) { + if (AO != AllowedOperand::Any) + return ErrorDiagnostic::get(SM, Expr, "unexpected function call"); + + return parseCallExpr(Expr, LineNumber, Context, SM); + } + if (AO == AllowedOperand::LineVar || AO == AllowedOperand::Any) { // Try to parse as a numeric variable use. Expected ParseVarResult = @@ -304,10 +315,26 @@ return LeftOp + RightOp; } +static uint64_t mul(uint64_t LeftOp, uint64_t RightOp) { + return LeftOp * RightOp; +} + static uint64_t sub(uint64_t LeftOp, uint64_t RightOp) { return LeftOp - RightOp; } +static uint64_t udiv(uint64_t LeftOp, uint64_t RightOp) { + return LeftOp / RightOp; +} + +static uint64_t umax(uint64_t LeftOp, uint64_t RightOp) { + return std::max(LeftOp, RightOp); +} + +static uint64_t umin(uint64_t LeftOp, uint64_t RightOp) { + return std::min(LeftOp, RightOp); +} + Expected> Pattern::parseBinop(StringRef Expr, StringRef &RemainingExpr, std::unique_ptr LeftOp, @@ -352,6 +379,92 @@ std::move(*RightOpResult)); } +Expected> +Pattern::parseCallExpr(StringRef &Expr, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM) { + assert(Expr.startswith(CallPrefix)); + Expr.consume_front(CallPrefix); + + // Record this for diagnostics that should be tied to the function name. + SMLoc OpLoc = SMLoc::getFromPointer(Expr.data()); + + size_t FuncNameEnd = Expr.find('('); + if (FuncNameEnd == StringRef::npos) + return ErrorDiagnostic::get( + SM, Expr, "call expression missing '(' for argument list"); + + StringRef FuncName = Expr.take_front(FuncNameEnd); + if (FuncName.empty()) + return ErrorDiagnostic::get(SM, Expr, "missing function name"); + + auto OptFunc = StringSwitch>(FuncName) + .Case("add", add) + .Case("mul", mul) + .Case("sub", sub) + .Case("udiv", udiv) + .Case("umax", umax) + .Case("umin", umin) + .Default(None); + + if (!OptFunc) + return ErrorDiagnostic::get( + SM, Expr, Twine("call to undefined function '") + FuncName + "'"); + + // Consume function name along with leading '('; + Expr = Expr.drop_front(FuncNameEnd + 1); + Expr = Expr.ltrim(SpaceChars); + + // Parse call arguments, which are comma separated. + SmallVector, 4> Args; + while (!Expr.empty() && !Expr.startswith(")")) { + Expr = Expr.rtrim(SpaceChars); + + // Parse the argument, which is an arbitary expression. + StringRef OuterBinOpExpr = Expr; + Expected> Arg = + parseNumericOperand(Expr, AllowedOperand::Any, LineNumber, Context, SM); + while (Arg && !Expr.empty()) { + Expr = Expr.ltrim(SpaceChars); + // Have we reached an argument terminator? + if (Expr.startswith(",") || Expr.startswith(")")) + break; + + // Arg = Arg + Arg = parseBinop(OuterBinOpExpr, Expr, std::move(*Arg), false, LineNumber, + Context, SM); + } + + // Prefer an expression error over a generic invalid argument message. + if (!Arg) + return Arg.takeError(); + Args.push_back(std::move(*Arg)); + + // Have we parsed all available arguments? + Expr = Expr.ltrim(SpaceChars); + if (!Expr.consume_front(",")) + break; + + Expr = Expr.ltrim(SpaceChars); + if (Expr.startswith(")")) + return ErrorDiagnostic::get(SM, Expr, "missing argument"); + } + + if (!Expr.consume_front(")")) + return ErrorDiagnostic::get(SM, Expr, + "missing ')' at end of call expression"); + + const unsigned NumArgs = Args.size(); + if (NumArgs == 2) + return std::make_unique(Expr, *OptFunc, std::move(Args[0]), + std::move(Args[1])); + + // TODO: Support more than binop_eval_t. + return ErrorDiagnostic::get(SM, OpLoc, + Twine("function '") + FuncName + + Twine("' takes 2 arguments but ") + + Twine(NumArgs) + " given"); +} + Expected> Pattern::parseNumericSubstitutionBlock( StringRef Expr, Optional &DefinedNumericVariable, bool IsLegacyLineExpr, Optional LineNumber, @@ -361,9 +474,10 @@ DefinedNumericVariable = None; ExpressionFormat ExplicitFormat = ExpressionFormat(); - // Parse format specifier. + // Parse format specifier (NOTE: ',' is also an argument seperator). size_t FormatSpecEnd = Expr.find(','); - if (FormatSpecEnd != StringRef::npos) { + size_t FunctionStart = Expr.find(CallPrefix); + if (FormatSpecEnd != StringRef::npos && FormatSpecEnd < FunctionStart) { Expr = Expr.ltrim(SpaceChars); if (!Expr.consume_front("%")) return ErrorDiagnostic::get( diff --git a/llvm/lib/Support/FileCheckImpl.h b/llvm/lib/Support/FileCheckImpl.h --- a/llvm/lib/Support/FileCheckImpl.h +++ b/llvm/lib/Support/FileCheckImpl.h @@ -661,11 +661,11 @@ enum class AllowedOperand { LineVar, LegacyLiteral, Any }; /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or /// before input is parsed if \p LineNumber is None. Accepts both literal - /// values and numeric variables, depending on the value of \p AO. Parameter - /// \p Context points to the class instance holding the live string and - /// numeric variables. \returns the class representing that operand in the - /// AST of the expression or an error holding a diagnostic against \p SM - /// otherwise. + /// values, numeric variables and function calls, depending on the value of + /// \p AO. Parameter \p Context points to the class instance holding the live + /// string and numeric variables. \returns the class representing that operand + /// in the AST of the expression or an error holding a diagnostic against + /// \p SM otherwise. static Expected> parseNumericOperand(StringRef &Expr, AllowedOperand AO, Optional LineNumber, @@ -684,6 +684,15 @@ std::unique_ptr LeftOp, bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); + + /// Parses \p Expr for a function call at line \p LineNumber, or before input + /// is parsed if \p LineNumber is None. Parameter \p Context points to the + /// class instance holding the live string and numeric variables. \returns the + /// class representing that call in the AST of the expression or an error + /// holding a diagnostic against \p SM otherwise. + static Expected> + parseCallExpr(StringRef &Expr, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM); }; //===----------------------------------------------------------------------===// diff --git a/llvm/test/FileCheck/numeric-expression.txt b/llvm/test/FileCheck/numeric-expression.txt --- a/llvm/test/FileCheck/numeric-expression.txt +++ b/llvm/test/FileCheck/numeric-expression.txt @@ -54,16 +54,36 @@ 11 // CHECK-NEXT: {{^}}[[#%u,UNSI]] 12 // CHECK-NEXT: {{^}}[[#%u,UNSI+1]] 10 // CHECK-NEXT: {{^}}[[#%u,UNSI-1]] +15 // CHECK-NEXT: {{^}}[[#%u,!add(UNSI,4)]] +77 // CHECK-NEXT: {{^}}[[#%u,!mul(UNSI,7)]] +8 // CHECK-NEXT: {{^}}[[#%u,!sub(UNSI,3)]] +3 // CHECK-NEXT: {{^}}[[#%u,!udiv(UNSI,3)]] +11 // CHECK-NEXT: {{^}}[[#%u,!umax(UNSI,7)]] +99 // CHECK-NEXT: {{^}}[[#%u,!umax(UNSI,99)]] +7 // CHECK-NEXT: {{^}}[[#%u,!umin(UNSI,7)]] +11 // CHECK-NEXT: {{^}}[[#%u,!umin(UNSI,99)]] c // CHECK-NEXT: {{^}}[[#%x,LHEX]] d // CHECK-NEXT: {{^}}[[#%x,LHEX+1]] b // CHECK-NEXT: {{^}}[[#%x,LHEX-1]] 1a // CHECK-NEXT: {{^}}[[#%x,LHEX+0xe]] 1a // CHECK-NEXT: {{^}}[[#%x,LHEX+0xE]] +e // CHECK-NEXT: {{^}}[[#%x,!add(LHEX,2)]] +c0 // CHECK-NEXT: {{^}}[[#%x,!mul(LHEX,16)]] +a // CHECK-NEXT: {{^}}[[#%x,!sub(LHEX,2)]] +6 // CHECK-NEXT: {{^}}[[#%x,!udiv(LHEX,2)]] +ff // CHECK-NEXT: {{^}}[[#%x,!umax(LHEX,0xff)]] +a // CHECK-NEXT: {{^}}[[#%x,!umin(LHEX,0xa)]] D // CHECK-NEXT: {{^}}[[#%X,UHEX]] E // CHECK-NEXT: {{^}}[[#%X,UHEX+1]] C // CHECK-NEXT: {{^}}[[#%X,UHEX-1]] 1B // CHECK-NEXT: {{^}}[[#%X,UHEX+0xe]] 1B // CHECK-NEXT: {{^}}[[#%X,UHEX+0xE]] +F // CHECK-NEXT: {{^}}[[#%X,!add(UHEX,2)]] +D0 // CHECK-NEXT: {{^}}[[#%X,!mul(UHEX,16)]] +B // CHECK-NEXT: {{^}}[[#%X,!sub(UHEX,2)]] +6 // CHECK-NEXT: {{^}}[[#%X,!udiv(UHEX,2)]] +FF // CHECK-NEXT: {{^}}[[#%X,!umax(UHEX,0xff)]] +A // CHECK-NEXT: {{^}}[[#%X,!umin(UHEX,0xa)]] 11 // CHECK-NEXT: {{^}}[[#%u,UNSIa]] 11 // CHECK-NEXT: {{^}}[[#%u,UNSIb]] 11 // CHECK-NEXT: {{^}}[[#%u,UNSIc]] @@ -87,6 +107,14 @@ 10 // CHECK-NEXT: {{^}}[[# %u , UNSI -1]] 10 // CHECK-NEXT: {{^}}[[# %u , UNSI - 1]] 10 // CHECK-NEXT: {{^}}[[# %u , UNSI - 1 ]] +22 // CHECK-NEXT: {{^}}[[#%u, !mul(UNSI,2)]] +22 // CHECK-NEXT: {{^}}[[# %u, !mul(UNSI,2)]] +22 // CHECK-NEXT: {{^}}[[# %u , !mul(UNSI,2)]] +22 // CHECK-NEXT: {{^}}[[# %u , !mul(UNSI, 2)]] +22 // CHECK-NEXT: {{^}}[[# %u , !mul( UNSI, 2)]] +22 // CHECK-NEXT: {{^}}[[# %u , !mul( UNSI,2)]] +22 // CHECK-NEXT: {{^}}[[# %u , !mul(UNSI,2) ]] +67 // CHECK-NEXT: {{^}}[[# %u , UNSI + !udiv( !mul(100 , UNSI ), 20) +1 ]] ; Numeric expressions in implicit matching format and default matching rule using ; variables defined on other lines. @@ -94,16 +122,28 @@ 11 // CHECK-NEXT: {{^}}[[#UNSI]] 12 // CHECK-NEXT: {{^}}[[#UNSI+1]] 10 // CHECK-NEXT: {{^}}[[#UNSI-1]] +77 // CHECK-NEXT: {{^}}[[#!mul(UNSI,7)]] +1 // CHECK-NEXT: {{^}}[[#!udiv(UNSI,9)]] +99 // CHECK-NEXT: {{^}}[[#!umax(UNSI,99)]] +7 // CHECK-NEXT: {{^}}[[#!umin(UNSI,7)]] c // CHECK-NEXT: {{^}}[[#LHEX]] d // CHECK-NEXT: {{^}}[[#LHEX+1]] b // CHECK-NEXT: {{^}}[[#LHEX-1]] 1a // CHECK-NEXT: {{^}}[[#LHEX+0xe]] 1a // CHECK-NEXT: {{^}}[[#LHEX+0xE]] +c0 // CHECK-NEXT: {{^}}[[#!mul(LHEX,16)]] +3 // CHECK-NEXT: {{^}}[[#!udiv(LHEX,4)]] +ff // CHECK-NEXT: {{^}}[[#!umax(LHEX,255)]] +a // CHECK-NEXT: {{^}}[[#!umin(LHEX,10)]] D // CHECK-NEXT: {{^}}[[#UHEX]] E // CHECK-NEXT: {{^}}[[#UHEX+1]] C // CHECK-NEXT: {{^}}[[#UHEX-1]] 1B // CHECK-NEXT: {{^}}[[#UHEX+0xe]] 1B // CHECK-NEXT: {{^}}[[#UHEX+0xE]] +D0 // CHECK-NEXT: {{^}}[[#!mul(UHEX,16)]] +D // CHECK-NEXT: {{^}}[[#!udiv(UHEX,1)]] +FF // CHECK-NEXT: {{^}}[[#!umax(UHEX,255)]] +A // CHECK-NEXT: {{^}}[[#!umin(UHEX,10)]] ; Numeric expressions using variables defined on other lines and an immediate ; interpreted as an unsigned value. @@ -315,3 +355,70 @@ REDEF-NEW-FMT-MSG: numeric-expression.txt:[[#@LINE-1]]:31: error: format different from previous variable definition REDEF-NEW-FMT-MSG-NEXT: {{R}}EDEF-NEW-FMT-NEXT: {{\[\[#%X,UNSI:\]\]}} REDEF-NEW-FMT-MSG-NEXT: {{^}} ^{{$}} + +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-MISSING-OPENING-BRACKET --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-MISSING-OPENING-BRACKET-MSG %s +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-MISSING-CLOSING-BRACKET --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-MISSING-CLOSING-BRACKET-MSG %s +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-MISSING-NAME --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-MISSING-NAME-MSG %s +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-MISSING-ARGUMENT --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-MISSING-ARGUMENT-MSG %s +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-WRONG-ARGUMENT-COUNT --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-WRONG-ARGUMENT-COUNT-MSG %s +RUN: %ProtectFileCheckOutput \ +RUN: not FileCheck -D#NUMVAR=10 --check-prefix CALL-UNDEFINED-FUNCTION --input-file %s %s 2>&1 \ +RUN: | FileCheck --strict-whitespace --check-prefix CALL-UNDEFINED-FUNCTION-MSG %s + +CALL MISSING OPENING BRACKET +30 +CALL-MISSING-OPENING-BRACKET-LABEL: CALL MISSING OPENING BRACKET +CALL-MISSING-OPENING-BRACKET-NEXT: [[#!mulNUMVAR,3)]] +CALL-MISSING-OPENING-BRACKET-MSG: numeric-expression.txt:[[#@LINE-1]]:40: error: call expression missing '(' for argument list +CALL-MISSING-OPENING-BRACKET-MSG-NEXT: {{C}}ALL-MISSING-OPENING-BRACKET-NEXT: {{\[\[#!mulNUMVAR,3\)\]\]}} +CALL-MISSING-OPENING-BRACKET-MSG-NEXT: {{^}} ^{{$}} + +CALL MISSING CLOSING BRACKET +30 +CALL-MISSING-CLOSING-BRACKET-LABEL: CALL MISSING CLOSING BRACKET +CALL-MISSING-CLOSING-BRACKET-NEXT: [[#!mul(NUMVAR,3]] +CALL-MISSING-CLOSING-BRACKET-MSG: numeric-expression.txt:[[#@LINE-1]]:52: error: missing ')' at end of call expression +CALL-MISSING-CLOSING-BRACKET-MSG-NEXT: {{C}}ALL-MISSING-CLOSING-BRACKET-NEXT: {{\[\[#!mul\(NUMVAR,3\]\]}} +CALL-MISSING-CLOSING-BRACKET-MSG-NEXT: {{^}} ^{{$}} + +CALL MISSING NAME +30 +CALL-MISSING-NAME-LABEL: CALL MISSING NAME +CALL-MISSING-NAME-NEXT: [[#!(NUMVAR)]] +CALL-MISSING-NAME-MSG: numeric-expression.txt:[[#@LINE-1]]:29: error: missing function name +CALL-MISSING-NAME-MSG-NEXT: {{C}}ALL-MISSING-NAME-NEXT: {{\[\[#!\(NUMVAR\)\]\]}} +CALL-MISSING-NAME-MSG-NEXT: {{^}} ^{{$}} + +CALL MISSING ARGUMENT +30 +CALL-MISSING-ARGUMENT-LABEL: CALL MISSING ARGUMENT +CALL-MISSING-ARGUMENT-NEXT: [[#!mul(NUMVAR,)]] +CALL-MISSING-ARGUMENT-MSG: numeric-expression.txt:[[#@LINE-1]]:44: error: missing argument +CALL-MISSING-ARGUMENT-MSG-NEXT: {{C}}ALL-MISSING-ARGUMENT-NEXT: {{\[\[#!mul\(NUMVAR,\)\]\]}} +CALL-MISSING-ARGUMENT-MSG-NEXT: {{^}} ^{{$}} + +CALL WRONG ARGUMENT COUNT +30 +CALL-WRONG-ARGUMENT-COUNT-LABEL: CALL WRONG ARGUMENT COUNT +CALL-WRONG-ARGUMENT-COUNT-NEXT: [[#!mul(NUMVAR)]] +CALL-WRONG-ARGUMENT-COUNT-MSG: numeric-expression.txt:[[#@LINE-1]]:37: error: function 'mul' takes 2 arguments but 1 given +CALL-WRONG-ARGUMENT-COUNT-MSG-NEXT: {{C}}ALL-WRONG-ARGUMENT-COUNT-NEXT: {{\[\[#!mul\(NUMVAR\)\]\]}} +CALL-WRONG-ARGUMENT-COUNT-MSG-NEXT: {{^}} ^{{$}} + +CALL UNDEFINED FUNCTION +30 +CALL-UNDEFINED-FUNCTION-LABEL: CALL UNDEFINED FUNCTION +CALL-UNDEFINED-FUNCTION-NEXT: [[#!bogus_function(NUMVAR)]] +CALL-UNDEFINED-FUNCTION-MSG: numeric-expression.txt:[[#@LINE-1]]:35: error: call to undefined function 'bogus_function' +CALL-UNDEFINED-FUNCTION-MSG-NEXT: {{C}}ALL-UNDEFINED-FUNCTION-NEXT: {{\[\[#!bogus_function\(NUMVAR\)\]\]}} +CALL-UNDEFINED-FUNCTION-MSG-NEXT: {{^}} ^{{$}} diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp --- a/llvm/unittests/Support/FileCheckTest.cpp +++ b/llvm/unittests/Support/FileCheckTest.cpp @@ -724,6 +724,36 @@ "implicit format conflict between 'FOO' (%u) and " "'VAR_LOWER_HEX' (%x), need an explicit format specifier", Tester.parseSubst("FOO+VAR_LOWER_HEX").takeError()); + + // Valid expression with function call. + EXPECT_THAT_EXPECTED(Tester.parseSubst("!mul(FOO,3)"), Succeeded()); + // Valid expression with nested function call. + EXPECT_THAT_EXPECTED(Tester.parseSubst("!mul(FOO, !umin(BAR,10))"), + Succeeded()); + // Valid expression with function call taking expression as argument. + EXPECT_THAT_EXPECTED(Tester.parseSubst("!mul(FOO, !umin(BAR,10) + 3)"), + Succeeded()); + + // Malformed call syntax. + expectDiagnosticError("call expression missing '(' for argument list", + Tester.parseSubst("!mulFOO,3)").takeError()); + expectDiagnosticError("missing ')' at end of call expression", + Tester.parseSubst("!mul(FOO,!umin(BAR,7)").takeError()); + expectDiagnosticError("missing function name", + Tester.parseSubst("!(FOO)").takeError()); + expectDiagnosticError("missing argument", + Tester.parseSubst("!mul(FOO,)").takeError()); + + // Valid call, but to an unknown function. + expectDiagnosticError( + "call to undefined function 'bogus_function'", + Tester.parseSubst("!bogus_function(FOO,3)").takeError()); + + // Valid call, but with incorrect argument count. + expectDiagnosticError("function 'mul' takes 2 arguments but 1 given", + Tester.parseSubst("!mul(FOO)").takeError()); + expectDiagnosticError("function 'mul' takes 2 arguments but 3 given", + Tester.parseSubst("!mul(FOO,3,4)").takeError()); } TEST_F(FileCheckTest, ParsePattern) { @@ -844,6 +874,47 @@ Succeeded()); } +TEST_F(FileCheckTest, MatchBuiltinFunctions) { + PatternTester Tester; + // Esnure #NUMVAR has the expected value. + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#NUMVAR:]]")); + expectNotFoundError(Tester.match("FAIL").takeError()); + expectNotFoundError(Tester.match("").takeError()); + EXPECT_THAT_EXPECTED(Tester.match("18"), Succeeded()); + + // Check each builtin function generates the expected result. + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!add(NUMVAR,13)]]")); + EXPECT_THAT_EXPECTED(Tester.match("31"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!mul(NUMVAR,3)]]")); + EXPECT_THAT_EXPECTED(Tester.match("54"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!sub(NUMVAR,7)]]")); + EXPECT_THAT_EXPECTED(Tester.match("11"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!udiv(NUMVAR,3)]]")); + EXPECT_THAT_EXPECTED(Tester.match("6"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!umax(NUMVAR,5)]]")); + EXPECT_THAT_EXPECTED(Tester.match("18"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!umax(NUMVAR,99)]]")); + EXPECT_THAT_EXPECTED(Tester.match("99"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!umin(NUMVAR,5)]]")); + EXPECT_THAT_EXPECTED(Tester.match("5"), Succeeded()); + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!umin(NUMVAR,99)]]")); + EXPECT_THAT_EXPECTED(Tester.match("18"), Succeeded()); + + // Check nested function calls. + Tester.initNextPattern(); + ASSERT_FALSE(Tester.parsePattern("[[#!mul(!umin(7,2),!umax(4,10))]]")); + EXPECT_THAT_EXPECTED(Tester.match("20"), Succeeded()); +} + TEST_F(FileCheckTest, Substitution) { SourceMgr SM; FileCheckPatternContext Context;