[clang-tools-extra] 544f200 - Fix newline handling in clang-query parser
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 29 06:59:40 PST 2019
Author: Stephen Kelly
Date: 2019-12-29T14:58:56Z
New Revision: 544f200c785f0314949ba3b8d1c51f65bf8d7761
URL: https://github.com/llvm/llvm-project/commit/544f200c785f0314949ba3b8d1c51f65bf8d7761
DIFF: https://github.com/llvm/llvm-project/commit/544f200c785f0314949ba3b8d1c51f65bf8d7761.diff
LOG: Fix newline handling in clang-query parser
Don't prematurely remove characters from the end of the string
Added:
Modified:
clang-tools-extra/clang-query/QueryParser.cpp
clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-query/QueryParser.cpp b/clang-tools-extra/clang-query/QueryParser.cpp
index a980722de9e6..896145bf961a 100644
--- a/clang-tools-extra/clang-query/QueryParser.cpp
+++ b/clang-tools-extra/clang-query/QueryParser.cpp
@@ -250,7 +250,7 @@ QueryRef QueryParser::doParse() {
return completeMatcherExpression();
Diagnostics Diag;
- auto MatcherSource = Line.trim();
+ auto MatcherSource = Line.ltrim();
auto OrigMatcherSource = MatcherSource;
Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(
MatcherSource, nullptr, &QS.NamedValues, &Diag);
diff --git a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
index 79fcfcae6e0d..fa16c7172bac 100644
--- a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
+++ b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
@@ -348,4 +348,12 @@ match callExpr
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\n");
+
+ 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);
}
More information about the cfe-commits
mailing list