aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-21 22:59:16 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-21 22:59:16 +0000
commit3eb817e5095d25e7bf4a8df9ed3f9b13bed6f298 (patch)
tree1fa0d59723aed572dfeb0916275d433e6bdc6040
parente1b6d5084ecf8c81c315dece1d203acdb6eb8fb5 (diff)
Improve dead stores diagnostics to include the variable name.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51395 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticKinds.def3
-rw-r--r--lib/Analysis/DeadStores.cpp13
-rw-r--r--test/Analysis/dead-stores.c10
3 files changed, 15 insertions, 11 deletions
diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def
index 3eb08e4b55..1eb36e4b51 100644
--- a/include/clang/Basic/DiagnosticKinds.def
+++ b/include/clang/Basic/DiagnosticKinds.def
@@ -1007,9 +1007,6 @@ DIAG(warn_floatingpoint_eq, WARNING,
DIAG(warn_selfcomparison,WARNING,
"self-comparison always results in a constant value.")
-// CHECK: stores to variables that are no longer live (dead stores)
-DIAG(warn_dead_store, WARNING, "value stored to variable is never used")
-
// CHECK: use of uninitialized values
DIAG(warn_uninit_val, WARNING, "use of uninitialized variable")
diff --git a/lib/Analysis/DeadStores.cpp b/lib/Analysis/DeadStores.cpp
index f7523e508f..fb241fd552 100644
--- a/lib/Analysis/DeadStores.cpp
+++ b/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);
}
}
}
diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c
index 2ec9b48f00..21427c6910 100644
--- a/test/Analysis/dead-stores.c
+++ b/test/Analysis/dead-stores.c
@@ -3,12 +3,12 @@
void f1() {
int k, y;
int abc=1;
- long idx=abc+3*5; // expected-warning {{value stored to variable is never used}}
+ long idx=abc+3*5; // expected-warning {{never used}}
}
void f2(void *b) {
char *c = (char*)b; // no-warning
- char *d = b+1; // expected-warning {{value stored to variable is never used}}
+ char *d = b+1; // expected-warning {{never used}}
printf("%s", c);
}
@@ -27,19 +27,19 @@ void f4(int k) {
if (k)
f1();
- k = 2; // expected-warning {{value stored to variable is never used}}
+ k = 2; // expected-warning {{never used}}
}
void f5() {
int x = 4; // no-warning
- int *p = &x; // expected-warning{{value stored to variable is never used}}
+ int *p = &x; // expected-warning{{never used}}
}
int f6() {
int x = 4;
- ++x; // expected-warning{{value stored to variable is never used}}
+ ++x; // expected-warning{{never used}}
return 1;
}