[PATCH] D64882: [FileCheck] Fix @LINE substitution in error msg

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 14:00:53 PDT 2019


thopre created this revision.
thopre added reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk.
thopre added a project: LLVM.

Previous approach to correct @LINE substitution was to clear it just
after substitutions are performed in match(). However substitution is
also done when assert are enabled in setValue called later on in
match(). More importantly, it is also done in printSubstitutions to give
diagnostics about failed match.

This commit changes the approach to clear @LINE's value prior to setting
it to ensure it is successfully set by setValue and that the value
remains set until the next CHECK line is matched.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64882

Files:
  llvm/lib/Support/FileCheck.cpp
  llvm/test/FileCheck/line-count.txt


Index: llvm/test/FileCheck/line-count.txt
===================================================================
--- llvm/test/FileCheck/line-count.txt
+++ 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
Index: llvm/lib/Support/FileCheck.cpp
===================================================================
--- llvm/lib/Support/FileCheck.cpp
+++ 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<std::string> 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<StringRef, 4> MatchInfo;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64882.210409.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190717/6a1173c4/attachment.bin>


More information about the llvm-commits mailing list