[PATCH] D77715: [clangd] Add missing GoToStmt in FindTarget.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 02:07:53 PDT 2020


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

so that go-to-def on label can work.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77715

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


Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -130,6 +130,22 @@
     }
   )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) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -331,6 +331,14 @@
             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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77715.255926.patch
Type: text/x-patch
Size: 1387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200408/dd8d86eb/attachment.bin>


More information about the cfe-commits mailing list