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 | 35672e78523162ab292962ce5aec3f512ee5cf8a (patch) | |
| tree | 3fc477ff544140ebd4fe96a5b0fa46005c823a99 /clang/lib/Sema/SemaDecl.cpp | |
| parent | 5cd66587988e8fc858ca1c32f7cb295966fd824d (diff) | |
| download | bcm5719-llvm-35672e78523162ab292962ce5aec3f512ee5cf8a.tar.gz bcm5719-llvm-35672e78523162ab292962ce5aec3f512ee5cf8a.zip | |
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.
llvm-svn: 111025
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ea1cfa8f8a4..e1f9c82feca 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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; } |

