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 @@ -621,8 +621,10 @@ std::string TmpStr; if (!Substitutions.empty()) { TmpStr = RegExStr; - if (LineNumber) + if (LineNumber) { + Context->LineVariable->clearValue(); Context->LineVariable->setValue(*LineNumber); + } size_t InsertOffset = 0; // Substitute all string variables and expressions whose values are only @@ -631,10 +633,8 @@ for (const auto &Substitution : Substitutions) { // Substitute and check for failure (e.g. use of undefined variable). Expected Value = Substitution->getResult(); - if (!Value) { - Context->LineVariable->clearValue(); + if (!Value) return Value.takeError(); - } // Plop it into the regex at the adjusted offset. TmpStr.insert(TmpStr.begin() + Substitution->getIndex() + InsertOffset, @@ -644,7 +644,6 @@ // Match the newly constructed regex. RegExToMatch = TmpStr; - Context->LineVariable->clearValue(); } SmallVector MatchInfo; diff --git a/llvm/test/FileCheck/line-count.txt b/llvm/test/FileCheck/line-count.txt --- a/llvm/test/FileCheck/line-count.txt +++ b/llvm/test/FileCheck/line-count.txt @@ -55,12 +55,18 @@ 55 BAD11: [[@LINE-1x]] 56 ERR11: line-count.txt:[[#@LINE-1]]:20: error: unexpected characters at end of expression 'x' 57 -58 CHECK: [[#@LINE]] CHECK -59 CHECK: [[# @LINE]] CHECK -60 CHECK: [[# @LINE ]] CHECK -61 -62 CHECK: [[#@LINE-1]] -63 CHECK: [[# @LINE-1]] CHECK -64 CHECK: [[# @LINE -1]] CHECK -65 CHECK: [[# @LINE - 1]] CHECK -66 CHECK: [[# @LINE - 1 ]] CHECK +; RUN: not FileCheck -check-prefix BAD12 -input-file %s %s 2>&1 \ +; RUN: | FileCheck -check-prefix ERR12 %s +60 +61 BAD12: [[#@LINE-1]] NOT HERE +62 ERR12: note: with "@LINE-1" equal to "60" +63 +64 CHECK: [[#@LINE]] CHECK +65 CHECK: [[# @LINE]] CHECK +66 CHECK: [[# @LINE ]] CHECK +67 +68 CHECK: [[#@LINE-1]] +69 CHECK: [[# @LINE-1]] CHECK +70 CHECK: [[# @LINE -1]] CHECK +71 CHECK: [[# @LINE - 1]] CHECK +72 CHECK: [[# @LINE - 1 ]] CHECK