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")
#include "clang/Basic/Diagnostic.h"
#include "clang/AST/ASTContext.h"
#include "llvm/Support/Compiler.h"
+#include <sstream>
using namespace clang;
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);
}
}
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);
}
}
}
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);
}
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;
}