From 6f8fc217eaa12bf657be1c6468ed9938d10168b3 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Thu, 27 Jan 2022 23:06:42 +0100 Subject: Vendor import of llvm-project main llvmorg-14-init-17616-g024a1fab5c35. --- llvm/lib/FileCheck/FileCheck.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'llvm/lib/FileCheck') diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index c962231cbdc1..6186af444e73 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -1007,8 +1007,9 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix, // brackets. They also accept a combined form which sets a numeric variable // to the evaluation of an expression. Both string and numeric variable // names must satisfy the regular expression "[a-zA-Z_][0-9a-zA-Z_]*" to be - // valid, as this helps catch some common errors. - if (PatternStr.startswith("[[")) { + // valid, as this helps catch some common errors. If there are extra '['s + // before the "[[", treat them literally. + if (PatternStr.startswith("[[") && !PatternStr.startswith("[[[")) { StringRef UnparsedPatternStr = PatternStr.substr(2); // Find the closing bracket pair ending the match. End is going to be an // offset relative to the beginning of the match string. @@ -1183,12 +1184,14 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix, Substitutions.push_back(Substitution); } } + + continue; } // Handle fixed string matches. // Find the end, which is the start of the next regex. - size_t FixedMatchEnd = PatternStr.find("{{"); - FixedMatchEnd = std::min(FixedMatchEnd, PatternStr.find("[[")); + size_t FixedMatchEnd = + std::min(PatternStr.find("{{", 1), PatternStr.find("[[", 1)); RegExStr += Regex::escape(PatternStr.substr(0, FixedMatchEnd)); PatternStr = PatternStr.substr(FixedMatchEnd); } @@ -2215,7 +2218,7 @@ static Error reportMatchResult(bool ExpectedMatch, const SourceMgr &SM, static unsigned CountNumNewlinesBetween(StringRef Range, const char *&FirstNewLine) { unsigned NumNewLines = 0; - while (1) { + while (true) { // Scan for newline. Range = Range.substr(Range.find_first_of("\n\r")); if (Range.empty()) -- cgit v1.2.3