summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-08-13 20:13:06 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-08-13 20:13:06 +0000
commit98703d3883309f1a5eacf05299e0b850668334d5 (patch)
tree11284b550f11e59c2d2268d93bbb1dfc32fbe11d /clang/lib/Sema/SemaDecl.cpp
parentf288803a95d5d156030fc727b2c05f2d14e4ee89 (diff)
downloadbcm5719-llvm-98703d3883309f1a5eacf05299e0b850668334d5.tar.gz
bcm5719-llvm-98703d3883309f1a5eacf05299e0b850668334d5.zip
Revert 111026 & 111027, build breakage.
llvm-svn: 111036
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp64
1 files changed, 18 insertions, 46 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a37d25a1436..e1f9c82feca 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -521,52 +521,25 @@ static void RemoveUsingDecls(LookupResult &R) {
F.done();
}
-bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const {
- assert(D);
-
- if (D->isInvalidDecl() || D->isUsed() || D->hasAttr<UnusedAttr>())
- return false;
-
- // Ignore class templates.
- 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->isThisDeclarationADefinition())
- return !Context.DeclMustBeEmitted(FD);
- return true;
- }
-
- if (const VarDecl *VD = dyn_cast<VarDecl>(D))
- if (VD->isFileVarDecl())
- return !Context.DeclMustBeEmitted(VD);
-
- return false;
- }
-
- void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) {
- if (!D)
- return;
-
+static bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) {
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- const FunctionDecl *First = FD->getFirstDeclaration();
- if (FD != First && ShouldWarnIfUnusedFileScopedDecl(First))
- return; // First should already be in the vector.
- }
-
- if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
- const VarDecl *First = VD->getFirstDeclaration();
- if (VD != First && ShouldWarnIfUnusedFileScopedDecl(First))
- return; // First should already be in the vector.
+ // Warn for static, non-inlined function definitions that
+ // have not been used.
+ // FIXME: Also include static functions declared but not defined.
+ return (!FD->isInvalidDecl()
+ && !FD->isInlined() && FD->getLinkage() == InternalLinkage
+ && !FD->isUsed() && !FD->hasAttr<UnusedAttr>()
+ && !FD->hasAttr<ConstructorAttr>()
+ && !FD->hasAttr<DestructorAttr>());
}
+
+ return false;
+}
- if (ShouldWarnIfUnusedFileScopedDecl(D))
- UnusedFileScopedDecls.push_back(D);
- }
+void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) {
+ if (ShouldWarnIfUnusedFileScopedDecl(D))
+ UnusedFileScopedDecls.push_back(D);
+}
static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
if (D->isInvalidDecl())
@@ -2770,8 +2743,6 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
if (NewVD->getLinkage() == ExternalLinkage && !DC->isRecord())
AddPushedVisibilityAttribute(NewVD);
- MarkUnusedFileScopedDecl(NewVD);
-
return NewVD;
}
@@ -3667,7 +3638,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
if (FunctionTemplate)
return FunctionTemplate;
- MarkUnusedFileScopedDecl(NewFD);
+ if (IsFunctionDefinition)
+ MarkUnusedFileScopedDecl(NewFD);
return NewFD;
}
OpenPOWER on IntegriCloud