[clang-tools-extra] r358098 - [clangd] Fix non-indexing of builtin functions like printf when the TU is C
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 10 09:26:58 PDT 2019
Author: sammccall
Date: Wed Apr 10 09:26:58 2019
New Revision: 358098
URL: http://llvm.org/viewvc/llvm-project?rev=358098&view=rev
Log:
[clangd] Fix non-indexing of builtin functions like printf when the TU is C
Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=358098&r1=358097&r2=358098&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed Apr 10 09:26:58 2019
@@ -236,8 +236,6 @@ bool SymbolCollector::shouldCollectSymbo
const ASTContext &ASTCtx,
const Options &Opts,
bool IsMainFileOnly) {
- if (ND.isImplicit())
- return false;
// Skip anonymous declarations, e.g (anonymous enum/class/struct).
if (ND.getDeclName().isEmpty())
return false;
@@ -328,7 +326,9 @@ bool SymbolCollector::handleDeclOccurenc
// then no public declaration was visible, so assume it's main-file only.
bool IsMainFileOnly =
SM.isWrittenInMainFile(SM.getExpansionLoc(ND->getBeginLoc()));
- if (!shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly))
+ // In C, printf is a redecl of an implicit builtin! So check OrigD instead.
+ if (ASTNode.OrigD->isImplicit() ||
+ !shouldCollectSymbol(*ND, *ASTCtx, Opts, IsMainFileOnly))
return true;
// Do not store references to main-file symbols.
if (CollectRef && !IsMainFileOnly && !isa<NamespaceDecl>(ND) &&
Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=358098&r1=358097&r2=358098&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Wed Apr 10 09:26:58 2019
@@ -254,9 +254,8 @@ public:
auto Factory = llvm::make_unique<SymbolIndexActionFactory>(
CollectorOpts, PragmaHandler.get());
- std::vector<std::string> Args = {
- "symbol_collector", "-fsyntax-only", "-xc++",
- "-std=c++11", "-include", TestHeaderName};
+ std::vector<std::string> Args = {"symbol_collector", "-fsyntax-only",
+ "-xc++", "-include", TestHeaderName};
Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end());
// This allows to override the "-xc++" with something else, i.e.
// -xobjective-c++.
@@ -1165,6 +1164,15 @@ TEST_F(SymbolCollectorTest, UsingDecl) {
EXPECT_THAT(Symbols, Contains(QName("std::foo")));
}
+TEST_F(SymbolCollectorTest, CBuiltins) {
+ // In C, printf in stdio.h is a redecl of an implicit builtin.
+ const char *Header = R"(
+ extern int printf(const char*, ...);
+ )";
+ runSymbolCollector(Header, /**/ "", {"-xc"});
+ EXPECT_THAT(Symbols, Contains(QName("printf")));
+}
+
} // namespace
} // namespace clangd
} // namespace clang
More information about the cfe-commits
mailing list