[PATCH] D77717: [clang][index] index the missing LabelDecl in libindex.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 06:28:12 PDT 2020
hokein updated this revision to Diff 256001.
hokein added a comment.
Herald added subscribers: usaxena95, jkorous.
add a clangd xref test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77717/new/
https://reviews.llvm.org/D77717
Files:
clang-tools-extra/clangd/unittests/XRefsTests.cpp
clang/lib/Index/IndexBody.cpp
clang/unittests/Index/IndexTests.cpp
Index: clang/unittests/Index/IndexTests.cpp
===================================================================
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -334,6 +334,28 @@
WrittenAt(Position(3, 20)))));
}
+TEST(IndexTest, LabelDecl) {
+ std::string Code = R"cpp(
+ void foo() {
+ label:
+ return;
+ }
+ )cpp";
+ auto Index = std::make_shared<Indexer>();
+ IndexingOptions Opts;
+ Opts.IndexFunctionLocals = true;
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
+ EXPECT_THAT(Index->Symbols,
+ Contains(AllOf(QName("label"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(3, 5)))));
+ Index->Symbols.clear();
+ Opts.IndexFunctionLocals = false;
+ tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
+ EXPECT_THAT(Index->Symbols,
+ Not(Contains(AllOf(QName("label"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(3, 5))))));
+}
+
} // namespace
} // namespace index
} // namespace clang
Index: clang/lib/Index/IndexBody.cpp
===================================================================
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -140,6 +140,21 @@
Parent, ParentDC, Roles, Relations, E);
}
+ bool VisitGotoStmt(GotoStmt *Goto) {
+ if (auto *LabelDecl = Goto->getLabel())
+ IndexCtx.handleReference(LabelDecl, Goto->getLabelLoc(), Parent, ParentDC,
+ static_cast<unsigned>(SymbolRole::Reference));
+ return true;
+ }
+
+ bool VisitLabelStmt(LabelStmt *Label) {
+ if (auto *LabelDecl = Label->getDecl())
+ IndexCtx.handleReference(LabelDecl, Label->getIdentLoc(), Parent,
+ ParentDC,
+ static_cast<unsigned>(SymbolRole::Reference));
+ return true;
+ }
+
bool VisitMemberExpr(MemberExpr *E) {
SourceLocation Loc = E->getMemberLoc();
if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1083,6 +1083,14 @@
}
)cpp",
+ R"cpp(// Goto Label.
+ void test() {
+ [[la^bel]]:
+ return;
+ goto [[label]];
+ }
+ )cpp",
+
R"cpp(
int [[v^ar]] = 0;
void foo(int s = [[var]]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77717.256001.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200408/b00eec8a/attachment-0001.bin>
More information about the cfe-commits
mailing list