]> granicus.if.org Git - clang/commitdiff
analyzer: Introduce a new class, ValueManager, that serves as an aggregate
authorTed Kremenek <kremenek@apple.com>
Thu, 9 Apr 2009 16:13:17 +0000 (16:13 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 9 Apr 2009 16:13:17 +0000 (16:13 +0000)
"manager of symbolic values", wrapping BasicValueFactory, SymbolManager, and
MemRegionManager. While these individual managers nicely separate functionality
in the analyzer, constructing symbolic values can sometimes be cumbersome
because it requires using multiple managers at once. The goal of this class is
to create some factory methods to create SVals that require the use of these
different managers, thus (hopefully) simplifying the analyzer API for clients.

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

include/clang/Analysis/PathSensitive/GRExprEngine.h
include/clang/Analysis/PathSensitive/GRState.h
include/clang/Analysis/PathSensitive/ValueManager.h [new file with mode: 0644]
lib/Analysis/CFRefCount.cpp
lib/Analysis/GRState.cpp

index 56e0e1e531131012cfda2ef9d3e341f51e064a59..9c401bedc2e4ae3fcce88ee0ed187738265ed980 100644 (file)
@@ -457,6 +457,7 @@ public:
     return StateMgr.getConstraintManager();
   }
   
+  // FIXME: Remove when we migrate over to just using ValueManager.
   BasicValueFactory& getBasicVals() {
     return StateMgr.getBasicVals();
   }
@@ -464,6 +465,15 @@ public:
     return StateMgr.getBasicVals();
   }
   
+  ValueManager &getValueManager() {
+    return StateMgr.getValueManager();
+  }
+  
+  const ValueManager &getValueManager() const {
+    return StateMgr.getValueManager();
+  }
+  
+  // FIXME: Remove when we migrate over to just using ValueManager.
   SymbolManager& getSymbolManager() { return SymMgr; }
   const SymbolManager& getSymbolManager() const { return SymMgr; }
   
index c1736116a7a762e2afa705b35d0335a4fae1d76f..aa794175b10bc4cd66ad8c72cd27da2ed1ceb65b 100644 (file)
 #include "clang/Analysis/PathSensitive/Environment.h"
 #include "clang/Analysis/PathSensitive/Store.h"
 #include "clang/Analysis/PathSensitive/ConstraintManager.h"
-#include "clang/Analysis/PathSensitive/MemRegion.h"
-#include "clang/Analysis/PathSensitive/SVals.h"
-#include "clang/Analysis/PathSensitive/BasicValueFactory.h"
+#include "clang/Analysis/PathSensitive/ValueManager.h"
 #include "clang/Analysis/PathSensitive/GRCoreEngine.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
-
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/APSInt.h"
@@ -262,10 +259,7 @@ private:
   llvm::FoldingSet<GRState> StateSet;
 
   /// ValueMgr - Object that manages the data for all created SVals.
-  BasicValueFactory BasicVals;
-
-  /// SymMgr - Object that manages the symbol information.
-  SymbolManager SymMgr;
+  ValueManager ValueMgr;
 
   /// Alloc - A BumpPtrAllocator to allocate states.
   llvm::BumpPtrAllocator& Alloc;
@@ -309,29 +303,55 @@ public:
   : EnvMgr(alloc),
     ISetFactory(alloc),
     GDMFactory(alloc),
-    BasicVals(Ctx, alloc),
-    SymMgr(Ctx, BasicVals, alloc),
+    ValueMgr(alloc, Ctx),
     Alloc(alloc),
     cfg(c),
     codedecl(cd),
     Liveness(L) {
       StoreMgr.reset((*CreateStoreManager)(*this));
       ConstraintMgr.reset((*CreateConstraintManager)(*this));
+      
+      // FIXME: Have ValueMgr own the MemRegionManager, not StoreManager.
+      ValueMgr.setRegionManager(StoreMgr->getRegionManager());
   }
   
   ~GRStateManager();
 
   const GRState* getInitialState();
         
-  ASTContext& getContext() { return BasicVals.getContext(); }
-  const Decl& getCodeDecl() { return codedecl; }
+  ASTContext &getContext() { return ValueMgr.getContext(); }
+  const ASTContext &getContext() const { return ValueMgr.getContext(); }               
+                 
+  const Decl &getCodeDecl() { return codedecl; }
   GRTransferFuncs& getTransferFuncs() { return *TF; }
