summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Support/FileCheck.cpp4
-rw-r--r--llvm/unittests/Support/FileCheckTest.cpp15
2 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 03e892af274..93a3f0513fc 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -580,8 +580,10 @@ Expected<size_t> FileCheckPattern::match(StringRef Buffer, size_t &MatchLen,
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,
diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp
index 7fcd5bba608..58550c7b7bd 100644
--- a/llvm/unittests/Support/FileCheckTest.cpp
+++ b/llvm/unittests/Support/FileCheckTest.cpp
@@ -334,6 +334,21 @@ TEST_F(FileCheckTest, Match) {
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) {
OpenPOWER on IntegriCloud