llvm.org GIT mirror llvm / aa12251
[FileCheck] Fix @LINE value after match failure Summary: The value of the FileCheckNumericVariable class instance representing the @LINE numeric variable is set and cleared respectively before and after substitutions are made, if any. However, when a substitution fails, the value is not cleared. This causes the next substitution of @LINE later on to give the wrong value since setValue is a nop if the value is already set. This is what caused failures after commit r365249. Reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk Subscribers: hiraditya, llvm-commits, probinson, dblaikie, grimar, arichardson, tra, rnk, kristina, hfinkel, rogfer01, JonChesterfield Tags: #llvm Differential Revision: https://reviews.llvm.org/D64449 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365624 91177308-0d34-0410-b5e6-96231b3b80d8 Thomas Preud'homme 3 months ago
2 changed file(s) with 18 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
579579 for (const auto &Substitution : Substitutions) {
580580 // Substitute and check for failure (e.g. use of undefined variable).
581581 Expected Value = Substitution->getResult();
582 if (!Value)
582 if (!Value) {
583 Context->LineVariable->clearValue();
583584 return Value.takeError();
585 }
584586
585587 // Plop it into the regex at the adjusted offset.
586588 TmpStr.insert(TmpStr.begin() + Substitution->getIndex() + InsertOffset,
333333 EXPECT_TRUE(Tester.matchExpect("19 21"));
334334 EXPECT_TRUE(Tester.matchExpect("18 21"));
335335 EXPECT_FALSE(Tester.matchExpect("18 20"));
336
337 // Check matching a numeric expression using @LINE after match failure uses
338 // the correct value for @LINE.
339 Tester.initNextPattern();
340 EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
341 // Ok, @LINE is 4 now.
342 EXPECT_FALSE(Tester.matchExpect("4"));
343 Tester.initNextPattern();
344 // @LINE is now 5, match with substitution failure.
345 EXPECT_FALSE(Tester.parsePatternExpect("[[#UNKNOWN]]"));
346 EXPECT_TRUE(Tester.matchExpect("FOO"));
347 Tester.initNextPattern();
348 // Check that @LINE is 6 as expected.
349 EXPECT_FALSE(Tester.parsePatternExpect("[[#@LINE]]"));
350 EXPECT_FALSE(Tester.matchExpect("6"));
336351 }
337352
338353 TEST_F(FileCheckTest, Substitution) {