[clang-tools-extra] f5465e7 - [clangd] Include expression in DecltypeTypeLoc sourcerange while building SelectionTree
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 13 11:34:47 PST 2020
Author: Kadir Cetinkaya
Date: 2020-01-13T20:33:13+01:00
New Revision: f5465e74ef4c9e24f867002aa598dc9e6481ead3
URL: https://github.com/llvm/llvm-project/commit/f5465e74ef4c9e24f867002aa598dc9e6481ead3
DIFF: https://github.com/llvm/llvm-project/commit/f5465e74ef4c9e24f867002aa598dc9e6481ead3.diff
LOG: [clangd] Include expression in DecltypeTypeLoc sourcerange while building SelectionTree
Summary:
Currently AST only contains the location for `decltype` keyword,
therefore we were skipping expressions inside decltype while building selection
tree.
This patch extends source range in such cases to contain the expression as well.
A proper fix would require changes to Sema and DecltypeTypeLoc to contain these
location information.
Fixes https://github.com/clangd/clangd/issues/250.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D72594
Added:
Modified:
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index ffa48f3a57d9..14c05d1c0b49 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -527,6 +527,19 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
// don't intersect the selection may be recursively skipped.
bool canSafelySkipNode(const DynTypedNode &N) {
SourceRange S = N.getSourceRange();
+ if (auto *TL = N.get<TypeLoc>()) {
+ // DeclTypeTypeLoc::getSourceRange() is incomplete, which would lead to
+ // failing
+ // to descend into the child expression.
+ // decltype(2+2);
+ // ~~~~~~~~~~~~~ <-- correct range
+ // ~~~~~~~~ <-- range reported by getSourceRange()
+ // ~~~~~~~~~~~~ <-- range with this hack(i.e, missing closing paren)
+ // FIXME: Alter DecltypeTypeLoc to contain parentheses locations and get
+ // rid of this patch.
+ if (auto DT = TL->getAs<DecltypeTypeLoc>())
+ S.setEnd(DT.getUnderlyingExpr()->getEndLoc());
+ }
if (!SelChecker.mayHit(S)) {
dlog("{1}skip: {0}", printNodeToString(N, PrintPolicy), indent());
dlog("{1}skipped range = {0}", S.printToString(SM), indent(1));
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 9e1a90b55e3a..581309b1dccc 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -323,6 +323,12 @@ TEST(SelectionTest, CommonAncestor) {
Foo x = [[^12_ud]];
)cpp",
"UserDefinedLiteral"},
+ {
+ R"cpp(
+ int a;
+ decltype([[^a]] + a) b;
+ )cpp",
+ "DeclRefExpr"},
};
for (const Case &C : Cases) {
Annotations Test(C.Code);
More information about the cfe-commits
mailing list