summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-07-05 16:25:33 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-07-05 16:25:33 +0000
commitfe7ac170a7977079a6ce49e836bb0ab60455c986 (patch)
treeabee0f61116db82de59c45f3dcb7b328620eabad /llvm/unittests/Support
parent766accd3640f52b199ff37f39993368c4c0245e9 (diff)
downloadbcm5719-llvm-fe7ac170a7977079a6ce49e836bb0ab60455c986.tar.gz
bcm5719-llvm-fe7ac170a7977079a6ce49e836bb0ab60455c986.zip
[FileCheck] Don't diagnose undef vars at parse time
Summary: Diagnosing use of undefined variables takes place in parseNumericVariableUse() and printSubstitutions() for numeric variables but only takes place in printSubstitutions() for string variables. The reason for the split location of diagnostics is that parsing is not aware of the clearing of variables due to --enable-var-scope and thus use of variables cleared in this way can only be catched by printSubstitutions(). Beyond the code level inconsistency, there is also a user facing inconsistency since diagnostics look different between the two functions. While the diagnostic in printSubstitutions is more verbose, doing the diagnostic there allows to diagnose all undefined variables rather than just the first one and error out. This patch create dummy variable definition when encountering a use of undefined variable so that parsing can proceed and be diagnosed by printSubstitutions() later. Tests that were testing whether parsing fails in such case are thus modified accordingly. Reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk Subscribers: JonChesterfield, rogfer01, hfinkel, kristina, rnk, tra, arichardson, grimar, dblaikie, probinson, llvm-commits, hiraditya Tags: #llvm Differential Revision: https://reviews.llvm.org/D64228 llvm-svn: 365219
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/FileCheckTest.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp
index dc89eef3256..b9970ffc1f7 100644
--- a/llvm/unittests/Support/FileCheckTest.cpp
+++ b/llvm/unittests/Support/FileCheckTest.cpp
@@ -257,11 +257,11 @@ TEST_F(FileCheckTest, ParseExpr) {
// Unacceptable variable.
EXPECT_TRUE(Tester.parseSubstExpect("10VAR"));
EXPECT_TRUE(Tester.parseSubstExpect("@FOO"));
- EXPECT_TRUE(Tester.parseSubstExpect("UNDEF"));
// Only valid variable.
EXPECT_FALSE(Tester.parseSubstExpect("@LINE"));
EXPECT_FALSE(Tester.parseSubstExpect("FOO"));
+ EXPECT_FALSE(Tester.parseSubstExpect("UNDEF"));
// Use variable defined on same line.
EXPECT_FALSE(Tester.parsePatternExpect("[[#LINE1VAR:]]"));
@@ -471,9 +471,14 @@ TEST_F(FileCheckTest, FileCheckContext) {
P = FileCheckPattern(Check::CheckPlain, &Cxt, 2);
Expression = P.parseNumericSubstitutionBlock(LocalNumVarRef,
DefinedNumericVariable, SM);
- EXPECT_TRUE(errorToBool(Expression.takeError()));
+ EXPECT_TRUE(bool(Expression));
+ ExpressionVal = (*Expression)->eval();
+ EXPECT_TRUE(errorToBool(ExpressionVal.takeError()));
EmptyVar = Cxt.getPatternVarValue(EmptyVarStr);
EXPECT_TRUE(errorToBool(EmptyVar.takeError()));
+ // Clear again because parseNumericSubstitutionBlock would have created a
+ // dummy variable and stored it in GlobalNumericVariableTable.
+ Cxt.clearLocalVars();
// Redefine global variables and check variables are defined again.
GlobalDefines.emplace_back(std::string("$GlobalVar=BAR"));
OpenPOWER on IntegriCloud