[cfe-commits] r53628 - in /cfe/trunk: lib/Analysis/DeadStores.cpp test/Analysis/conditional-op-missing-lhs.c
Ted Kremenek
kremenek at apple.com
Tue Jul 15 11:06:32 PDT 2008
Author: kremenek
Date: Tue Jul 15 13:06:32 2008
New Revision: 53628
URL: http://llvm.org/viewvc/llvm-project?rev=53628&view=rev
Log:
Distinguish between dead stores and dead initializations.
Modified:
cfe/trunk/lib/Analysis/DeadStores.cpp
cfe/trunk/test/Analysis/conditional-op-missing-lhs.c
Modified: cfe/trunk/lib/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DeadStores.cpp?rev=53628&r1=53627&r2=53628&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/DeadStores.cpp Tue Jul 15 13:06:32 2008
@@ -37,16 +37,26 @@
virtual ~DeadStoreObs() {}
- void Report(VarDecl* V, bool inEnclosing, SourceLocation L, SourceRange R) {
+ void Report(VarDecl* V, bool inEnclosing, SourceLocation L, SourceRange R,
+ bool isInitialization = false) {
- std::string name(V->getName());
- std::string msg = inEnclosing
- ? "Although the value stored to '" + name +
- "' is used in the enclosing expression, the value is never actually"
- " read from '" + name + "'"
- : "Value stored to '" + name + "' is never read";
+ std::string name(V->getName());
- BR.EmitBasicReport("dead store", msg.c_str(), L, R);
+ if (isInitialization) {
+ std::string msg = "Value stored to '" + name +
+ "' during its initialization is never read";
+
+ BR.EmitBasicReport("dead initialization", msg.c_str(), L, R);
+ }
+ else {
+ std::string msg = inEnclosing
+ ? "Although the value stored to '" + name +
+ "' is used in the enclosing expression, the value is never actually"
+ " read from '" + name + "'"
+ : "Value stored to '" + name + "' is never read";
+
+ BR.EmitBasicReport("dead store", msg.c_str(), L, R);
+ }
}
void CheckVarDecl(VarDecl* VD, Expr* Ex, Expr* Val,
@@ -124,7 +134,7 @@
// a warning. This is because such initialization can be
// due to defensive programming.
if (!E->isConstantExpr(Ctx,NULL))
- Report(V, false, V->getLocation(), E->getSourceRange());
+ Report(V, false, V->getLocation(), E->getSourceRange(), true);
}
}
}
Modified: cfe/trunk/test/Analysis/conditional-op-missing-lhs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/conditional-op-missing-lhs.c?rev=53628&r1=53627&r2=53628&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/conditional-op-missing-lhs.c (original)
+++ cfe/trunk/test/Analysis/conditional-op-missing-lhs.c Tue Jul 15 13:06:32 2008
@@ -4,7 +4,7 @@
{
int i;
- int j = i ? : 1; // expected-warning{{use of uninitialized variable}} //expected-warning{{Value stored to 'j' is never read}}
+ int j = i ? : 1; // expected-warning{{use of uninitialized variable}} //expected-warning{{Value stored to 'j' during its initialization is never read}}
}
void *f2(int *i)
More information about the cfe-commits
mailing list