[PATCH] D64449: [FileCheck] Fix @LINE value after match failure

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 05:49:53 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL365624: [FileCheck] Fix @LINE value after match failure (authored by thopre, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64449?vs=208816&id=208925#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64449/new/

https://reviews.llvm.org/D64449

Files:
  llvm/trunk/lib/Support/FileCheck.cpp
  llvm/trunk/unittests/Support/FileCheckTest.cpp


Index: llvm/trunk/lib/Support/FileCheck.cpp
===================================================================
--- llvm/trunk/lib/Support/FileCheck.cpp
+++ llvm/trunk/lib/Support/FileCheck.cpp
@@ -580,8 +580,10 @@
     for (const auto &Substitution : Substitutions) {
       // Substitute and check for failure (e.g. use of undefined variable).
       Expected<std::string> Value = Substitution->getResult();
-      if (!Value)
+      if (!Value) {
+        Context->LineVariable->clearValue();
         return Value.takeError();
+      }
 
       // Plop it into the regex at the adjusted offset.
       TmpStr.insert(TmpStr.begin() + Substitution->getIndex() + InsertOffset,
Index: llvm/trunk/unittests/Support/FileCheckTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/FileCheckTest.cpp
+++ llvm/trunk/unittests/Support/FileCheckTest.cpp
@@ -334,6 +334,21 @@
   EXPECT_TRUE(Tester.matchExpect("19 21"));
   EXPECT_TRUE(Tester.matchExpect("18 21"));
   EXPECT_FALSE(Tester.matchExpect("18 20"));
+
+  // Check matching a numeric expression using @LINE after match failure uses
+  // the correct value for @LINE.
+  Tester.initNextPattern();
+  EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
+  // Ok, @LINE is 4 now.
+  EXPECT_FALSE(Tester.matchExpect("4"));
+  Tester.initNextPattern();
+  // @LINE is now 5, match with substitution failure.
+  EXPECT_FALSE(Tester.parsePatternExpect("[[#UNKNOWN]]"));
+  EXPECT_TRUE(Tester.matchExpect("FOO"));
+  Tester.initNextPattern();
+  // Check that @LINE is 6 as expected.
+  EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
+  EXPECT_FALSE(Tester.matchExpect("6"));
 }
 
 TEST_F(FileCheckTest, Substitution) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64449.208925.patch
Type: text/x-patch
Size: 1731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190710/a4fa32f5/attachment.bin>


More information about the llvm-commits mailing list