[cfe-commits] r41757 - in /cfe/trunk/Analysis: DeadStores.cpp LiveVariables.cpp

Ted Kremenek kremenek at apple.com
Thu Sep 6 16:39:53 PDT 2007


Author: kremenek
Date: Thu Sep  6 18:39:53 2007
New Revision: 41757

URL: http://llvm.org/viewvc/llvm-project?rev=41757&view=rev
Log:
Added more checking in "dead stores" for values that are initialized
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.

Modified:
    cfe/trunk/Analysis/DeadStores.cpp
    cfe/trunk/Analysis/LiveVariables.cpp

Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=41757&r1=41756&r2=41757&view=diff

==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Thu Sep  6 18:39:53 2007
@@ -47,6 +47,19 @@
         }
       }
     }
+    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);
+            }
+    }
   }
 };
   

Modified: cfe/trunk/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/LiveVariables.cpp?rev=41757&r1=41756&r2=41757&view=diff

==============================================================================
--- cfe/trunk/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/Analysis/LiveVariables.cpp Thu Sep  6 18:39:53 2007
@@ -252,7 +252,10 @@
     // 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);





More information about the cfe-commits mailing list