[cfe-commits] r49709 - in /cfe/trunk: include/clang/Analysis/FlowSensitive/DataflowSolver.h lib/Analysis/LiveVariables.cpp lib/Analysis/UninitializedValues.cpp

Ted Kremenek kremenek at apple.com
Mon Apr 14 21:39:08 PDT 2008


Author: kremenek
Date: Mon Apr 14 23:39:08 2008
New Revision: 49709

URL: http://llvm.org/viewvc/llvm-project?rev=49709&view=rev
Log:
Added initial support into the flow-sensitive dataflow solver to visit the Block-level expression
in a block's terminator.  This expression is visited within a block, but it is accessed by the
terminator.  This is important to observe because for live-variables analysis the block-level
expression is live between the terminator and where the expression occurs in the block.  So far
this hasn't been an issue to not observe this because the block-level expression used in the
terminator is always the last one in the block, and we have never queried the liveness information
about this point (but before the terminator).

Modified:
    cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
    cfe/trunk/lib/Analysis/LiveVariables.cpp
    cfe/trunk/lib/Analysis/UninitializedValues.cpp

Modified: cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h?rev=49709&r1=49708&r2=49709&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h (original)
+++ cfe/trunk/include/clang/Analysis/FlowSensitive/DataflowSolver.h Mon Apr 14 23:39:08 2008
@@ -159,7 +159,7 @@
 
     if (I != M.end()) {
       TF.getVal().copyValues(I->second);
-      ProcessBlock(B, recordStmtValues);
+      ProcessBlock(B, recordStmtValues, AnalysisDirTag());
     }
   }
   
@@ -192,7 +192,7 @@
     while (!WorkList.isEmpty()) {
       const CFGBlock* B = WorkList.dequeue();
       ProcessMerge(cfg,B);
-      ProcessBlock(B, recordStmtValues);
+      ProcessBlock(B, recordStmtValues, AnalysisDirTag());
       UpdateEdges(cfg,B,TF.getVal());
     }
   }
@@ -230,11 +230,23 @@
     
     // Set the data for the block.
     D.getBlockDataMap()[B].copyValues(V);
+  }  
+
+  /// ProcessBlock - Process the transfer functions for a given block.
+  void ProcessBlock(const CFGBlock* B, bool recordStmtValues,
+                    dataflow::forward_analysis_tag) {
+    
+    for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I)
+      ProcessStmt(*I, recordStmtValues, AnalysisDirTag());
+    
+    if (Stmt* Term = (Stmt*) B->getTerminator()) TF.VisitTerminator(Term);  
   }
   
+  void ProcessBlock(const CFGBlock* B, bool recordStmtValues,
+                    dataflow::backward_analysis_tag) {
+    
+    if (Stmt* Term = (Stmt*) B->getTerminator()) TF.VisitTerminator(Term);
 
-  /// ProcessBlock - Process the transfer functions for a given block.
-  void ProcessBlock(const CFGBlock* B, bool recordStmtValues) {
     for (StmtItr I=ItrTraits::StmtBegin(B), E=ItrTraits::StmtEnd(B); I!=E;++I)
       ProcessStmt(*I, recordStmtValues, AnalysisDirTag());
   }

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

==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Mon Apr 14 23:39:08 2008
@@ -73,7 +73,8 @@
   void VisitAssign(BinaryOperator* B);
   void VisitDeclStmt(DeclStmt* DS);
   void VisitUnaryOperator(UnaryOperator* U);
-  void Visit(Stmt *S);
+  void Visit(Stmt *S);  
+  void VisitTerminator(Stmt* S); 
 };
       
 void TransferFuncs::Visit(Stmt *S) {
@@ -90,6 +91,23 @@
     // For block-level expressions, mark that they are live.
     LiveState(S,AD) = Alive;
 }
+  
+void TransferFuncs::VisitTerminator(Stmt* S) {
+  return;
+  
+  for (Stmt::child_iterator I = S->child_begin(), E = S->child_end();
+       I != E; ++I) {
+    
+    Stmt* Child = *I;
+    if (!Child) continue;
+    
+    if (getCFG().isBlkExpr(Child)) {
+      LiveState(Child, AD) = Alive;
+      return;  // Only one "condition" expression.
+    }
+  }
+}
+
 
 void TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
   if (VarDecl* V = dyn_cast<VarDecl>(DR->getDecl())) 

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=49709&r1=49708&r2=49709&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Apr 14 23:39:08 2008
@@ -75,6 +75,8 @@
   
   bool Visit(Stmt *S);
   bool BlockStmt_VisitExpr(Expr* E);
+    
+  void VisitTerminator(Stmt* T) { Visit(T); }
   
   BlockVarDecl* FindBlockVarDecl(Stmt* S);
 };





More information about the cfe-commits mailing list