diff --git a/include/MSSA/SVFG.h b/include/MSSA/SVFG.h index 55e56aeef..88bfb5d0c 100644 --- a/include/MSSA/SVFG.h +++ b/include/MSSA/SVFG.h @@ -105,7 +105,7 @@ class SVFG : public GenericSVFGGraphTy { StorePEToSVFGNodeMap storePEToSVFGNodeMap; ///< map store inst to store SVFGNode SVFGStat * stat; SVFGK kind; - MemSSA* mssa; + std::unique_ptr mssa; PointerAnalysis* pta; /// Clean up memory @@ -115,7 +115,7 @@ class SVFG : public GenericSVFGGraphTy { SVFG(SVFGK k = ORIGSVFGK); /// Start building SVFG - virtual void buildSVFG(MemSSA* m); + virtual void buildSVFG(std::unique_ptr m); public: /// Destructor @@ -133,9 +133,13 @@ class SVFG : public GenericSVFGGraphTy { return PAG::getPAG(); } + inline MemSSA* getMSSA() { + return mssa.get(); + }; + /// Clear MSSA inline void clearMSSA() { - mssa = NULL; + mssa.reset(); } /// Get SVFG kind diff --git a/include/MSSA/SVFGBuilder.h b/include/MSSA/SVFGBuilder.h index c28935f76..dbfa271ef 100644 --- a/include/MSSA/SVFGBuilder.h +++ b/include/MSSA/SVFGBuilder.h @@ -95,7 +95,7 @@ class SVFGBuilder { /// We start from here virtual bool build(SVFG* graph,BVDataPTAImpl* pta); /// Can be rewritten by subclasses - virtual void createSVFG(MemSSA* mssa, SVFG* graph); + virtual void createSVFG(std::unique_ptr mssa, SVFG* graph); /// Release global SVFG virtual void releaseMemory(SVFG* graph); /// Update call graph using pre-analysis points-to results diff --git a/include/MSSA/SVFGOPT.h b/include/MSSA/SVFGOPT.h index 28a1df4f2..34ed28517 100644 --- a/include/MSSA/SVFGOPT.h +++ b/include/MSSA/SVFGOPT.h @@ -81,8 +81,8 @@ class SVFGOPT : public SVFG { return g->getKind() == OPTSVFGK; } protected: - virtual inline void buildSVFG(MemSSA* m) { - SVFG::buildSVFG(m); + virtual inline void buildSVFG(std::unique_ptr m) { + SVFG::buildSVFG(std::move(m)); dump("SVFG_before_opt"); diff --git a/include/SABER/SaberSVFGBuilder.h b/include/SABER/SaberSVFGBuilder.h index 5db948e42..c9a6816e6 100644 --- a/include/SABER/SaberSVFGBuilder.h +++ b/include/SABER/SaberSVFGBuilder.h @@ -55,7 +55,7 @@ class SaberSVFGBuilder : public SVFGBuilder { } protected: /// Re-write create SVFG method - virtual void createSVFG(MemSSA* mssa, SVFG* graph); + virtual void createSVFG(std::unique_ptr mssa, SVFG* graph); private: /// Remove direct value-flow edge to a dereference point for Saber source-sink memory error detection diff --git a/lib/MSSA/SVFG.cpp b/lib/MSSA/SVFG.cpp index aba4e5187..6da6544ab 100644 --- a/lib/MSSA/SVFG.cpp +++ b/lib/MSSA/SVFG.cpp @@ -43,7 +43,7 @@ static cl::opt DumpVFG("dump-svfg", cl::init(false), /*! * Constructor */ -SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),mssa(NULL),pta(NULL) { +SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),pta(NULL) { stat = new SVFGStat(this); } @@ -53,7 +53,7 @@ SVFG::SVFG(SVFGK k): totalSVFGNode(0), kind(k),mssa(NULL),pta(NULL) { void SVFG::destroy() { delete stat; stat = NULL; - mssa = NULL; + mssa.reset(); pta = NULL; } @@ -66,9 +66,9 @@ void SVFG::destroy() { * a) between two statements (PAGEdges) * b) between two memory SSA operators (MSSAPHI MSSAMU and MSSACHI) */ -void SVFG::buildSVFG(MemSSA* m) { - mssa = m; - pta = m->getPTA(); +void SVFG::buildSVFG(std::unique_ptr m) { + mssa = std::move(m); + pta = mssa->getPTA(); stat->startClk(); DBOUT(DGENERAL, outs() << pasMsg("\tCreate SVFG Top Level Node\n")); diff --git a/lib/MSSA/SVFGBuilder.cpp b/lib/MSSA/SVFGBuilder.cpp index 7ea07753e..d89903f3f 100644 --- a/lib/MSSA/SVFGBuilder.cpp +++ b/lib/MSSA/SVFGBuilder.cpp @@ -45,10 +45,10 @@ SVFGOPT* SVFGBuilder::globalSvfg = NULL; /*! * Create SVFG */ -void SVFGBuilder::createSVFG(MemSSA* mssa, SVFG* graph) { +void SVFGBuilder::createSVFG(std::unique_ptr mssa, SVFG* graph) { svfg = graph; - svfg->buildSVFG(mssa); - if(mssa->getPTA()->printStat()) + svfg->buildSVFG(std::move(mssa)); + if(svfg->getMSSA()->getPTA()->printStat()) svfg->performStat(); svfg->dump("FS_SVFG"); } @@ -85,7 +85,7 @@ void SVFGBuilder::releaseMemory(SVFG* vfg) { */ bool SVFGBuilder::build(SVFG* graph,BVDataPTAImpl* pta) { - MemSSA mssa(pta); + auto mssa = llvm::make_unique(pta); DBOUT(DGENERAL, outs() << pasMsg("Build Memory SSA \n")); @@ -102,20 +102,22 @@ bool SVFGBuilder::build(SVFG* graph,BVDataPTAImpl* pta) { dt.recalculate(fun); df.runOnDT(dt); - mssa.buildMemSSA(fun, &df, &dt); + mssa->buildMemSSA(fun, &df, &dt); } - mssa.performStat(); - mssa.dumpMSSA(); + mssa->performStat(); + mssa->dumpMSSA(); DBOUT(DGENERAL, outs() << pasMsg("Build Sparse Value-Flow Graph \n")); - createSVFG(&mssa, graph); + createSVFG(std::move(mssa), graph); if(SVFGWithIndirectCall || SVFGWithIndCall) - updateCallGraph(mssa.getPTA()); + updateCallGraph(graph->getMSSA()->getPTA()); - releaseMemory(graph); + // Graph will release mssa either on request or + // when it itself is deleted. + // releaseMemory(graph); return false; } diff --git a/lib/SABER/SaberSVFGBuilder.cpp b/lib/SABER/SaberSVFGBuilder.cpp index a96214aaa..cd3ef5063 100644 --- a/lib/SABER/SaberSVFGBuilder.cpp +++ b/lib/SABER/SaberSVFGBuilder.cpp @@ -34,11 +34,11 @@ using namespace llvm; using namespace analysisUtil; -void SaberSVFGBuilder::createSVFG(MemSSA* mssa, SVFG* graph) { +void SaberSVFGBuilder::createSVFG(std::unique_ptr mssa, SVFG* graph) { svfg = graph; - svfg->buildSVFG(mssa); - BVDataPTAImpl* pta = mssa->getPTA(); + svfg->buildSVFG(std::move(mssa)); + BVDataPTAImpl* pta = svfg->getMSSA()->getPTA(); DBOUT(DGENERAL, outs() << pasMsg("\tCollect Global Variables\n")); collectGlobals(pta); diff --git a/lib/WPA/WPAPass.cpp b/lib/WPA/WPAPass.cpp index 0dd13d1aa..1d560195b 100644 --- a/lib/WPA/WPAPass.cpp +++ b/lib/WPA/WPAPass.cpp @@ -129,7 +129,7 @@ void WPAPass::runPointerAnalysis(llvm::Module& module, u32_t kind) if (anderSVFG) { SVFGBuilder memSSA(true); SVFG *svfg = memSSA.buildSVFG((BVDataPTAImpl*)_pta); - svfg->dump("ander_svfg", true /* simple */); + svfg->dump("ander_svfg"); } }