From 04757e7d94ce5db11bb397accb0b1c0523d351ba Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Thu, 12 Dec 2024 12:15:32 -0600 Subject: [PATCH 1/3] [clangd] Index reserved symbols from `*intrin.h` system headers 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: https://github.com/llvm/llvm-project/issues/118684 --- clang-tools-extra/clangd/index/SymbolCollector.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 81125dbb1aeaf..6d0af20e31260 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; From d320cbbf576fce53f6e3df477c705dd0bf645fca Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 13 Dec 2024 07:19:23 -0600 Subject: [PATCH 2/3] test --- .../clangd/unittests/SymbolCollectorTests.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index e8088cb37fa51..edc4e8aabe9a9 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -2111,6 +2111,20 @@ TEST_F(SymbolCollectorTest, Reserved) { EXPECT_THAT(Symbols, IsEmpty()); } +TEST_F(SymbolCollectorTest, UnreservedIntrin) { + const char *Header = R"cpp( + #pragma once + void __foo(); + )cpp"; + + TestHeaderName = "xintrin.h"; + TestHeaderURI = URI::create(testPath(TestHeaderName)).toString(); + InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem; + CollectorOpts.FallbackDir = testRoot(); + runSymbolCollector("#pragma GCC system_header\n" + std::string(Header), ""); + EXPECT_THAT(Symbols, UnorderedElementsAre(qName("__foo"))); +} + TEST_F(SymbolCollectorTest, Concepts) { const char *Header = R"cpp( template From f029a6216559f61f6e86ba62e9dff0e7b6c72c6b Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sun, 15 Dec 2024 02:51:19 -0500 Subject: [PATCH 3/3] tweak test name --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index edc4e8aabe9a9..7a9703c744e93 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -2111,7 +2111,7 @@ TEST_F(SymbolCollectorTest, Reserved) { EXPECT_THAT(Symbols, IsEmpty()); } -TEST_F(SymbolCollectorTest, UnreservedIntrin) { +TEST_F(SymbolCollectorTest, ReservedSymbolInIntrinsicHeader) { const char *Header = R"cpp( #pragma once void __foo();