diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-05-21 22:59:16 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-05-21 22:59:16 +0000 |
commit | 91f035cda700f19129675d503b6bd65c41c6c566 (patch) | |
tree | c823067047db5c35d89cbd45174a0221a39296df /clang/lib | |
parent | a5d27ae5866e5751a0369798e3fa35578a5dd023 (diff) | |
download | bcm5719-llvm-91f035cda700f19129675d503b6bd65c41c6c566.tar.gz bcm5719-llvm-91f035cda700f19129675d503b6bd65c41c6c566.zip |
Improve dead stores diagnostics to include the variable name.
llvm-svn: 51395
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Analysis/DeadStores.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Analysis/DeadStores.cpp b/clang/lib/Analysis/DeadStores.cpp index f7523e508f0..fb241fd5525 100644 --- a/clang/lib/Analysis/DeadStores.cpp +++ b/clang/lib/Analysis/DeadStores.cpp @@ -20,6 +20,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/AST/ASTContext.h" #include "llvm/Support/Compiler.h" +#include <sstream> using namespace clang; @@ -35,16 +36,22 @@ public: virtual ~DeadStoreObs() {} + unsigned GetDiag(VarDecl* VD) { + std::ostringstream os; + os << "value stored to '" << VD->getName() << "' is never used"; + return Diags.getCustomDiagID(Diagnostic::Warning, os.str().c_str()); + } + void CheckDeclRef(DeclRefExpr* DR, Expr* Val, const LiveVariables::AnalysisDataTy& AD, const LiveVariables::ValTy& Live) { if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) if (VD->hasLocalStorage() && !Live(VD, AD)) { - SourceRange R = Val->getSourceRange(); + SourceRange R = Val->getSourceRange(); Diags.Report(&Client, Ctx.getFullLoc(DR->getSourceRange().getBegin()), - diag::warn_dead_store, 0, 0, &R, 1); + GetDiag(VD), 0, 0, &R, 1); } } @@ -94,7 +101,7 @@ public: SourceRange R = E->getSourceRange(); Diags.Report(&Client, Ctx.getFullLoc(V->getLocation()), - diag::warn_dead_store, 0, 0, &R, 1); + GetDiag(V), 0, 0, &R, 1); } } } |