-  BasicValueFactory& getBasicVals() { return BasicVals; }
-  const BasicValueFactory& getBasicVals() const { return BasicVals; }
-  SymbolManager& getSymbolManager() { return SymMgr; }
+
+  BasicValueFactory &getBasicVals() {
+    return ValueMgr.getBasicValueFactory();
+  }
+  const BasicValueFactory& getBasicVals() const {
+    return ValueMgr.getBasicValueFactory();
+  }
+                 
+  SymbolManager &getSymbolManager() {
+    return ValueMgr.getSymbolManager();
+  }
+  const SymbolManager &getSymbolManager() const {
+    return ValueMgr.getSymbolManager();
+  }
+  
+  ValueManager &getValueManager() { return ValueMgr; }
+  const ValueManager &getValueManager() const { return ValueMgr; }
+  
   LiveVariables& getLiveVariables() { return Liveness; }
   llvm::BumpPtrAllocator& getAllocator() { return Alloc; }
-  MemRegionManager& getRegionManager() { return StoreMgr->getRegionManager(); }
+
+  MemRegionManager& getRegionManager() {
+    return ValueMgr.getRegionManager();
+  }
+  const MemRegionManager& getRegionManager() const {
+    return ValueMgr.getRegionManager();
+  }
+  
   StoreManager& getStoreManager() { return *StoreMgr; }
   ConstraintManager& getConstraintManager() { return *ConstraintMgr; }
 
@@ -406,7 +426,7 @@ public:
   // Methods that query & manipulate the Environment.
   
   SVal GetSVal(const GRState* St, Stmt* Ex) {
-    return St->getEnvironment().GetSVal(Ex, BasicVals);
+    return St->getEnvironment().GetSVal(Ex, getBasicVals());
   }
   
   SVal GetSValAsScalarOrLoc(const GRState* state, const Stmt *S) {
@@ -421,11 +441,11 @@ public:
     
 
   SVal GetSVal(const GRState* St, const Stmt* Ex) {
-    return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), BasicVals);
+    return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), getBasicVals());
   }
   
   SVal GetBlkExprSVal(const GRState* St, Stmt* Ex) {
-    return St->getEnvironment().GetBlkExprSVal(Ex, BasicVals);
+    return St->getEnvironment().GetBlkExprSVal(Ex, getBasicVals());
   }
   
   
