From c6a1fafe4289da10487799fc745eedc73dd8e5bc Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 28 Sep 2007 20:48:41 +0000 Subject: [PATCH] DeadStores no longer reports warnings for stores to non-local variables. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42447 91177308-0d34-0410-b5e6-96231b3b80d8 --- Analysis/DeadStores.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Analysis/DeadStores.cpp b/Analysis/DeadStores.cpp index 28c21b0b2d..3c3117cf09 100644 --- a/Analysis/DeadStores.cpp +++ b/Analysis/DeadStores.cpp @@ -37,11 +37,11 @@ public: if (!B->isAssignmentOp()) return; // Skip non-assignments. if (DeclRefExpr* DR = dyn_cast(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(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(S)) @@ -49,23 +49,24 @@ public: // expressions that are not live (never used). for (VarDecl* V = cast(DS->getDecl()); V != NULL ; V = cast_or_null(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); + } } } - } } } }; -- 2.40.0