From 544f200c785f0314949ba3b8d1c51f65bf8d7761 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 29 Dec 2019 14:48:47 +0000 Subject: [PATCH] Fix newline handling in clang-query parser Don't prematurely remove characters from the end of the string --- clang-tools-extra/clang-query/QueryParser.cpp | 2 +- .../unittests/clang-query/QueryParserTest.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 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(Q)); EXPECT_EQ("1:1: Invalid token found when looking for a value.", cast(Q)->ErrStr); + + Q = parse("\nm parmVarDecl()\nlet someMatcher\n"); + + ASSERT_TRUE(isa(Q)); + Q = parse(Q->RemainingContent); + + ASSERT_TRUE(isa(Q)); + EXPECT_EQ("1:1: Invalid token found when looking for a value.", cast(Q)->ErrStr); }