Use std:unique_ptr instead of raw pointers in theory/bv. (#2385)
authorMathias Preiner <mathias.preiner@gmail.com>
Mon, 27 Aug 2018 23:19:34 +0000 (16:19 -0700)
committerAndres Noetzli <andres.noetzli@gmail.com>
Mon, 27 Aug 2018 23:19:34 +0000 (16:19 -0700)
This should also fix CIDs 146568714656951465696, and 1465701.

src/theory/bv/bv_quick_check.cpp
src/theory/bv/bv_quick_check.h
src/theory/bv/bv_subtheory_algebraic.cpp
src/theory/bv/bv_subtheory_algebraic.h
src/theory/bv/bv_subtheory_bitblast.cpp
src/theory/bv/bv_subtheory_bitblast.h
src/theory/bv/bv_subtheory_core.cpp
src/theory/bv/bv_subtheory_core.h
src/theory/bv/theory_bv.cpp
src/theory/bv/theory_bv.h

index cc007bef44ed67b785a1b3b21c9febd360c351de..d81300b84148ecd2ec1746ff612b5aab2110ff18 100644 (file)
@@ -145,7 +145,6 @@ bool BVQuickCheck::collectModelInfo(theory::TheoryModel* model, bool fullModel)
 
 BVQuickCheck::~BVQuickCheck() {
   clearSolver();
-  delete d_bitblaster;
 }
 
 QuickXPlain::QuickXPlain(const std::string& name, BVQuickCheck* solver, unsigned long budget)
index ec4eb9f4f983e5630f36d84a91bba9623e82a58b..b2c31edcbab4678dafa3e10e67f2bfba7deb7747 100644 (file)
@@ -40,7 +40,7 @@ class TheoryBV;
 
 class BVQuickCheck {
   context::Context d_ctx;
-  TLazyBitblaster* d_bitblaster;
+  std::unique_ptr<TLazyBitblaster> d_bitblaster;
   Node d_conflict;
   context::CDO<bool> d_inConflict;
   void setConflict();
index 0150264fd48b15535db85f14a6bbbdfefefdf36f..df7ba29b5cc06e52654e65921c5ac5f08ac376ba 100644 (file)
@@ -228,30 +228,28 @@ void SubstitutionEx::storeCache(TNode from, TNode to, Node reason) {
 }
 
 AlgebraicSolver::AlgebraicSolver(context::Context* c, TheoryBV* bv)
-  : SubtheorySolver(c, bv)
-  , d_modelMap(NULL)
-  , d_quickSolver(new BVQuickCheck("theory::bv::algebraic", bv))
-  , d_isComplete(c, false)
-  , d_isDifficult(c, false)
-  , d_budget(options::bitvectorAlgebraicBudget())
-  , d_explanations()
-  , d_inputAssertions()
-  , d_ids()
-  , d_numSolved(0)
-  , d_numCalls(0)
-  , d_ctx(new context::Context())
-  , d_quickXplain(options::bitvectorQuickXplain() ? new QuickXPlain("theory::bv::algebraic", d_quickSolver) : NULL)
-  , d_statistics()
-{}
-
-AlgebraicSolver::~AlgebraicSolver() {
-  if(d_modelMap != NULL) { delete d_modelMap; }
-  delete d_quickXplain;
-  delete d_quickSolver;
-  delete d_ctx;
+    : SubtheorySolver(c, bv),
+      d_modelMap(),
+      d_quickSolver(new BVQuickCheck("theory::bv::algebraic", bv)),
+      d_isComplete(c, false),
+      d_isDifficult(c, false),
+      d_budget(options::bitvectorAlgebraicBudget()),
+      d_explanations(),
+      d_inputAssertions(),
+      d_ids(),
+      d_numSolved(0),
+      d_numCalls(0),
+      d_quickXplain(),
+      d_statistics()
+{
+  if (options::bitvectorQuickXplain())
+  {
+    d_quickXplain.reset(
+        new QuickXPlain("theory::bv::algebraic", d_quickSolver.get()));
+  }
 }
 
-
+AlgebraicSolver::~AlgebraicSolver() {}
 
 bool AlgebraicSolver::check(Theory::Effort e)
 {
@@ -298,16 +296,15 @@ bool AlgebraicSolver::check(Theory::Effort e)
 
   Assert (d_explanations.size() == worklist.size());
 
-  delete d_modelMap;
-  d_modelMap = new SubstitutionMap(d_context);
-  SubstitutionEx subst(d_modelMap);
+  d_modelMap.reset(new SubstitutionMap(d_context));
+  SubstitutionEx subst(d_modelMap.get());
 
   // first round of substitutions
   processAssertions(worklist, subst);
 
   if (!d_isDifficult.get()) {
     // skolemize all possible extracts
-    ExtractSkolemizer skolemizer(d_modelMap);
+    ExtractSkolemizer skolemizer(d_modelMap.get());
     skolemizer.skolemize(worklist);
     // second round of substitutions
     processAssertions(worklist, subst);
index 09d958f258bf76541bb192445a30d0e032b96261..42f5faa7c88149876347a953c0e7dd7081ff657a 100644 (file)
@@ -169,8 +169,8 @@ class AlgebraicSolver : public SubtheorySolver {
     ~Statistics();
   };
 
-  SubstitutionMap* d_modelMap;
-  BVQuickCheck* d_quickSolver;
+  std::unique_ptr<SubstitutionMap> d_modelMap;
+  std::unique_ptr<BVQuickCheck> d_quickSolver;
   context::CDO<bool> d_isComplete; 
   context::CDO<bool> d_isDifficult; /**< flag to indicate whether the current assertions contain expensive BV operators */
   
@@ -181,9 +181,9 @@ class AlgebraicSolver : public SubtheorySolver {
   uint64_t d_numSolved;
   uint64_t d_numCalls;
 
-  context::Context* d_ctx;
-  QuickXPlain* d_quickXplain;   /**< separate quickXplain module as it can reuse the current SAT solver */
-  
+  /** separate quickXplain module as it can reuse the current SAT solver */
+  std::unique_ptr<QuickXPlain> d_quickXplain;
+
   Statistics d_statistics;
   bool useHeuristic();
   void setConflict(TNode conflict);
index cdbf2f955450ffb0186dae3ea83b1bfccb63cf6c..ea2f8e4bfb2ebd6d1fb48474efd67f0779aab412 100644 (file)
@@ -35,24 +35,25 @@ namespace theory {
 namespace bv {
 
 BitblastSolver::BitblastSolver(context::Context* c, TheoryBV* bv)
-  : SubtheorySolver(c, bv),
-    d_bitblaster(new TLazyBitblaster(c, bv, "theory::bv::lazy")),
-    d_bitblastQueue(c),
-    d_statistics(),
-    d_validModelCache(c, true),
-    d_lemmaAtomsQueue(c),
-    d_useSatPropagation(options::bitvectorPropagate()),
-    d_abstractionModule(NULL),
-    d_quickCheck(options::bitvectorQuickXplain() ? new BVQuickCheck("bb", bv) : NULL),
-    d_quickXplain(options::bitvectorQuickXplain() ? new QuickXPlain("bb", d_quickCheck) :  NULL)
+    : SubtheorySolver(c, bv),
+      d_bitblaster(new TLazyBitblaster(c, bv, "theory::bv::lazy")),
+      d_bitblastQueue(c),
+      d_statistics(),
+      d_validModelCache(c, true),
+      d_lemmaAtomsQueue(c),
+      d_useSatPropagation(options::bitvectorPropagate()),
+      d_abstractionModule(NULL),
+      d_quickCheck(),
+      d_quickXplain()
 {
+  if (options::bitvectorQuickXplain())
+  {
+    d_quickCheck.reset(new BVQuickCheck("bb", bv));
+    d_quickXplain.reset(new QuickXPlain("bb", d_quickCheck.get()));
+  }
 }
 
-BitblastSolver::~BitblastSolver() {
-  delete d_quickXplain;
-  delete d_quickCheck;
-  delete d_bitblaster;
-}
+BitblastSolver::~BitblastSolver() {}
 
 BitblastSolver::Statistics::Statistics()
   : d_numCallstoCheck("theory::bv::BitblastSolver::NumCallsToCheck", 0)
@@ -278,7 +279,7 @@ void BitblastSolver::setConflict(TNode conflict) {
 
 void BitblastSolver::setProofLog( BitVectorProof * bvp ) {
   d_bitblaster->setProofLog( bvp );
-  bvp->setBitblaster(d_bitblaster);
+  bvp->setBitblaster(d_bitblaster.get());
 }
 
 }/* namespace CVC4::theory::bv */
index 350baae41492050a1b94aafd06de4f61df7f0d4a..ac0d38815ee3bb4c0dc5fed8bc356e56550ecddb 100644 (file)
@@ -42,7 +42,7 @@ class BitblastSolver : public SubtheorySolver {
     ~Statistics();
   };
   /** Bitblaster */
-  TLazyBitblaster* d_bitblaster;
+  std::unique_ptr<TLazyBitblaster> d_bitblaster;
 
   /** Nodes that still need to be bit-blasted */
   context::CDQueue<TNode> d_bitblastQueue;
@@ -56,8 +56,8 @@ class BitblastSolver : public SubtheorySolver {
   context::CDQueue<TNode> d_lemmaAtomsQueue;
   bool  d_useSatPropagation;
   AbstractionModule* d_abstractionModule;
-  BVQuickCheck* d_quickCheck;
-  QuickXPlain* d_quickXplain;
+  std::unique_ptr<BVQuickCheck> d_quickCheck;
+  std::unique_ptr<QuickXPlain> d_quickXplain;
   //  Node getModelValueRec(TNode node);
   void setConflict(TNode conflict);
 public:
index b3c3f73f3fcb793826f9c7c520fab0ea3587a35a..9285141a0b3251a59d241cd2999aee4a9212eee1 100644 (file)
@@ -79,9 +79,8 @@ CoreSolver::CoreSolver(context::Context* c, TheoryBV* bv)
   d_equalityEngine.addFunctionKind(kind::INT_TO_BITVECTOR);
 }
 
-CoreSolver::~CoreSolver() {
-  delete d_slicer;
-}
+CoreSolver::~CoreSolver() {}
+
 void CoreSolver::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   d_equalityEngine.setMasterEqualityEngine(eq);
 }
index 2ef18e613a37f13fc4196182af7534aed30a5843..ce570d5312a98a7ca2f25858a7a567b2fc703db3 100644 (file)
@@ -82,7 +82,7 @@ class CoreSolver : public SubtheorySolver {
   /** new equivalence class */
   void eqNotifyNewClass(TNode t);
 
-  Slicer* d_slicer;
+  std::unique_ptr<Slicer> d_slicer;
   context::CDO<bool> d_isComplete;
   unsigned d_lemmaThreshold;
   
index 1b7eeddac93fdc523a5f9935b3ece6e3e6ea4e3d..d08405ef313b00aa4cc37cc790228639da782157 100644 (file)
@@ -44,79 +44,72 @@ namespace CVC4 {
 namespace theory {
 namespace bv {
 
-TheoryBV::TheoryBV(context::Context* c, context::UserContext* u,
-                   OutputChannel& out, Valuation valuation,
-                   const LogicInfo& logicInfo, std::string name)
-  : Theory(THEORY_BV, c, u, out, valuation, logicInfo, name),
-    d_context(c),
-    d_alreadyPropagatedSet(c),
-    d_sharedTermsSet(c),
-    d_subtheories(),
-    d_subtheoryMap(),
-    d_statistics(),
-    d_staticLearnCache(),
-    d_BVDivByZero(),
-    d_BVRemByZero(),
-    d_lemmasAdded(c, false),
-    d_conflict(c, false),
-    d_invalidateModelCache(c, true),
-    d_literalsToPropagate(c),
-    d_literalsToPropagateIndex(c, 0),
-    d_propagatedBy(c),
-    d_eagerSolver(NULL),
-    d_abstractionModule(new AbstractionModule(getStatsPrefix(THEORY_BV))),
-    d_isCoreTheory(false),
-    d_calledPreregister(false),
-    d_needsLastCallCheck(false),
-    d_extf_range_infer(u),
-    d_extf_collapse_infer(u)
+TheoryBV::TheoryBV(context::Context* c,
+                   context::UserContext* u,
+                   OutputChannel& out,
+                   Valuation valuation,
+                   const LogicInfo& logicInfo,
+                   std::string name)
+    : Theory(THEORY_BV, c, u, out, valuation, logicInfo, name),
+      d_context(c),
+      d_alreadyPropagatedSet(c),
+      d_sharedTermsSet(c),
+      d_subtheories(),
+      d_subtheoryMap(),
+      d_statistics(),
+      d_staticLearnCache(),
+      d_BVDivByZero(),
+      d_BVRemByZero(),
+      d_lemmasAdded(c, false),
+      d_conflict(c, false),
+      d_invalidateModelCache(c, true),
+      d_literalsToPropagate(c),
+      d_literalsToPropagateIndex(c, 0),
+      d_propagatedBy(c),
+      d_eagerSolver(),
+      d_abstractionModule(new AbstractionModule(getStatsPrefix(THEORY_BV))),
+      d_isCoreTheory(false),
+      d_calledPreregister(false),
+      d_needsLastCallCheck(false),
+      d_extf_range_infer(u),
+      d_extf_collapse_infer(u)
 {
   setupExtTheory();
   getExtTheory()->addFunctionKind(kind::BITVECTOR_TO_NAT);
   getExtTheory()->addFunctionKind(kind::INT_TO_BITVECTOR);
   if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER) {
-    d_eagerSolver = new EagerBitblastSolver(c, this);
+    d_eagerSolver.reset(new EagerBitblastSolver(c, this));
     return;
   }
 
   if (options::bitvectorEqualitySolver() && !options::proof())
   {
-    SubtheorySolver* core_solver = new CoreSolver(c, this);
-    d_subtheories.push_back(core_solver);
-    d_subtheoryMap[SUB_CORE] = core_solver;
+    d_subtheories.emplace_back(new CoreSolver(c, this));
+    d_subtheoryMap[SUB_CORE] = d_subtheories.back().get();
   }
 
   if (options::bitvectorInequalitySolver() && !options::proof())
   {
-    SubtheorySolver* ineq_solver = new InequalitySolver(c, u, this);
-    d_subtheories.push_back(ineq_solver);
-    d_subtheoryMap[SUB_INEQUALITY] = ineq_solver;
+    d_subtheories.emplace_back(new InequalitySolver(c, u, this));
+    d_subtheoryMap[SUB_INEQUALITY] = d_subtheories.back().get();
   }
 
   if (options::bitvectorAlgebraicSolver() && !options::proof())
   {
-    SubtheorySolver* alg_solver = new AlgebraicSolver(c, this);
-    d_subtheories.push_back(alg_solver);
-    d_subtheoryMap[SUB_ALGEBRAIC] = alg_solver;
+    d_subtheories.emplace_back(new AlgebraicSolver(c, this));
+    d_subtheoryMap[SUB_ALGEBRAIC] = d_subtheories.back().get();
   }
 
   BitblastSolver* bb_solver = new BitblastSolver(c, this);
-  if (options::bvAbstraction()) {
-    bb_solver->setAbstraction(d_abstractionModule);
+  if (options::bvAbstraction())
+  {
+    bb_solver->setAbstraction(d_abstractionModule.get());
   }
-  d_subtheories.push_back(bb_solver);
+  d_subtheories.emplace_back(bb_solver);
   d_subtheoryMap[SUB_BITBLAST] = bb_solver;
 }
 
-TheoryBV::~TheoryBV() {
-  if (d_eagerSolver) {
-    delete d_eagerSolver;
-  }
-  for (unsigned i = 0; i < d_subtheories.size(); ++i) {
-    delete d_subtheories[i];
-  }
-  delete d_abstractionModule;
-}
+TheoryBV::~TheoryBV() {}
 
 void TheoryBV::setMasterEqualityEngine(eq::EqualityEngine* eq) {
   if (options::bitblastMode() == theory::bv::BITBLAST_MODE_EAGER) {
index 05bb695e549b66544ea1384b012440dd7bb67a0a..d5e3ad02efb0af59f48f611b8ee037c696ab539c 100644 (file)
@@ -53,7 +53,7 @@ class TheoryBV : public Theory {
   context::CDHashSet<Node, NodeHashFunction> d_alreadyPropagatedSet;
   context::CDHashSet<Node, NodeHashFunction> d_sharedTermsSet;
 
-  std::vector<SubtheorySolver*> d_subtheories;
+  std::vector<std::unique_ptr<SubtheorySolver>> d_subtheories;
   std::unordered_map<SubTheory, SubtheorySolver*, std::hash<int> > d_subtheoryMap;
 
 public:
@@ -172,8 +172,8 @@ private:
   typedef context::CDHashMap<Node, SubTheory, NodeHashFunction> PropagatedMap;
   PropagatedMap d_propagatedBy;
 
-  EagerBitblastSolver* d_eagerSolver;
-  AbstractionModule* d_abstractionModule;
+  std::unique_ptr<EagerBitblastSolver> d_eagerSolver;
+  std::unique_ptr<AbstractionModule> d_abstractionModule;
   bool d_isCoreTheory;
   bool d_calledPreregister;