diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -127,6 +127,13 @@ [Foo [[x]]:2 [[^y]]:4]; } )cpp", + R"cpp( // Label + int main() { + goto [[^theLabel]]; + [[theLabel]]: + return 1; + } + )cpp", }; for (const char *Test : Tests) { Annotations T(Test); diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp --- a/clang/lib/Index/IndexBody.cpp +++ b/clang/lib/Index/IndexBody.cpp @@ -144,6 +144,23 @@ Parent, ParentDC, Roles, Relations, E); } + bool VisitGotoStmt(GotoStmt *S) { + if (IndexCtx.shouldIndexFunctionLocalSymbols()) { + return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent, + ParentDC, + unsigned(SymbolRole::NameReference)); + } + return true; + } + + bool VisitLabelStmt(LabelStmt *S) { + if (IndexCtx.shouldIndexFunctionLocalSymbols()) { + return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent, + ParentDC, {}); + } + return true; + } + bool VisitMemberExpr(MemberExpr *E) { SourceLocation Loc = E->getMemberLoc(); if (Loc.isInvalid())