diff options
| author | Ted Kremenek <kremenek@apple.com> | 2007-09-28 20:48:41 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2007-09-28 20:48:41 +0000 |
| commit | a6ef56e6d212014d7c959a6be85d00a97b06355c (patch) | |
| tree | 2ef6d3eba0f32394ec6547a9904af66eff354304 /clang | |
| parent | 0064ff47e6087c2aec76efe4639da7140580d6c3 (diff) | |
| download | bcm5719-llvm-a6ef56e6d212014d7c959a6be85d00a97b06355c.tar.gz bcm5719-llvm-a6ef56e6d212014d7c959a6be85d00a97b06355c.zip | |
DeadStores no longer reports warnings for stores to non-local variables.
llvm-svn: 42447
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Analysis/DeadStores.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/clang/Analysis/DeadStores.cpp b/clang/Analysis/DeadStores.cpp index 28c21b0b2d1..3c3117cf09b 100644 --- a/clang/Analysis/DeadStores.cpp +++ b/clang/Analysis/DeadStores.cpp @@ -37,11 +37,11 @@ public: if (!B->isAssignmentOp()) return; // Skip non-assignments. if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(B->getLHS())) - // Is the variable NOT live? If so, flag a dead store. - if (!Live(DR->getDecl(),AD)) { - SourceRange R = B->getRHS()->getSourceRange(); - Diags.Report(DR->getSourceRange().Begin(), diag::warn_dead_store, - 0, 0, &R, 1); + if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl())) + if (VD->hasLocalStorage() && !Live(VD,AD)) { + SourceRange R = B->getRHS()->getSourceRange(); + Diags.Report(DR->getSourceRange().Begin(), diag::warn_dead_store, + 0, 0, &R, 1); } } else if(DeclStmt* DS = dyn_cast<DeclStmt>(S)) @@ -49,23 +49,24 @@ public: // expressions that are not live (never used). for (VarDecl* V = cast<VarDecl>(DS->getDecl()); V != NULL ; V = cast_or_null<VarDecl>(V->getNextDeclarator())) { - if (Expr* E = V->getInit()) { - if (!Live(DS->getDecl(),AD)) { - // Special case: check for initializations with constants. - // - // e.g. : int x = 0; - // - // If x is EVER assigned a new value later, don't issue - // a warning. This is because such initialization can be - // due to defensive programming. - if (!E->isConstantExpr(Ctx,NULL)) { - // Flag a warning. - SourceRange R = E->getSourceRange(); - Diags.Report(V->getLocation(), diag::warn_dead_store, 0, 0, - &R,1); + if (V->hasLocalStorage()) + if (Expr* E = V->getInit()) { + if (!Live(DS->getDecl(),AD)) { + // Special case: check for initializations with constants. + // + // e.g. : int x = 0; + // + // If x is EVER assigned a new value later, don't issue + // a warning. This is because such initialization can be + // due to defensive programming. + if (!E->isConstantExpr(Ctx,NULL)) { + // Flag a warning. + SourceRange R = E->getSourceRange(); + Diags.Report(V->getLocation(), diag::warn_dead_store, 0, 0, + &R,1); + } } } - } } } }; |

