Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,20 @@ TEST_F(SymbolCollectorTest, Reserved) {
EXPECT_THAT(Symbols, IsEmpty());
}

TEST_F(SymbolCollectorTest, ReservedSymbolInIntrinsicHeader) {
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 <class T>
Expand Down
Loading