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 @@ -595,7 +595,7 @@ to the value ``61680``. The syntax to check a numeric expression constraint is -``[[#%:]]`` where: +``[[#%: ]]`` where: * ``%`` is the same matching format specifier as for defining numeric variables but acting as a printf-style format to indicate how a numeric @@ -605,6 +605,12 @@ if no numeric variable is used. In case of conflict between matching formats of several numeric variables the format specifier is mandatory. +* ```` is the matching constraint describing how the value to match + must relate to the value of the numeric expression. The only currently + accepted constraint is ``==`` for an exact match and is the default if + ```` is not provided. No matching constraint must be specified + when the ```` is empty. + * ``>`` is a numeric expression whose operands are either numeric variables previously defined or integer immediates. Currently supported numeric operations are ``+`` and ``-``. A single numeric variable or 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 @@ -649,10 +649,23 @@ Expr = Expr.substr(DefEnd + 1); } + // Parse matching constraint. + SkipWhitespace(Expr); + StringRef ConstraintExpr = Expr; + if (Skip(Expr, "==", true /*Optional*/)) + return nullptr; + // Parse numeric expression itself. SkipWhitespace(Expr); StringRef UseExpr = Expr; - if (!Expr.empty()) { + if (Expr.empty()) { + if (Expr.size() != ConstraintExpr.size()) { + SM.PrintMessage( + SMLoc::getFromPointer(Expr.data()), SourceMgr::DK_Error, + "Empty numeric expression should not have a matching constraint"); + return nullptr; + } + } else { // First operand in legacy numeric expression is the @LINE pseudo variable. enum AllowedOperand AO = Legacy ? LegacyVar : Any; NumExprAST = ParseNumericOperand(Expr, AO, 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 @@ -13,6 +13,8 @@ ; RUN: not FileCheck -check-prefixes CHECK,FMT-CONFLICT -input-file %s %s 2>&1 | FileCheck --strict-whitespace -check-prefix FMT-CONFLICT-MSG %s ; RUN: not FileCheck -check-prefix OVERFLOW -input-file %s %s 2>&1 | FileCheck -check-prefix OVERFLOW-MSG %s ; RUN: not FileCheck -check-prefix UNDERFLOW -input-file %s %s 2>&1 | FileCheck -check-prefix UNDERFLOW-MSG %s +; RUN: not FileCheck -check-prefix EMPTY-NUMEXPR-CONSTRAINT -input-file %s %s 2>&1 | FileCheck -check-prefix EMPTY-NUMEXPR-CONSTRAINT-MSG %s +; RUN: not FileCheck -check-prefix EMPTY-NUMDEF-CONSTRAINT -input-file %s %s 2>&1 | FileCheck -check-prefix EMPTY-NUMDEF-CONSTRAINT-MSG %s ; We ensure we attemt to match all lines with digits by using CHECK-NEXT @@ -190,6 +192,18 @@ ; CHECK-NEXT: [[#VAR1+0x8000000000000000]] +; Numeric expressions in default matching format and explicit matching rule using +; variables defined on other lines +USE DEF FMT EXPL MATCH +11 +11 +11 +; CHECK-LABEL: USE DEF FMT EXPL MATCH +; CHECK-NEXT: [[#==VAR1]] +; CHECK-NEXT: [[# ==VAR1]] +; CHECK-NEXT: [[# == VAR1]] + + ; Numeric expressions with conversion matching format and implicit matching rule ; using variables defined on other lines USE CONV FMT IMPL MATCH @@ -322,3 +336,23 @@ ; UNDERFLOW-MSG: numeric-expression.txt:[[#@LINE-1]]:31: error: Unable to substitute variable or numeric expression ; UNDERFLOW-MSG-NEXT: {{U}}NDERFLOW-NEXT: TINYVAR: {{\[\[#%d,TINYVAR:-0x8000000000000000-0x8000000000000000\]\]}} ; UNDERFLOW-MSG-NEXT: {{^ \^$}} + + +; Empty numeric expression with matching constraint +EMPTY NUMEXPR USE WITH CONSTRAINT +18 +; EMPTY-NUMEXPR-CONSTRAINT-LABEL: EMPTY NUMEXPR USE WITH CONSTRAINT +; EMPTY-NUMEXPR-CONSTRAINT-NEXT: [[# ==]] +; EMPTY-NUMEXPR-CONSTRAINT-MSG: numeric-expression.txt:[[#@LINE-1]]:40: error: Empty numeric expression should not have a matching constraint +; EMPTY-NUMEXPR-CONSTRAINT-MSG-NEXT: {{E}}MPTY-NUMEXPR-CONSTRAINT-NEXT: {{\[\[# ==\]\]}} +; EMPTY-NUMEXPR-CONSTRAINT-MSG-NEXT: {{^ \^$}} + + +; Empty numeric expression with matching constraint +EMPTY NUMEXPR DEF WITH CONSTRAINT +18 +; EMPTY-NUMDEF-CONSTRAINT-LABEL: EMPTY NUMEXPR CONSTRAINT +; EMPTY-NUMDEF-CONSTRAINT-NEXT: [[#VARDEF: ==]] +; EMPTY-NUMDEF-CONSTRAINT-MSG: numeric-expression.txt:[[#@LINE-1]]:46: error: Empty numeric expression should not have a matching constraint +; EMPTY-NUMDEF-CONSTRAINT-MSG-NEXT: {{E}}MPTY-NUMDEF-CONSTRAINT-NEXT: {{\[\[#VARDEF: ==\]\]}} +; EMPTY-NUMDEF-CONSTRAINT-MSG-NEXT: {{^ \^$}}