From d37d35b571c2bc9711638c85bcf9c0a1bf8ecfcf Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 27 Oct 2010 01:41:35 +0000 Subject: [PATCH] Avoid calculating linkage until the more obvious checks have run when deciding whether to queue a decl for unused-declaration warnings. llvm-svn: 117431 --- clang/lib/Sema/SemaDecl.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index de3a4f963fb1..a85e5f5cac46 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -559,10 +559,6 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { if (D->getDeclContext()->isDependentContext()) return false; - // We warn for unused decls internal to the translation unit. - if (D->getLinkage() == ExternalLinkage) - return false; - if (const FunctionDecl *FD = dyn_cast(D)) { if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return false; @@ -577,25 +573,32 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { return false; } - if (FD->isThisDeclarationADefinition()) - return !Context.DeclMustBeEmitted(FD); - return true; - } + if (FD->isThisDeclarationADefinition() && + Context.DeclMustBeEmitted(FD)) + return false; + + } else if (const VarDecl *VD = dyn_cast(D)) { + if (!VD->isFileVarDecl() || + VD->getType().isConstant(Context) || + Context.DeclMustBeEmitted(VD)) + return false; - if (const VarDecl *VD = dyn_cast(D)) { if (VD->isStaticDataMember() && VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return false; - if ( VD->isFileVarDecl() && - !VD->getType().isConstant(Context)) - return !Context.DeclMustBeEmitted(VD); + } else { + return false; } - return false; - } + // Only warn for unused decls internal to the translation unit. + if (D->getLinkage() == ExternalLinkage) + return false; - void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) { + return true; +} + +void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) { if (!D) return;