]> granicus.if.org Git - clang/commitdiff
Added more checking in "dead stores" for values that are initialized
authorTed Kremenek <kremenek@apple.com>
Thu, 6 Sep 2007 23:39:53 +0000 (23:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 6 Sep 2007 23:39:53 +0000 (23:39 +0000)
but never used.

Fix a bug in LiveVariables where uses on the LHS of self-assign
operators (e.g +=, *=, etc) would not be properly recorded in the
liveness state of the variable.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41757 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/DeadStores.cpp
Analysis/LiveVariables.cpp

index e7077ecae3116e50a887a8484a235b91794fa0f8..f79aa6ae047987787aac71b7d39dff03867d2af9 100644 (file)
@@ -47,6 +47,19 @@ public:
         }
       }
     }
+    else if(DeclStmt* DS = dyn_cast<DeclStmt>(S)) {
+      // Iterate through the decls.  Warn if any of them (which have
+      // initializers) are not live.
+      for (Decl* D = DS->getDecl() ; D != NULL ; D = D->getNextDeclarator())
+        if (VarDecl* V = dyn_cast<VarDecl>(D))
+          if (Expr* E = V->getInit())
+            if (!L.isLive(Live,D)) {
+              SourceRange R = E->getSourceRange();
+              PP.getDiagnostics().Report(D->getLocation(),
+                                         diag::warn_dead_store, 0, 0,
+                                         &R,1);
+            }
+    }
   }
 };
   
index 6b25f9eee60f9d6e4f3183d006f4bccd0eabdd70..bf4437470e371948ae5caf3ead10500cb16c960c 100644 (file)
@@ -252,7 +252,10 @@ void LivenessTFuncs::VisitAssign(BinaryOperator* B) {
     // We only need to register kills once, so we check if this block
     // has been previously processed.
     if (!blockPreviouslyProcessed)
-      V.AddKill(CurrentStmt,DR);    
+      V.AddKill(CurrentStmt,DR);
+      
+    if (B->getOpcode() != BinaryOperator::Assign)
+      Visit(LHS);
   }
   else
     Visit(LHS);