diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:17 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:17 +0000 |
commit | 49b96d1a382ae9f31456166f1a734d3f7f30b992 (patch) | |
tree | bb2d3d611d5aeb0efc82ca470524fe844aa497d6 /lib/Sema/SemaDecl.cpp | |
parent | f759b4dc74fe8b0cc6e1350b860676ac9b853371 (diff) |
Change Sema's UnusedStaticFuncs to UnusedFileScopedDecls to allow also keeping track of unused file scoped variables.
This is only preparation, currently only static function definitions are tracked, as before.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111025 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ea1cfa8f8a..e1f9c82fec 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -521,6 +521,26 @@ static void RemoveUsingDecls(LookupResult &R) { F.done(); } +static bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) { + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + // 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; +} + +void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) { + if (ShouldWarnIfUnusedFileScopedDecl(D)) + UnusedFileScopedDecls.push_back(D); +} + static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { if (D->isInvalidDecl()) return false; @@ -3618,17 +3638,9 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (FunctionTemplate) return FunctionTemplate; - - // Keep track of static, non-inlined function definitions that - // have not been used. We will warn later. - // FIXME: Also include static functions declared but not defined. - if (!NewFD->isInvalidDecl() && IsFunctionDefinition - && !NewFD->isInlined() && NewFD->getLinkage() == InternalLinkage - && !NewFD->isUsed() && !NewFD->hasAttr<UnusedAttr>() - && !NewFD->hasAttr<ConstructorAttr>() - && !NewFD->hasAttr<DestructorAttr>()) - UnusedStaticFuncs.push_back(NewFD); - + if (IsFunctionDefinition) + MarkUnusedFileScopedDecl(NewFD); + return NewFD; } @@ -4891,7 +4903,7 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg, // deletion in some later function. if (getDiagnostics().hasErrorOccurred()) ExprTemporaries.clear(); - + return D; } |