[clang-tools-extra] dc93540 - Fix handling of newlines in clang-query
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 29 06:59:39 PST 2019
Author: Stephen Kelly
Date: 2019-12-29T14:58:56Z
New Revision: dc93540acbf047cf54052568d2826d1a06df025e
URL: https://github.com/llvm/llvm-project/commit/dc93540acbf047cf54052568d2826d1a06df025e
DIFF: https://github.com/llvm/llvm-project/commit/dc93540acbf047cf54052568d2826d1a06df025e.diff
LOG: Fix handling of newlines in clang-query
Replace assert with diagnostic for missing newline.
Added:
Modified:
clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
clang/lib/ASTMatchers/Dynamic/Parser.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
index 4725789f29f2..79fcfcae6e0d 100644
--- a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
+++ b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
@@ -330,4 +330,22 @@ match callExpr
EXPECT_EQ("1:9: Error parsing matcher. Found token <NewLine> "
"while looking for '('.",
cast<InvalidQuery>(Q)->ErrStr);
+
+ Q = parse("let someMatcher\nm parmVarDecl()");
+
+ ASSERT_TRUE(isa<InvalidQuery>(Q));
+ EXPECT_EQ("1:1: Invalid token <NewLine> found when looking for a value.", cast<InvalidQuery>(Q)->ErrStr);
+
+ Q = parse("\nm parmVarDecl()\nlet someMatcher\nm parmVarDecl()");
+
+ ASSERT_TRUE(isa<MatchQuery>(Q));
+ Q = parse(Q->RemainingContent);
+
+ ASSERT_TRUE(isa<InvalidQuery>(Q));
+ EXPECT_EQ("1:1: Invalid token <NewLine> found when looking for a value.", cast<InvalidQuery>(Q)->ErrStr);
+
+ Q = parse("\nlet someMatcher\n");
+
+ ASSERT_TRUE(isa<InvalidQuery>(Q));
+ EXPECT_EQ("1:1: Invalid token <NewLine> found when looking for a value.", cast<InvalidQuery>(Q)->ErrStr);
}
diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index caa3a3bd0953..ef209d1274af 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -607,15 +607,13 @@ bool Parser::parseExpressionImpl(VariantValue *Value) {
// This error was already reported by the tokenizer.
return false;
case TokenInfo::TK_NewLine:
- llvm_unreachable("Newline should never be found here");
- return false;
case TokenInfo::TK_OpenParen:
case TokenInfo::TK_CloseParen:
case TokenInfo::TK_Comma:
case TokenInfo::TK_Period:
case TokenInfo::TK_InvalidChar:
const TokenInfo Token = Tokenizer->consumeNextToken();
- Error->addError(Token.Range, Error->ET_ParserInvalidToken) << Token.Text;
+ Error->addError(Token.Range, Error->ET_ParserInvalidToken) << (Token.Kind == TokenInfo::TK_NewLine ? "NewLine" : Token.Text);
return false;
}
More information about the cfe-commits
mailing list