aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-10-27 01:41:35 +0000
committerJohn McCall <rjmccall@apple.com>2010-10-27 01:41:35 +0000
commit82b965992fbd27da37b9e13b5ef618d73f33e5c9 (patch)
treec28437f12b3f348525a4d1ac383bda850236cbd2
parentd4aff0e2b77879e27e7e4eac8c972aaaa293fa12 (diff)
Avoid calculating linkage until the more obvious checks have run when
deciding whether to queue a decl for unused-declaration warnings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117431 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index de3a4f963f..a85e5f5cac 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/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<FunctionDecl>(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<VarDecl>(D)) {
+ if (!VD->isFileVarDecl() ||
+ VD->getType().isConstant(Context) ||
+ Context.DeclMustBeEmitted(VD))
+ return false;
- if (const VarDecl *VD = dyn_cast<VarDecl>(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;
+
+ return true;
+}
- void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) {
+void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) {
if (!D)
return;