Skip to content

[clangd] Index reserved symbols from *intrin.h system headers #119735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Dec 12, 2024

Summary:
clangd intentionally suppresses indexing symbols from system headers
as these are likely implementation details the user does not want.
Howver, there are plenty of system headers that provide extensions that
we want to index, such as vector intrinsic headers. This patch adds an
extra check for these commonly-named '*intrin.h' headers. This is not
fully inclusive for all symbols the user might want, but it's a good
start.

Fixes: #118684

@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Joseph Huber (jhuber6)

Changes

Summary:
clangd intentionally suppresses indexing symbols from system headers
as these are likely implementation details the user does not want.
Howver, there are plenty of system headers that provide extensions that
we want to index, such as vector intrinsic headers. This patch adds an
extra check for these commonly-named '*intrin.h' headers. This is not
fully inclusive for all symbols the user might want, but it's a good
start.

Fixes: #118684


Full diff: https://github.com/llvm/llvm-project/pull/119735.diff

1 Files Affected:

  • (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+6-1)
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 81125dbb1aeafc..6d0af20e31260c 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -550,9 +550,14 @@ bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND,
   // Avoid indexing internal symbols in protobuf generated headers.
   if (isPrivateProtoDecl(ND))
     return false;
+
+  // System headers that end with `intrin.h` likely contain useful symbols.
   if (!Opts.CollectReserved &&
       (hasReservedName(ND) || hasReservedScope(*ND.getDeclContext())) &&
-      ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation()))
+      ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation()) &&
+      !ASTCtx.getSourceManager()
+           .getFilename(ND.getLocation())
+           .ends_with("intrin.h"))
     return false;
 
   return true;

Copy link
Collaborator

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I thought about whether it makes sense to have an additional check for the *intrin.h header being inside the resource directory specifically, but I don't see any headers with that name ending in any other system include directories, so I don't think we need to bother.

Would you mind adding a test case to SymbolCollectorTests.cpp as well? Here's an example of a test customizing a header file name, and here of exercising the "is system header" codepath.

Summary:
`clangd` intentionally suppresses indexing symbols from system headers
as these are likely implementation details the user does not want.
Howver, there are plenty of system headers that provide extensions that
we want to index, such as vector intrinsic headers. This patch adds an
extra check for these commonly-named '*intrin.h' headers. This is not
fully inclusive for all symbols the user might want, but it's a good
start.

Fixes: llvm#118684
@jhuber6 jhuber6 force-pushed the FixIntrinSymbols branch 2 times, most recently from 46e5548 to 89b8a34 Compare December 13, 2024 15:35
Copy link
Collaborator

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (I made a small tweak to the test name)

@jhuber6 jhuber6 merged commit e1271dd into llvm:main Dec 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clangd] Allow indexing of exposed resource directory headers
3 participants