indexer: handle DecltypeType and empty main file; diag: -Wno-unused-function for headers

This commit is contained in:
Fangrui Song 2018-11-22 20:07:39 -08:00
parent 8c684c11c7
commit 9fb17be2cd
2 changed files with 25 additions and 4 deletions

View File

@ -481,6 +481,9 @@ void *DiagnosticMain(void *manager_) {
BuildCompilerInvocation(session->file.args, FS); BuildCompilerInvocation(session->file.args, FS);
if (!CI) if (!CI)
continue; continue;
// If main file is a header, add -Wno-unused-function
if (lookupExtension(session->file.filename).second)
CI->getDiagnosticOpts().Warnings.push_back("no-unused-function");
CI->getDiagnosticOpts().IgnoreWarnings = false; CI->getDiagnosticOpts().IgnoreWarnings = false;
CI->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking; CI->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking;
StoreDiags DC(path); StoreDiags DC(path);

View File

@ -552,7 +552,7 @@ public:
std::string_view qualified, IndexVar::Def &def) { std::string_view qualified, IndexVar::Def &def) {
QualType T; QualType T;
const Expr *init = nullptr; const Expr *init = nullptr;
bool binding = false; bool deduced = false;
if (auto *VD = dyn_cast<VarDecl>(D)) { if (auto *VD = dyn_cast<VarDecl>(D)) {
T = VD->getType(); T = VD->getType();
init = VD->getAnyInitializer(); init = VD->getAnyInitializer();
@ -562,9 +562,23 @@ public:
init = FD->getInClassInitializer(); init = FD->getInClassInitializer();
} else if (auto *BD = dyn_cast<BindingDecl>(D)) { } else if (auto *BD = dyn_cast<BindingDecl>(D)) {
T = BD->getType(); T = BD->getType();
binding = true; deduced = true;
} }
if (!T.isNull() && (binding || T->getContainedDeducedType())) { if (!T.isNull()) {
if (DeducedType *AT = T->getContainedDeducedType()) {
if (QualType T1 = AT->getDeducedType(); !T1.isNull())
T = T1;
deduced = true;
} else if (auto *DT = dyn_cast<DecltypeType>(T)) {
// decltype(y) x;
while (DT && !DT->getUnderlyingType().isNull()) {
T = DT->getUnderlyingType();
DT = dyn_cast<DecltypeType>(T);
}
deduced = true;
}
}
if (!T.isNull() && deduced) {
SmallString<256> Str; SmallString<256> Str;
llvm::raw_svector_ostream OS(Str); llvm::raw_svector_ostream OS(Str);
PrintingPolicy PP = GetDefaultPolicy(); PrintingPolicy PP = GetDefaultPolicy();
@ -671,7 +685,11 @@ public:
public: public:
IndexDataConsumer(IndexParam &param) : param(param) {} IndexDataConsumer(IndexParam &param) : param(param) {}
void initialize(ASTContext &Ctx) override { this->Ctx = param.Ctx = &Ctx; } void initialize(ASTContext &Ctx) override {
this->Ctx = param.Ctx = &Ctx;
SourceManager &SM = Ctx.getSourceManager();
(void)param.ConsumeFile(*SM.getFileEntryForID(SM.getMainFileID()));
}
bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles, bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef<index::SymbolRelation> Relations, ArrayRef<index::SymbolRelation> Relations,
#if LLVM_VERSION_MAJOR >= 7 #if LLVM_VERSION_MAJOR >= 7