diff --git a/llvm/include/llvm/FileCheck/FileCheck.h b/llvm/include/llvm/FileCheck/FileCheck.h --- a/llvm/include/llvm/FileCheck/FileCheck.h +++ b/llvm/include/llvm/FileCheck/FileCheck.h @@ -35,7 +35,8 @@ std::vector GlobalDefines; bool AllowEmptyInput = false; bool AllowUnusedPrefixes = false; - bool MatchFullLines = false; + bool MatchFullLinesTrailing = false; + bool MatchFullLinesLeading = false; bool IgnoreCase = false; bool IsDefaultCheckPrefix = false; bool EnableVarScope = false; diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -759,12 +759,15 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req) { - bool MatchFullLinesHere = Req.MatchFullLines && CheckTy != Check::CheckNot; + bool MatchFullLinesLeadingHere = + Req.MatchFullLinesLeading && CheckTy != Check::CheckNot; + bool MatchFullLinesTrailingHere = + Req.MatchFullLinesTrailing && CheckTy != Check::CheckNot; IgnoreCase = Req.IgnoreCase; PatternLoc = SMLoc::getFromPointer(PatternStr.data()); - if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLines)) + if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLinesLeading)) // Ignore trailing whitespace. while (!PatternStr.empty() && (PatternStr.back() == ' ' || PatternStr.back() == '\t')) @@ -797,14 +800,14 @@ } // Check to see if this is a fixed string, or if it has regex pieces. - if (!MatchFullLinesHere && + if (!(MatchFullLinesLeadingHere || MatchFullLinesTrailingHere) && (PatternStr.size() < 2 || (!PatternStr.contains("{{") && !PatternStr.contains("[[")))) { FixedStr = PatternStr; return false; } - if (MatchFullLinesHere) { + if (MatchFullLinesLeadingHere) { RegExStr += '^'; if (!Req.NoCanonicalizeWhiteSpace) RegExStr += " *"; @@ -1039,7 +1042,7 @@ PatternStr = PatternStr.substr(FixedMatchEnd); } - if (MatchFullLinesHere) { + if (MatchFullLinesTrailingHere) { if (!Req.NoCanonicalizeWhiteSpace) RegExStr += " *"; RegExStr += '$'; @@ -1823,7 +1826,7 @@ // Okay, we found the prefix, yay. Remember the rest of the line, but ignore // leading whitespace. - if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLines)) + if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLinesTrailing)) Buffer = Buffer.substr(Buffer.find_first_not_of(" \t")); // Scan ahead to the end of line. diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp --- a/llvm/utils/FileCheck/FileCheck.cpp +++ b/llvm/utils/FileCheck/FileCheck.cpp @@ -90,6 +90,18 @@ "Allows leading and trailing whitespace if --strict-whitespace\n" "is not also passed.")); +static cl::opt MatchFullLinesLeading( + "match-full-lines-leading", cl::init(false), + cl::desc("Require all positive matches to cover the entire trailing input\n" + "line. Allows trailing whitespace if --strict-whitespace is not\n" + "also passed.")); + +static cl::opt MatchFullLinesTrailing( + "match-full-lines-trailing", cl::init(false), + cl::desc("Require all positive matches to cover the entire trailing input\n" + "line. Allows leading whitespace if --strict-whitespace is not\n" + "also passed.")); + static cl::opt EnableVarScope( "enable-var-scope", cl::init(false), cl::desc("Enables scope for regex variables. Variables with names that\n" @@ -800,7 +812,8 @@ Req.Verbose = Verbose; Req.VerboseVerbose = VerboseVerbose; Req.NoCanonicalizeWhiteSpace = NoCanonicalizeWhiteSpace; - Req.MatchFullLines = MatchFullLines; + Req.MatchFullLinesLeading = MatchFullLines || MatchFullLinesLeading; + Req.MatchFullLinesTrailing = MatchFullLines || MatchFullLinesTrailing; Req.IgnoreCase = IgnoreCase; if (VerboseVerbose)