[cfe-commits] r55064 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Environment.h lib/Analysis/Environment.cpp lib/Analysis/GRState.cpp

Ted Kremenek kremenek at apple.com
Wed Aug 20 10:08:30 PDT 2008


Author: kremenek
Date: Wed Aug 20 12:08:29 2008
New Revision: 55064

URL: http://llvm.org/viewvc/llvm-project?rev=55064&view=rev
Log:
Patch by Zhongxing Xu:

This patch moves some code in GRStateManager::RemoveDeadBindings() to EnvironmentManager::RemoveDeadBindings().

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
    cfe/trunk/lib/Analysis/Environment.cpp
    cfe/trunk/lib/Analysis/GRState.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h?rev=55064&r1=55063&r2=55064&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Environment.h Wed Aug 20 12:08:29 2008
@@ -14,6 +14,10 @@
 #ifndef LLVM_CLANG_ANALYSIS_ENVIRONMENT_H
 #define LLVM_CLANG_ANALYSIS_ENVIRONMENT_H
 
+// For using typedefs in StoreManager. Should find a better place for these
+// typedefs.
+#include "clang/Analysis/PathSensitive/Store.h"
+
 #include "llvm/ADT/ImmutableMap.h"
 #include "clang/Analysis/PathSensitive/RValues.h"
 #include "llvm/Support/Allocator.h"
@@ -23,7 +27,8 @@
 
 class EnvironmentManager;
 class BasicValueFactory;
-  
+class LiveVariables;
+
 class Environment : public llvm::FoldingSetNode {
 private:
     
@@ -132,6 +137,12 @@
   
   Environment SetRVal(const Environment& Env, Expr* E, RVal V,
                       bool isBlkExpr, bool Invalidate);
+
+  Environment RemoveDeadBindings(Environment Env, 
+                                 Stmt* Loc,
+                                 const LiveVariables& Liveness,
+                                 StoreManager::DeclRootsTy& DRoots,
+                                 StoreManager::LiveSymbolsTy& LSymbols);
 };
   
 } // end clang namespace

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

==============================================================================
--- cfe/trunk/lib/Analysis/Environment.cpp (original)
+++ cfe/trunk/lib/Analysis/Environment.cpp Wed Aug 20 12:08:29 2008
@@ -12,7 +12,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathSensitive/Environment.h"
+#include "clang/Analysis/Analyses/LiveVariables.h"
 #include "llvm/ADT/ImmutableMap.h"
+#include "llvm/Support/Streams.h"
 
 using namespace clang;
 
@@ -103,3 +105,49 @@
 
   return isBlkExpr ? AddBlkExpr(Env, E, V) : AddSubExpr(Env, E, V);
 }
+
+Environment 
+EnvironmentManager::RemoveDeadBindings(Environment Env, 
+                                       Stmt* Loc,
+                                       const LiveVariables& Liveness,
+                                       StoreManager::DeclRootsTy& DRoots,
+                                       StoreManager::LiveSymbolsTy& LSymbols) {
+  // Drop bindings for subexpressions.
+  Env = RemoveSubExprBindings(Env);
+
+  // Iterate over the block-expr bindings.
+  for (Environment::beb_iterator I = Env.beb_begin(), E = Env.beb_end(); 
+       I != E; ++I) {
+    Expr* BlkExpr = I.getKey();
+
+    if (Liveness.isLive(Loc, BlkExpr)) {
+      RVal X = I.getData();
+
+      // If the block expr's value is the address of some Decl, then mark that
+      // Decl.
+      if (isa<lval::DeclVal>(X)) {
+        lval::DeclVal LV = cast<lval::DeclVal>(X);
+        DRoots.push_back(LV.getDecl());
+      }
+
+      // Mark all symbols in the block expr's value.
+      for (RVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end();
+           SI != SE; ++SI) {
+        LSymbols.insert(*SI);
+      }
+    } else {
+      // The block expr is dead.
+      RVal X = I.getData();
+
+      // Do not misclean LogicalExpr or ConditionalOperator.
+      // Why is it dead? Should look at LiveVariables.
+
+      if (X.isUndef() && cast<UndefinedVal>(X).getData())
+        continue;
+
+      Env = RemoveBlkExpr(Env, BlkExpr);
+    }
+  }
+
+  return Env;
+}

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Wed Aug 20 12:08:29 2008
@@ -88,40 +88,8 @@
   
   GRState NewSt = *St;
 
-  // FIXME: Put this in environment.
-  // Clean up the environment.
-  
-  // Drop bindings for subexpressions.
-  NewSt.Env = EnvMgr.RemoveSubExprBindings(NewSt.Env);
-  
-  // Iterate over the block-expr bindings.
-
-  for (GRState::beb_iterator I = St->beb_begin(), E = St->beb_end();
-                                                    I!=E ; ++I) {    
-    Expr* BlkExpr = I.getKey();
-    
-    if (Liveness.isLive(Loc, BlkExpr)) {
-      RVal X = I.getData();
-      
-      if (isa<lval::DeclVal>(X)) {
-        lval::DeclVal LV = cast<lval::DeclVal>(X);
-        DRoots.push_back(LV.getDecl());
-      }
-      
-      for (RVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end(); 
-                                                        SI != SE; ++SI) {        
-        LSymbols.insert(*SI);
-      }
-    }
-    else {
-      RVal X = I.getData();
-      
-      if (X.isUndef() && cast<UndefinedVal>(X).getData())
-        continue;
-      
-      NewSt.Env = EnvMgr.RemoveBlkExpr(NewSt.Env, BlkExpr);
-    }
-  }
+  NewSt.Env = EnvMgr.RemoveDeadBindings(NewSt.Env, Loc, Liveness, 
+                                        DRoots, LSymbols);
 
   // Clean up the store.
   DSymbols.clear();





More information about the cfe-commits mailing list