diff --git a/include/clang/Analysis/PathSensitive/ValueManager.h b/include/clang/Analysis/PathSensitive/ValueManager.h
new file mode 100644 (file)
index 0000000..b60c86d
--- /dev/null
@@ -0,0 +1,83 @@
+//== ValueManager.h - Aggregate manager of symbols and SVals ----*- C++ -*--==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines ValueManager, a class that manages symbolic values
+//  and SVals created for use by GRExprEngine and related classes.  It
+//  wraps SymbolManager, MemRegionManager, and BasicValueFactory.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_ANALYSIS_AGGREGATE_VALUE_MANAGER_H
+#define LLVM_CLANG_ANALYSIS_AGGREGATE_VALUE_MANAGER_H
+
+#include "clang/Analysis/PathSensitive/MemRegion.h"
+#include "clang/Analysis/PathSensitive/SVals.h"
+#include "clang/Analysis/PathSensitive/BasicValueFactory.h"
+#include "clang/Analysis/PathSensitive/SymbolManager.h"
+
+namespace llvm { class BumpPtrAllocator; }
+namespace clang { class GRStateManager; }
+
+namespace clang {  
+class ValueManager {
+  friend class GRStateManager;
+
+  ASTContext &Context;  
+  BasicValueFactory BasicVals;
+  
+  /// SymMgr - Object that manages the symbol information.
+  SymbolManager SymMgr;
+
+  // FIXME: Eventually ValueManager will own this object.
+  MemRegionManager *MemMgr;
+
+  void setRegionManager(MemRegionManager& mm) { MemMgr = &mm; }
+  
+public:
+  ValueManager(llvm::BumpPtrAllocator &alloc, ASTContext &context)
+               : Context(context), BasicVals(Context, alloc),
+                 SymMgr(Context, BasicVals, alloc),
+                 MemMgr(0) {}
+
+  // Accessors to submanagers.
+  
+  ASTContext &getContext() { return Context; }
+  const ASTContext &getContext() const { return Context; }
+  
+  BasicValueFactory &getBasicValueFactory() { return BasicVals; }
+  const BasicValueFactory &getBasicValueFactory() const { return BasicVals; }
+  
+  SymbolManager &getSymbolManager() { return SymMgr; }
+  const SymbolManager &getSymbolManager() const { return SymMgr; }
+
+  MemRegionManager &getRegionManager() { return *MemMgr; }
+  const MemRegionManager &getRegionManager() const { return *MemMgr; }
+  
+  // Forwarding methods to SymbolManager.
+  
+  const SymbolConjured* getConjuredSymbol(const Stmt* E, QualType T,
+                                          unsigned VisitCount,
+                                          const void* SymbolTag = 0) {
+    return SymMgr.getConjuredSymbol(E, T, VisitCount, SymbolTag);
+  }
+  
+  const SymbolConjured* getConjuredSymbol(const Expr* E, unsigned VisitCount,
+                                          const void* SymbolTag = 0) {    
+    return SymMgr.getConjuredSymbol(E, VisitCount, SymbolTag);
+  }
+  
+  // Aggregation methods that use multiple submanagers.
+  
+  Loc makeRegionVal(SymbolRef Sym) {
+    return Loc::MakeVal(MemMgr->getSymbolicRegion(Sym));
+  }
+};
+} // end clang namespace
+#endif
+
index 482662c19e16b52d9b6c030cecb4942f3e72f498..267fc0be1a204cfd38c8a006ad50275ca680edc5 100644 (file)
@@ -1884,14 +1884,12 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
     case RetEffect::OwnedAllocatedSymbol:
     case RetEffect::OwnedSymbol: {
       unsigned Count = Builder.getCurrentBlockCount();
-      SymbolRef Sym = Eng.getSymbolManager().getConjuredSymbol(Ex, Count);
-      QualType RetT = GetReturnType(Ex, Eng.getContext());      
-      state =
-        state.set<RefBindings>(Sym, RefVal::makeOwned(RE.getObjKind(), RetT));
-      MemRegionManager& MRMgr = Eng.getStoreManager().getRegionManager();
-      state = state.BindExpr(Ex, Loc::MakeVal(MRMgr.getSymbolicRegion(Sym)), 
-                             false);
-
+      ValueManager &ValMgr = Eng.getValueManager();      
+      SymbolRef Sym = ValMgr.getConjuredSymbol(Ex, Count);
+      QualType RetT = GetReturnType(Ex, ValMgr.getContext());      
+      state = state.set<RefBindings>(Sym, RefVal::makeOwned(RE.getObjKind(),
+                                                            RetT));
+      state = state.BindExpr(Ex, ValMgr.makeRegionVal(Sym), false);
 
       // FIXME: Add a flag to the checker where allocations are assumed to
       // *not fail.
@@ -1908,14 +1906,12 @@ void CFRefCount::EvalSummary(ExplodedNodeSet<GRState>& Dst,
       
     case RetEffect::NotOwnedSymbol: {
       unsigned Count = Builder.getCurrentBlockCount();
-      SymbolRef Sym = Eng.getSymbolManager().getConjuredSymbol(Ex, Count);
-      QualType RetT = GetReturnType(Ex, Eng.getContext());
-      
-      state =
-        state.set<RefBindings>(Sym, RefVal::makeNotOwned(RE.getObjKind(),RetT));
-      MemRegionManager& MRMgr = Eng.getStoreManager().getRegionManager();
-      state = state.BindExpr(Ex, Loc::MakeVal(MRMgr.getSymbolicRegion(Sym)), 
-                             false);
+      ValueManager &ValMgr = Eng.getValueManager();
+      SymbolRef Sym = ValMgr.getConjuredSymbol(Ex, Count);
+      QualType RetT = GetReturnType(Ex, ValMgr.getContext());      
+      state = state.set<RefBindings>(Sym, RefVal::makeNotOwned(RE.getObjKind(),
+                                                               RetT));
+      state = state.BindExpr(Ex, ValMgr.makeRegionVal(Sym), false);
       break;
     }
   }
index 82cb1f24c41dace1074e5fa2c2bbb94efbe21f10..e0e478c30717a7a84923b575ffd8a993e56448c9 100644 (file)
@@ -308,7 +308,7 @@ bool GRStateManager::isEqual(const GRState* state, Expr* Ex,
 }
   
 bool GRStateManager::isEqual(const GRState* state, Expr* Ex, uint64_t x) {
-  return isEqual(state, Ex, BasicVals.getValue(x, Ex->getType()));
+  return isEqual(state, Ex, getBasicVals().getValue(x, Ex->getType()));
 }
 
 //===----------------------------------------------------------------------===//