summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-09 22:15:01 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-09 22:15:01 +0000
commit890d44eb7fb684b3d9104b0454e2b76a6c130fd3 (patch)
treea55ed857dc84a676870a301c1dcfc130c000ec93 /clang/lib
parent47b8cf6deb90a2782e92c67f7c5a20b5aacbee9f (diff)
downloadbcm5719-llvm-890d44eb7fb684b3d9104b0454e2b76a6c130fd3.tar.gz
bcm5719-llvm-890d44eb7fb684b3d9104b0454e2b76a6c130fd3.zip
Dead stores checker: Don't flag dead stores for self-assignments (common escape hatch for 'unused variable' warnings).
llvm-svn: 62010
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Analysis/CheckDeadStores.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Analysis/CheckDeadStores.cpp b/clang/lib/Analysis/CheckDeadStores.cpp
index 51943d50166..cad19f4f934 100644
--- a/clang/lib/Analysis/CheckDeadStores.cpp
+++ b/clang/lib/Analysis/CheckDeadStores.cpp
@@ -128,16 +128,23 @@ public:
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(B->getLHS()))
if (VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
+ Expr* RHS = B->getRHS()->IgnoreParenCasts();
+
// Special case: check for assigning null to a pointer.
// This is a common form of defensive programming.
if (VD->getType()->isPointerType()) {
- if (IntegerLiteral* L =
- dyn_cast<IntegerLiteral>(B->getRHS()->IgnoreParenCasts()))
+ if (IntegerLiteral* L = dyn_cast<IntegerLiteral>(RHS))
// FIXME: Probably should have an Expr::isNullPointerConstant.
if (L->getValue() == 0)
return;
}
-
+ // Special case: self-assignments. These are often used to shut up
+ // "unused variable" compiler warnings.
+ if (DeclRefExpr* RhsDR = dyn_cast<DeclRefExpr>(RHS))
+ if (VD == dyn_cast<VarDecl>(RhsDR->getDecl()))
+ return;
+
+ // Otherwise, issue a warning.
DeadStoreKind dsk =
Parents.isSubExpr(B)
? Enclosing
OpenPOWER on IntegriCloud