[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 9 02:54:20 PDT 2023


ilya-biryukov added a comment.

Thanks! This looks like a useful addition.

Could you add a test into `libIndex` for this too? Just for the sake of having better coverage, some folks probably don't run `clang-tools-extra` tests.
Also, could we add a test that a label does not get indexed if local function indexing is off?



================
Comment at: clang/lib/Index/IndexBody.cpp:148
+  bool VisitGotoStmt(GotoStmt *S) {
+    if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+      return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
----------------
`IndexingContext::handleReference` already has this check, we should call `handleReference` unconditionally.




================
Comment at: clang/lib/Index/IndexBody.cpp:158
+    if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+      return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent,
+                                      ParentDC, {});
----------------
We should call `handleDecl`, indexing output can differentiate between a declarations and a references.
`LabelStmt` is exactly the node that declares a `LabelDecl`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150124/new/

https://reviews.llvm.org/D150124



More information about the cfe-commits mailing list