[clang-tools-extra] a533b03 - [clangd] Add missing GoToStmt in FindTarget.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 05:20:02 PDT 2020
Author: Haojian Wu
Date: 2020-04-08T14:19:52+02:00
New Revision: a533b03028fad4555e53b803197980735ccd68f9
URL: https://github.com/llvm/llvm-project/commit/a533b03028fad4555e53b803197980735ccd68f9
DIFF: https://github.com/llvm/llvm-project/commit/a533b03028fad4555e53b803197980735ccd68f9.diff
LOG: [clangd] Add missing GoToStmt in FindTarget.
Summary: so that go-to-def on label can work.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77715
Added:
Modified:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 9a397a5a4383..ff50323980a7 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -331,6 +331,14 @@ struct TargetFinder {
break;
}
}
+ void VisitGotoStmt(const GotoStmt *Goto) {
+ if (auto *LabelDecl = Goto->getLabel())
+ Outer.add(LabelDecl, Flags);
+ }
+ void VisitLabelStmt(const LabelStmt *Label) {
+ if (auto *LabelDecl = Label->getDecl())
+ Outer.add(LabelDecl, Flags);
+ }
void
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
const Type *BaseType = E->getBaseType().getTypePtrOrNull();
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index e0def88845a8..cdea98c299e8 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -130,6 +130,22 @@ TEST_F(TargetDeclTest, Exprs) {
}
)cpp";
EXPECT_DECLS("CXXOperatorCallExpr", "void operator()(int n)");
+
+ Code = R"cpp(
+ void test() {
+ goto [[label]];
+ label:
+ return;
+ }
+ )cpp";
+ EXPECT_DECLS("GotoStmt", "label:");
+ Code = R"cpp(
+ void test() {
+ [[label]]:
+ return;
+ }
+ )cpp";
+ EXPECT_DECLS("LabelStmt", "label:");
}
TEST_F(TargetDeclTest, Recovery) {
More information about the cfe-commits
mailing list