[clangd] Add missing GoToStmt in FindTarget.
authorHaojian Wu <hokein.wu@gmail.com>
Wed, 8 Apr 2020 09:03:50 +0000 (11:03 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Wed, 8 Apr 2020 12:19:52 +0000 (14:19 +0200)
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

clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

index 9a397a5..ff50323 100644 (file)
@@ -331,6 +331,14 @@ public:
             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();
index e0def88..cdea98c 100644 (file)
@@ -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) {