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/Sema.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/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 778bf8c98a..f5c85ad99c 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -262,12 +262,12 @@ void Sema::ActOnEndOfTranslationUnit() { break; } - // Remove functions that turned out to be used. - UnusedStaticFuncs.erase(std::remove_if(UnusedStaticFuncs.begin(), - UnusedStaticFuncs.end(), - std::bind2nd(std::mem_fun(&FunctionDecl::isUsed), + // Remove file scoped decls that turned out to be used. + UnusedFileScopedDecls.erase(std::remove_if(UnusedFileScopedDecls.begin(), + UnusedFileScopedDecls.end(), + std::bind2nd(std::mem_fun(&DeclaratorDecl::isUsed), true)), - UnusedStaticFuncs.end()); + UnusedFileScopedDecls.end()); if (!CompleteTranslationUnit) return; @@ -330,14 +330,16 @@ void Sema::ActOnEndOfTranslationUnit() { } - // Output warning for unused functions. - for (std::vector<FunctionDecl*>::iterator - F = UnusedStaticFuncs.begin(), - FEnd = UnusedStaticFuncs.end(); - F != FEnd; - ++F) - Diag((*F)->getLocation(), diag::warn_unused_function) << (*F)->getDeclName(); - + // Output warning for unused file scoped decls. + for (std::vector<const DeclaratorDecl*>::iterator + I = UnusedFileScopedDecls.begin(), + E = UnusedFileScopedDecls.end(); I != E; ++I) { + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) + Diag(FD->getLocation(), diag::warn_unused_function) << FD->getDeclName(); + else + Diag((*I)->getLocation(), diag::warn_unused_variable) + << cast<VarDecl>(*I)->getDeclName(); + } } |