diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-09 22:15:01 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-09 22:15:01 +0000 |
commit | 3b58786f85aaa173e122f6eaff0b6efa233d59a2 (patch) | |
tree | 115faaecdab2e0db286c64c2e33c661c5bd63cea /lib/Analysis/CheckDeadStores.cpp | |
parent | 5f074266cc59563036c40516c814d63825723e20 (diff) |
Dead stores checker: Don't flag dead stores for self-assignments (common escape hatch for 'unused variable' warnings).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62010 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CheckDeadStores.cpp')
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 51943d5016..cad19f4f93 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/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 |