Skip to content

Commit e1271dd

Browse files
[clangd] Index reserved symbols from *intrin.h system headers (#119735)
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 --------- Co-authored-by: Nathan Ridge <[email protected]>
1 parent 734a204 commit e1271dd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,14 @@ bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND,
550550
// Avoid indexing internal symbols in protobuf generated headers.
551551
if (isPrivateProtoDecl(ND))
552552
return false;
553+
554+
// System headers that end with `intrin.h` likely contain useful symbols.
553555
if (!Opts.CollectReserved &&
554556
(hasReservedName(ND) || hasReservedScope(*ND.getDeclContext())) &&
555-
ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation()))
557+
ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation()) &&
558+
!ASTCtx.getSourceManager()
559+
.getFilename(ND.getLocation())
560+
.ends_with("intrin.h"))
556561
return false;
557562

558563
return true;

clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,20 @@ TEST_F(SymbolCollectorTest, Reserved) {
21112111
EXPECT_THAT(Symbols, IsEmpty());
21122112
}
21132113

2114+
TEST_F(SymbolCollectorTest, ReservedSymbolInIntrinsicHeader) {
2115+
const char *Header = R"cpp(
2116+
#pragma once
2117+
void __foo();
2118+
)cpp";
2119+
2120+
TestHeaderName = "xintrin.h";
2121+
TestHeaderURI = URI::create(testPath(TestHeaderName)).toString();
2122+
InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem;
2123+
CollectorOpts.FallbackDir = testRoot();
2124+
runSymbolCollector("#pragma GCC system_header\n" + std::string(Header), "");
2125+
EXPECT_THAT(Symbols, UnorderedElementsAre(qName("__foo")));
2126+
}
2127+
21142128
TEST_F(SymbolCollectorTest, Concepts) {
21152129
const char *Header = R"cpp(
21162130
template <class T>

0 commit comments

Comments
 (0)