From b8747ac15dc7489d69479c309acec05be018b2f1 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 16 Oct 2024 17:24:22 +1100 Subject: [PATCH 01/45] copy all fields of SVFFunction into CallGraphNode (cherry picked from commit 94a899a3de687447b7c332355de717ac43e0368d) (cherry picked from commit 82daf5b459c0d5e3e5918c0c2f169b642d883d20) --- svf/include/Graphs/CallGraph.h | 196 ++++++++++++++++++++++++++++++++- svf/include/SVFIR/SVFValue.h | 6 +- svf/lib/Graphs/CallGraph.cpp | 21 +++- 3 files changed, 220 insertions(+), 3 deletions(-) diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 25e6683b8..2785fd423 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -113,15 +113,209 @@ class CallGraphEdge : public GenericCallGraphEdgeTy typedef GenericNode GenericCallGraphNodeTy; class CallGraphNode : public GenericCallGraphNodeTy { + +public: + typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; + typedef CallGraphEdge::CallGraphEdgeSet::iterator iterator; + typedef CallGraphEdge::CallGraphEdgeSet::const_iterator const_iterator; + typedef SVFLoopAndDomInfo::BBSet BBSet; + typedef SVFLoopAndDomInfo::BBList BBList; + typedef SVFLoopAndDomInfo::LoopBBs LoopBBs; + typedef std::vector::const_iterator bb_const_iterator; + private: const SVFFunction* fun; + bool isDecl; /// return true if this function does not have a body + bool intrinsic; /// return true if this function is an intrinsic function (e.g., llvm.dbg), which does not reside in the application code + bool addrTaken; /// return true if this function is address-taken (for indirect call purposes) + bool isUncalled; /// return true if this function is never called + bool isNotRet; /// return true if this function never returns + bool varArg; /// return true if this function supports variable arguments + const SVFFunctionType* funcType; /// FunctionType, which is different from the type (PointerType) of this SVFFunction + SVFLoopAndDomInfo* loopAndDom; /// the loop and dominate information + const SVFFunction* realDefFun; /// the definition of a function across multiple modules + std::vector allBBs; /// all BasicBlocks of this function + std::vector allArgs; /// all formal arguments of this function + const SVFBasicBlock *exitBlock; /// a 'single' basic block having no successors and containing return instruction in a function public: /// Constructor - CallGraphNode(NodeID i, const SVFFunction* f) : GenericCallGraphNodeTy(i,CallNodeKd), fun(f) + CallGraphNode(NodeID i, const SVFFunction* f); + + + inline bool isDeclaration() const + { + return isDecl; + } + + inline bool isIntrinsic() const + { + return intrinsic; + } + + inline bool hasAddressTaken() const + { + return addrTaken; + } + + inline bool isVarArg() const + { + return varArg; + } + + inline bool isUncalledFunction() const + { + return isUncalled; + } + + inline bool hasReturn() const + { + return !isNotRet; + } + + /// Returns the FunctionType + inline const SVFFunctionType* getFunctionType() const + { + return funcType; + } + + /// Returns the FunctionType + inline const SVFType* getReturnType() const + { + return funcType->getReturnType(); + } + + inline SVFLoopAndDomInfo* getLoopAndDomInfo() + { + return loopAndDom; + } + + inline const std::vector& getReachableBBs() const + { + return loopAndDom->getReachableBBs(); + } + + inline void getExitBlocksOfLoop(const SVFBasicBlock* bb, BBList& exitbbs) const + { + return loopAndDom->getExitBlocksOfLoop(bb,exitbbs); + } + + inline bool hasLoopInfo(const SVFBasicBlock* bb) const + { + return loopAndDom->hasLoopInfo(bb); + } + + const LoopBBs& getLoopInfo(const SVFBasicBlock* bb) const + { + return loopAndDom->getLoopInfo(bb); + } + + inline const SVFBasicBlock* getLoopHeader(const BBList& lp) const + { + return loopAndDom->getLoopHeader(lp); + } + + inline bool loopContainsBB(const BBList& lp, const SVFBasicBlock* bb) const + { + return loopAndDom->loopContainsBB(lp,bb); + } + + inline const Map& getDomTreeMap() const { + return loopAndDom->getDomTreeMap(); } + inline const Map& getDomFrontierMap() const + { + return loopAndDom->getDomFrontierMap(); + } + + inline bool isLoopHeader(const SVFBasicBlock* bb) const + { + return loopAndDom->isLoopHeader(bb); + } + + inline bool dominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const + { + return loopAndDom->dominate(bbKey,bbValue); + } + + inline bool postDominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const + { + return loopAndDom->postDominate(bbKey,bbValue); + } + + inline const SVFFunction* getDefFunForMultipleModule() const + { + if(realDefFun==nullptr) + return this->fun; + return realDefFun; + } + + inline bool hasBasicBlock() const + { + return !allBBs.empty(); + } + + inline const SVFBasicBlock* getEntryBlock() const + { + assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); + return allBBs.front(); + } + + inline const SVFBasicBlock* back() const + { + assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); + /// Carefully! 'back' is just the last basic block of function, + /// but not necessarily a exit basic block + /// more refer to: https://github.com/SVF-tools/SVF/pull/1262 + return allBBs.back(); + } + + inline bb_const_iterator begin() const + { + return allBBs.begin(); + } + + inline bb_const_iterator end() const + { + return allBBs.end(); + } + + inline const std::vector& getBasicBlockList() const + { + return allBBs; + } + + inline const SVFBasicBlock* getExitBB() const + { + assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); + assert(exitBlock && "must have an exitBlock"); + return exitBlock; + } + + inline void setExitBlock(SVFBasicBlock *bb) + { + assert(!exitBlock && "have already set exit Basicblock!"); + exitBlock = bb; + } + + + u32_t inline arg_size() const + { + return allArgs.size(); + } + + inline const SVFArgument* getArg(u32_t idx) const + { + assert (idx < allArgs.size() && "getArg() out of range!"); + return allArgs[idx]; + } + + + + + inline const std::string &getName() const { return fun->getName(); diff --git a/svf/include/SVFIR/SVFValue.h b/svf/include/SVFIR/SVFValue.h index 04559ebf6..c14940aef 100644 --- a/svf/include/SVFIR/SVFValue.h +++ b/svf/include/SVFIR/SVFValue.h @@ -367,7 +367,7 @@ class SVFFunction : public SVFValue return node->getKind() == SVFFunc; } - inline SVFLoopAndDomInfo* getLoopAndDomInfo() + inline SVFLoopAndDomInfo* getLoopAndDomInfo() const { return loopAndDom; } @@ -408,6 +408,10 @@ class SVFFunction : public SVFValue u32_t arg_size() const; const SVFArgument* getArg(u32_t idx) const; bool isVarArg() const; + inline const std::vector& getArgsList() const + { + return allArgs; + } inline bool hasBasicBlock() const { diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 00ca4d54e..49299a8ca 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -57,6 +57,25 @@ const std::string CallGraphEdge::toString() const return rawstr.str(); } +CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNodeTy(i,CallNodeKd), fun(f) +{ + isUncalled = f->isUncalledFunction(); + isNotRet = !(f->hasReturn()); + isDecl = f->isDeclaration(); + intrinsic = f->isIntrinsic(); + addrTaken = f->hasAddressTaken(); + varArg = f->isVarArg(); + funcType = f->getFunctionType(); + loopAndDom = f->getLoopAndDomInfo(); + realDefFun = f->getDefFunForMultipleModule(); + allBBs = f->getBasicBlockList(); + allArgs = f->getArgsList(); + if (f->hasBasicBlock()) + exitBlock = f->getExitBB(); +} + + + const std::string CallGraphNode::toString() const { std::string str; @@ -86,7 +105,7 @@ void CallGraph::destroy() void CallGraph::addCallGraphNode(const SVFFunction* fun) { NodeID id = callGraphNodeNum; - CallGraphNode*callGraphNode = new CallGraphNode(id, fun); + CallGraphNode *callGraphNode = new CallGraphNode(id, fun); addGNode(id, callGraphNode); funToCallGraphNodeMap[callGraphNode->getFunction()] = callGraphNode; callGraphNodeNum++; From 7c52c5b8a24dd5673f7936c3daec308daaa36d59 Mon Sep 17 00:00:00 2001 From: hwg Date: Thu, 30 Jan 2025 13:33:43 +1100 Subject: [PATCH 02/45] fix --- svf/include/Graphs/CallGraph.h | 33 +++++++++------------------------ svf/lib/Graphs/CallGraph.cpp | 2 +- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 2785fd423..3ea2245ba 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -134,7 +134,7 @@ class CallGraphNode : public GenericCallGraphNodeTy const SVFFunctionType* funcType; /// FunctionType, which is different from the type (PointerType) of this SVFFunction SVFLoopAndDomInfo* loopAndDom; /// the loop and dominate information const SVFFunction* realDefFun; /// the definition of a function across multiple modules - std::vector allBBs; /// all BasicBlocks of this function + BasicBlockGraph* bbGraph; /// the basic block graph of this function std::vector allArgs; /// all formal arguments of this function const SVFBasicBlock *exitBlock; /// a 'single' basic block having no successors and containing return instruction in a function @@ -252,39 +252,24 @@ class CallGraphNode : public GenericCallGraphNodeTy return realDefFun; } - inline bool hasBasicBlock() const - { - return !allBBs.empty(); - } - - inline const SVFBasicBlock* getEntryBlock() const - { - assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); - return allBBs.front(); - } - - inline const SVFBasicBlock* back() const + void setBasicBlockGraph(BasicBlockGraph* graph) { - assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); - /// Carefully! 'back' is just the last basic block of function, - /// but not necessarily a exit basic block - /// more refer to: https://github.com/SVF-tools/SVF/pull/1262 - return allBBs.back(); + this->bbGraph = graph; } - inline bb_const_iterator begin() const + BasicBlockGraph* getBasicBlockGraph() { - return allBBs.begin(); + return bbGraph; } - inline bb_const_iterator end() const + const BasicBlockGraph* getBasicBlockGraph() const { - return allBBs.end(); + return bbGraph; } - inline const std::vector& getBasicBlockList() const + inline bool hasBasicBlock() const { - return allBBs; + return bbGraph && bbGraph->begin() != bbGraph->end(); } inline const SVFBasicBlock* getExitBB() const diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 49299a8ca..caee2dbb2 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -68,7 +68,7 @@ CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNo funcType = f->getFunctionType(); loopAndDom = f->getLoopAndDomInfo(); realDefFun = f->getDefFunForMultipleModule(); - allBBs = f->getBasicBlockList(); + bbGraph = const_cast(f->getBasicBlockGraph()); allArgs = f->getArgsList(); if (f->hasBasicBlock()) exitBlock = f->getExitBB(); From 0cdfac126e0c612fb912fab677f4e9c4477c18d4 Mon Sep 17 00:00:00 2001 From: hwg Date: Thu, 30 Jan 2025 13:52:39 +1100 Subject: [PATCH 03/45] rm SVFFunction in CFL --- svf/include/CFL/CFLAlias.h | 2 +- svf/lib/CFL/CFLAlias.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/svf/include/CFL/CFLAlias.h b/svf/include/CFL/CFLAlias.h index c349e2946..522378bbb 100644 --- a/svf/include/CFL/CFLAlias.h +++ b/svf/include/CFL/CFLAlias.h @@ -135,7 +135,7 @@ class CFLAlias : public CFLBase virtual void onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, CallEdgeMap& newEdges); /// Connect formal and actual parameters for indirect callsites - void connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunction* F); + void connectCaller2CalleeParams(const CallICFGNode* cs, const CallGraphNode* F); void heapAllocatorViaIndCall(const CallICFGNode* cs); diff --git a/svf/lib/CFL/CFLAlias.cpp b/svf/lib/CFL/CFLAlias.cpp index 2ed412b38..28111b61a 100644 --- a/svf/lib/CFL/CFLAlias.cpp +++ b/svf/lib/CFL/CFLAlias.cpp @@ -28,6 +28,7 @@ */ #include "CFL/CFLAlias.h" +#include "Graphs/CallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -59,7 +60,7 @@ void CFLAlias::onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, Call * Connect formal and actual parameters for indirect callsites */ -void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunction* F) +void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const CallGraphNode* F) { assert(F); @@ -68,15 +69,15 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunct const CallICFGNode* callBlockNode = cs; const RetICFGNode* retBlockNode = cs->getRetICFGNode(); - if(SVFUtil::isHeapAllocExtFunViaRet(F) && svfir->callsiteHasRet(retBlockNode)) + if(SVFUtil::isHeapAllocExtFunViaRet(F->getFunction()) && svfir->callsiteHasRet(retBlockNode)) { heapAllocatorViaIndCall(cs); } - if (svfir->funHasRet(F) && svfir->callsiteHasRet(retBlockNode)) + if (svfir->funHasRet(F->getFunction()) && svfir->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = svfir->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = svfir->getFunRet(F); + const PAGNode* fun_return = svfir->getFunRet(F->getFunction()); if (cs_return->isPointer() && fun_return->isPointer()) { NodeID dstrec = cs_return->getId(); @@ -89,12 +90,12 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunct } } - if (svfir->hasCallSiteArgsMap(callBlockNode) && svfir->hasFunArgsList(F)) + if (svfir->hasCallSiteArgsMap(callBlockNode) && svfir->hasFunArgsList(F->getFunction())) { // connect actual and formal param const SVFIR::SVFVarList& csArgList = svfir->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = svfir->getFunArgsList(F); + const SVFIR::SVFVarList& funArgList = svfir->getFunArgsList(F->getFunction()); //Go through the fixed parameters. DBOUT(DPAGBuild, outs() << " args:"); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); @@ -122,7 +123,7 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunct //Any remaining actual args must be varargs. if (F->isVarArg()) { - NodeID vaF = svfir->getVarargNode(F); + NodeID vaF = svfir->getVarargNode(F->getFunction()); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; csArgIt != csArgEit; ++csArgIt) { @@ -178,7 +179,7 @@ bool CFLAlias::updateCallGraph(const CallSiteToFunPtrMap& callsites) { for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { - connectCaller2CalleeParams(it->first,*cit); + connectCaller2CalleeParams(it->first,(*cit)->getCallGraphNode()); } } From 207340ec12d000d9f24792a3e4a9fe25eba65075 Mon Sep 17 00:00:00 2001 From: hwg Date: Tue, 10 Dec 2024 13:29:03 +1100 Subject: [PATCH 04/45] seperate buildSVFIRCallGraph to two functions --- svf-llvm/lib/LLVMModule.cpp | 24 +++++++++++------------- svf/include/Util/CallGraphBuilder.h | 4 +++- svf/lib/Util/CallGraphBuilder.cpp | 8 ++++++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index d4159f5aa..ea4eb93b2 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -179,24 +179,22 @@ void LLVMModuleSet::build() createSVFDataStructure(); initSVFFunction(); - - ICFGBuilder icfgbuilder; - icfg = icfgbuilder.build(); - CallGraphBuilder callGraphBuilder; - callgraph = callGraphBuilder.buildSVFIRCallGraph(svfModule); - for (const auto& func : svfModule->getFunctionSet()) + callgraph = callGraphBuilder.createSVFIRCallGraph(svfModule); + for (const SVFFunction* func : svfModule->getFunctionSet()) { SVFFunction* svffunc = const_cast(func); - svffunc->setCallGraphNode(callgraph->getCallGraphNode(func)); + CallGraphNode* callGraphNode = callgraph->getCallGraphNode(svffunc); + svffunc->setCallGraphNode(callGraphNode); + addFunctionMap(SVFUtil::cast(getLLVMValue(func)),callGraphNode); } - for (const auto& it : *callgraph) - { - addFunctionMap( - SVFUtil::cast(getLLVMValue(it.second->getFunction())), - it.second); - } + ICFGBuilder icfgbuilder; + icfg = icfgbuilder.build(); + + callGraphBuilder.connectSVFIRCallGraphEdge(callgraph); + + } void LLVMModuleSet::createSVFDataStructure() diff --git a/svf/include/Util/CallGraphBuilder.h b/svf/include/Util/CallGraphBuilder.h index 337d30e22..921532f4b 100644 --- a/svf/include/Util/CallGraphBuilder.h +++ b/svf/include/Util/CallGraphBuilder.h @@ -47,7 +47,9 @@ class CallGraphBuilder CallGraphBuilder()=default; /// Buidl SVFIR callgraoh - CallGraph* buildSVFIRCallGraph(SVFModule* svfModule); + CallGraph* createSVFIRCallGraph(SVFModule* svfModule); + + void connectSVFIRCallGraphEdge(CallGraph* callGraph); /// Buidl PTA callgraoh PTACallGraph* buildPTACallGraph(); diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 5bda6882b..bc702f0b8 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -38,14 +38,18 @@ using namespace SVF; using namespace SVFUtil; -CallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) +CallGraph* CallGraphBuilder::createSVFIRCallGraph(SVFModule* svfModule) { CallGraph* callgraph = new CallGraph(); for (const SVFFunction* svfFunc: svfModule->getFunctionSet()) { callgraph->addCallGraphNode(svfFunc); } + return callgraph; +} +void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) +{ for (const auto& item : *callgraph) { for (auto it : *(item.second)->getFunction()) @@ -64,9 +68,9 @@ CallGraph* CallGraphBuilder::buildSVFIRCallGraph(SVFModule* svfModule) } } } - return callgraph; } + PTACallGraph* CallGraphBuilder::buildPTACallGraph() { CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); From 7823b9f7df5ceeed7c1f22dd9b943c9a65707ccb Mon Sep 17 00:00:00 2001 From: hwg Date: Tue, 10 Dec 2024 16:36:31 +1100 Subject: [PATCH 05/45] change ICFGNode::SVFFunction* calledFunc to const CallGraphNode* calledFunc; --- svf-llvm/lib/ICFGBuilder.cpp | 15 ++++++----- svf/include/Graphs/ICFG.h | 2 +- svf/include/Graphs/ICFGNode.h | 6 ++--- svf/include/SABER/DoubleFreeChecker.h | 4 +-- svf/include/SABER/FileChecker.h | 4 +-- svf/include/SABER/LeakChecker.h | 8 +++--- svf/include/SABER/SaberCheckerAPI.h | 19 ++++---------- svf/include/Util/SVFUtil.h | 9 +++---- svf/include/Util/ThreadAPI.h | 11 +------- svf/lib/AE/Svfexe/AEDetector.cpp | 5 ++-- svf/lib/AE/Svfexe/AbsExtAPI.cpp | 8 +++--- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 27 +++++++++----------- svf/lib/MemoryModel/PointerAnalysis.cpp | 4 +-- svf/lib/SABER/DoubleFreeChecker.cpp | 7 ++--- svf/lib/SABER/LeakChecker.cpp | 7 ++--- svf/lib/SABER/SaberCheckerAPI.cpp | 14 +++++++++- svf/lib/SABER/SaberSVFGBuilder.cpp | 4 +-- svf/lib/Util/CallGraphBuilder.cpp | 4 +-- svf/lib/Util/SVFBugReport.cpp | 3 ++- svf/lib/Util/SVFUtil.cpp | 26 +++++++++++++++---- svf/lib/Util/ThreadAPI.cpp | 14 +++++++++- 21 files changed, 112 insertions(+), 89 deletions(-) diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index 9ad6ac6c7..eb86750a3 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -241,17 +241,18 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst) assert(llvmModuleSet()->getCallBlock(inst)==nullptr && "duplicate CallICFGNode"); const CallBase* cb = SVFUtil::dyn_cast(inst); bool isvcall = cppUtil::isVirtualCallSite(cb); - SVFFunction* calledFunc = nullptr; + const CallGraphNode* calledFunc = nullptr; auto called_llvmval = cb->getCalledOperand()->stripPointerCasts(); if (const Function* called_llvmfunc = SVFUtil::dyn_cast(called_llvmval)) { - calledFunc = llvmModuleSet()->getSVFFunction(called_llvmfunc); - } - else - { - calledFunc = SVFUtil::dyn_cast( - llvmModuleSet()->getSVFValue(called_llvmval)); + calledFunc = llvmModuleSet()->getCallGraphNode(called_llvmfunc); } +// else +// { +// const SVFFunction* func = SVFUtil::dyn_cast( +// llvmModuleSet()->getSVFValue(called_llvmval)); +// calledFunc = func?func->getCallGraphNode(): nullptr ; +// } SVFBasicBlock* bb = llvmModuleSet()->getSVFBasicBlock(inst->getParent()); diff --git a/svf/include/Graphs/ICFG.h b/svf/include/Graphs/ICFG.h index 33d67bbe1..b2f8deefe 100644 --- a/svf/include/Graphs/ICFG.h +++ b/svf/include/Graphs/ICFG.h @@ -182,7 +182,7 @@ class ICFG : public GenericICFGTy virtual inline CallICFGNode* addCallICFGNode( const SVFBasicBlock* bb, const SVFType* ty, - const SVFFunction* calledFunc, bool isVararg, bool isvcall, + const CallGraphNode* calledFunc, bool isVararg, bool isvcall, s32_t vcallIdx, const std::string& funNameOfVcall) { diff --git a/svf/include/Graphs/ICFGNode.h b/svf/include/Graphs/ICFGNode.h index 033660187..88af9efb1 100644 --- a/svf/include/Graphs/ICFGNode.h +++ b/svf/include/Graphs/ICFGNode.h @@ -430,7 +430,7 @@ class CallICFGNode : public InterICFGNode protected: const RetICFGNode* ret; ActualParmNodeVec APNodes; /// arguments - const SVFFunction* calledFunc; /// called function + const CallGraphNode* calledFunc; /// called function bool isvararg; /// is variable argument bool isVirCallInst; /// is virtual call inst SVFVar* vtabPtr; /// virtual table pointer @@ -442,7 +442,7 @@ class CallICFGNode : public InterICFGNode public: CallICFGNode(NodeID id, const SVFBasicBlock* b, const SVFType* ty, - const SVFFunction* cf, bool iv, bool ivc, s32_t vfi, + const CallGraphNode* cf, bool iv, bool ivc, s32_t vfi, const std::string& fnv) : InterICFGNode(id, FunCallBlock), ret(nullptr), calledFunc(cf), isvararg(iv), isVirCallInst(ivc), vtabPtr(nullptr), @@ -515,7 +515,7 @@ class CallICFGNode : public InterICFGNode { return arg_size(); } - inline const SVFFunction* getCalledFunction() const + inline const CallGraphNode* getCalledFunction() const { return calledFunc; } diff --git a/svf/include/SABER/DoubleFreeChecker.h b/svf/include/SABER/DoubleFreeChecker.h index 786a49db8..1ec064be1 100644 --- a/svf/include/SABER/DoubleFreeChecker.h +++ b/svf/include/SABER/DoubleFreeChecker.h @@ -67,8 +67,8 @@ class DoubleFreeChecker : public LeakChecker /// Validate test cases for regression test purpose void testsValidation(ProgSlice* slice); - void validateSuccessTests(ProgSlice* slice, const SVFFunction* fun); - void validateExpectedFailureTests(ProgSlice* slice, const SVFFunction* fun); + void validateSuccessTests(ProgSlice* slice, const CallGraphNode* fun); + void validateExpectedFailureTests(ProgSlice* slice, const CallGraphNode* fun); }; } // End namespace SVF diff --git a/svf/include/SABER/FileChecker.h b/svf/include/SABER/FileChecker.h index ddcc1d4e2..3e04b0323 100644 --- a/svf/include/SABER/FileChecker.h +++ b/svf/include/SABER/FileChecker.h @@ -64,12 +64,12 @@ class FileChecker : public LeakChecker inline bool isSourceLikeFun(const SVFFunction* fun) { - return SaberCheckerAPI::getCheckerAPI()->isFOpen(fun); + return SaberCheckerAPI::getCheckerAPI()->isFOpen(fun->getCallGraphNode()); } /// Whether the function is a heap deallocator (free/release memory) inline bool isSinkLikeFun(const SVFFunction* fun) { - return SaberCheckerAPI::getCheckerAPI()->isFClose(fun); + return SaberCheckerAPI::getCheckerAPI()->isFClose(fun->getCallGraphNode()); } /// Report file/close bugs void reportBug(ProgSlice* slice); diff --git a/svf/include/SABER/LeakChecker.h b/svf/include/SABER/LeakChecker.h index 2328adaa6..f07eb903f 100644 --- a/svf/include/SABER/LeakChecker.h +++ b/svf/include/SABER/LeakChecker.h @@ -80,12 +80,12 @@ class LeakChecker : public SrcSnkDDA /// Whether the function is a heap allocator/reallocator (allocate memory) virtual inline bool isSourceLikeFun(const SVFFunction* fun) override { - return SaberCheckerAPI::getCheckerAPI()->isMemAlloc(fun); + return SaberCheckerAPI::getCheckerAPI()->isMemAlloc(fun->getCallGraphNode()); } /// Whether the function is a heap deallocator (free/release memory) virtual inline bool isSinkLikeFun(const SVFFunction* fun) override { - return SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun); + return SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun->getCallGraphNode()); } //@} @@ -97,8 +97,8 @@ class LeakChecker : public SrcSnkDDA /// Validate test cases for regression test purpose void testsValidation(const ProgSlice* slice); - void validateSuccessTests(const SVFGNode* source, const SVFFunction* fun); - void validateExpectedFailureTests(const SVFGNode* source, const SVFFunction* fun); + void validateSuccessTests(const SVFGNode* source, const CallGraphNode* fun); + void validateExpectedFailureTests(const SVFGNode* source, const CallGraphNode* fun); /// Record a source to its callsite //@{ diff --git a/svf/include/SABER/SaberCheckerAPI.h b/svf/include/SABER/SaberCheckerAPI.h index 812506445..bb73f741d 100644 --- a/svf/include/SABER/SaberCheckerAPI.h +++ b/svf/include/SABER/SaberCheckerAPI.h @@ -73,16 +73,7 @@ class SaberCheckerAPI static SaberCheckerAPI* ckAPI; /// Get the function type of a function - inline CHECKER_TYPE getType(const SVFFunction* F) const - { - if(F) - { - TDAPIMap::const_iterator it= tdAPIMap.find(F->getName()); - if(it != tdAPIMap.end()) - return it->second; - } - return CK_DUMMY; - } + CHECKER_TYPE getType(const CallGraphNode* F) const; public: /// Return a static reference @@ -97,7 +88,7 @@ class SaberCheckerAPI /// Return true if this call is a memory allocation //@{ - inline bool isMemAlloc(const SVFFunction* fun) const + inline bool isMemAlloc(const CallGraphNode* fun) const { return getType(fun) == CK_ALLOC; } @@ -109,7 +100,7 @@ class SaberCheckerAPI /// Return true if this call is a memory deallocation //@{ - inline bool isMemDealloc(const SVFFunction* fun) const + inline bool isMemDealloc(const CallGraphNode* fun) const { return getType(fun) == CK_FREE; } @@ -121,7 +112,7 @@ class SaberCheckerAPI /// Return true if this call is a file open //@{ - inline bool isFOpen(const SVFFunction* fun) const + inline bool isFOpen(const CallGraphNode* fun) const { return getType(fun) == CK_FOPEN; } @@ -133,7 +124,7 @@ class SaberCheckerAPI /// Return true if this call is a file close //@{ - inline bool isFClose(const SVFFunction* fun) const + inline bool isFClose(const CallGraphNode* fun) const { return getType(fun) == CK_FCLOSE; } diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index e3ae68e37..1c1493043 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -272,6 +272,8 @@ inline bool isExtCall(const SVFFunction* fun) return fun && ExtAPI::getExtAPI()->is_ext(fun); } +bool isExtCall(const CallGraphNode* fun); + inline bool isMemcpyExtFun(const SVFFunction* fun) { return fun && ExtAPI::getExtAPI()->is_memcpy(fun); @@ -327,12 +329,7 @@ const SVFFunction* getProgEntryFunction(); /// Return true if this is a program exit function call //@{ -inline bool isProgExitFunction (const SVFFunction * fun) -{ - return fun && (fun->getName() == "exit" || - fun->getName() == "__assert_rtn" || - fun->getName() == "__assert_fail" ); -} +bool isProgExitFunction (const CallGraphNode * fun); bool isArgOfUncalledFunction(const SVFVar* svfvar); diff --git a/svf/include/Util/ThreadAPI.h b/svf/include/Util/ThreadAPI.h index 3acb042b5..6ce49f38e 100644 --- a/svf/include/Util/ThreadAPI.h +++ b/svf/include/Util/ThreadAPI.h @@ -91,16 +91,7 @@ class ThreadAPI static ThreadAPI* tdAPI; /// Get the function type if it is a threadAPI function - inline TD_TYPE getType(const SVFFunction* F) const - { - if(F) - { - TDAPIMap::const_iterator it= tdAPIMap.find(F->getName()); - if(it != tdAPIMap.end()) - return it->second; - } - return TD_DUMMY; - } + TD_TYPE getType(const CallGraphNode* F) const; public: /// Return a static reference diff --git a/svf/lib/AE/Svfexe/AEDetector.cpp b/svf/lib/AE/Svfexe/AEDetector.cpp index 7420e8fb0..e4393ec4e 100644 --- a/svf/lib/AE/Svfexe/AEDetector.cpp +++ b/svf/lib/AE/Svfexe/AEDetector.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "Graphs/CallGraph.h" using namespace SVF; @@ -219,12 +220,12 @@ void BufOverflowDetector::initExtAPIBufOverflowCheckRules() void BufOverflowDetector::detectExtAPI(AbstractState& as, const CallICFGNode* call) { - assert(call->getCalledFunction() && "SVFFunction* is nullptr"); + assert(call->getCalledFunction() && "CallGraphNode* is nullptr"); AbsExtAPI::ExtAPIType extType = AbsExtAPI::UNCLASSIFIED; // Determine the type of external memory API - for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction())) + for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction()->getFunction())) { if (annotation.find("MEMCPY") != std::string::npos) extType = AbsExtAPI::MEMCPY; diff --git a/svf/lib/AE/Svfexe/AbsExtAPI.cpp b/svf/lib/AE/Svfexe/AbsExtAPI.cpp index bc212af96..ae02d3b9f 100644 --- a/svf/lib/AE/Svfexe/AbsExtAPI.cpp +++ b/svf/lib/AE/Svfexe/AbsExtAPI.cpp @@ -26,6 +26,7 @@ // #include "AE/Svfexe/AbsExtAPI.h" #include "AE/Svfexe/AbstractInterpretation.h" +#include "Graphs/CallGraph.h" using namespace SVF; AbsExtAPI::AbsExtAPI(Map& traces): abstractTrace(traces) @@ -386,8 +387,9 @@ std::string AbsExtAPI::strRead(AbstractState& as, const SVFVar* rhs) void AbsExtAPI::handleExtAPI(const CallICFGNode *call) { AbstractState& as = getAbsStateFromTrace(call); - const SVFFunction *fun = call->getCalledFunction(); - assert(fun && "SVFFunction* is nullptr"); + const CallGraphNode *cgNode = call->getCalledFunction(); + assert(cgNode && "CallGraphNode* is nullptr"); + const SVFFunction *fun = cgNode->getFunction(); ExtAPIType extType = UNCLASSIFIED; // get type of mem api for (const std::string &annotation: ExtAPI::getExtAPI()->getExtFuncAnnotations(fun)) @@ -546,7 +548,7 @@ void AbsExtAPI::handleStrcat(const SVF::CallICFGNode *call) // __strcat_chk, strcat, __wcscat_chk, wcscat, __strncat_chk, strncat, __wcsncat_chk, wcsncat // to check it is strcat group or strncat group AbstractState& as = getAbsStateFromTrace(call); - const SVFFunction *fun = call->getCalledFunction(); + const CallGraphNode *fun = call->getCalledFunction(); const std::vector strcatGroup = {"__strcat_chk", "strcat", "__wcscat_chk", "wcscat"}; const std::vector strncatGroup = {"__strncat_chk", "strncat", "__wcsncat_chk", "wcsncat"}; if (std::find(strcatGroup.begin(), strcatGroup.end(), fun->getName()) != strcatGroup.end()) diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index d877cef7b..5809c7839 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -565,7 +565,10 @@ void AbstractInterpretation::handleCallSite(const ICFGNode* node) bool AbstractInterpretation::isExtCall(const SVF::CallICFGNode *callNode) { - return SVFUtil::isExtCall(callNode->getCalledFunction()); + if (callNode->getCalledFunction()) + return SVFUtil::isExtCall(callNode->getCalledFunction()->getFunction()); + else + return false; } void AbstractInterpretation::extCallPass(const SVF::CallICFGNode *callNode) @@ -581,11 +584,8 @@ void AbstractInterpretation::extCallPass(const SVF::CallICFGNode *callNode) bool AbstractInterpretation::isRecursiveCall(const SVF::CallICFGNode *callNode) { - const SVFFunction *callfun = callNode->getCalledFunction(); - if (!callfun) - return false; - else - return recursiveFuns.find(callfun->getCallGraphNode()) != recursiveFuns.end(); + const CallGraphNode *callfun = callNode->getCalledFunction(); + return callfun && recursiveFuns.find(callfun) != recursiveFuns.end(); } void AbstractInterpretation::recursiveCallPass(const SVF::CallICFGNode *callNode) @@ -609,11 +609,8 @@ void AbstractInterpretation::recursiveCallPass(const SVF::CallICFGNode *callNode bool AbstractInterpretation::isDirectCall(const SVF::CallICFGNode *callNode) { - const SVFFunction *callfun =callNode->getCalledFunction(); - if (!callfun) - return false; - else - return funcToWTO.find(callfun->getCallGraphNode()) != funcToWTO.end(); + const CallGraphNode *callfun =callNode->getCalledFunction(); + return callfun && funcToWTO.find(callfun) != funcToWTO.end(); } void AbstractInterpretation::directCallFunPass(const SVF::CallICFGNode *callNode) { @@ -622,8 +619,8 @@ void AbstractInterpretation::directCallFunPass(const SVF::CallICFGNode *callNode abstractTrace[callNode] = as; - const SVFFunction *callfun =callNode->getCalledFunction(); - ICFGWTO* wto = funcToWTO[callfun->getCallGraphNode()]; + const CallGraphNode *callfun =callNode->getCalledFunction(); + ICFGWTO* wto = funcToWTO[callfun]; handleWTOComponents(wto->getWTOComponents()); callSiteStack.pop_back(); @@ -800,7 +797,7 @@ void AbstractInterpretation::SkipRecursiveCall(const CallICFGNode *callNode) } FIFOWorkList blkWorkList; FIFOWorkList instWorklist; - for (const SVFBasicBlock * bb: callNode->getCalledFunction()->getReachableBBs()) + for (const SVFBasicBlock * bb: callNode->getCalledFunction()->getReachableBBs()) // HWG need to rethink this { for (const ICFGNode* node: bb->getICFGNodeList()) { @@ -928,7 +925,7 @@ void AbstractInterpretation::collectCheckPoint() const ICFGNode* node = it->second; if (const CallICFGNode *call = SVFUtil::dyn_cast(node)) { - if (const SVFFunction *fun = call->getCalledFunction()) + if (const CallGraphNode *fun = call->getCalledFunction()) { if (ae_checkpoint_names.find(fun->getName()) != ae_checkpoint_names.end()) diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 1e53080db..a0e9e319a 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -504,7 +504,7 @@ void PointerAnalysis::resolveCPPIndCalls(const CallICFGNode* cs, const PointsTo& void PointerAnalysis::validateSuccessTests(std::string fun) { // check for must alias cases, whether our alias analysis produce the correct results - if (const SVFFunction* checkFun = svfMod->getSVFFunction(fun)) + if (const CallGraphNode* checkFun = pag->getCallGraph()->getCallGraphNode(fun)) { if(!checkFun->isUncalledFunction()) outs() << "[" << this->PTAName() << "] Checking " << fun << "\n"; @@ -569,7 +569,7 @@ void PointerAnalysis::validateSuccessTests(std::string fun) void PointerAnalysis::validateExpectedFailureTests(std::string fun) { - if (const SVFFunction* checkFun = svfMod->getSVFFunction(fun)) + if (const CallGraphNode* checkFun = pag->getCallGraph()->getCallGraphNode(fun)) { if(!checkFun->isUncalledFunction()) outs() << "[" << this->PTAName() << "] Checking " << fun << "\n"; diff --git a/svf/lib/SABER/DoubleFreeChecker.cpp b/svf/lib/SABER/DoubleFreeChecker.cpp index f14a0d8f5..cb30a0e3f 100644 --- a/svf/lib/SABER/DoubleFreeChecker.cpp +++ b/svf/lib/SABER/DoubleFreeChecker.cpp @@ -30,6 +30,7 @@ #include "SABER/DoubleFreeChecker.h" #include "Util/SVFUtil.h" #include "Util/Options.h" +#include "Graphs/CallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -55,14 +56,14 @@ void DoubleFreeChecker::testsValidation(ProgSlice *slice) { const SVFGNode* source = slice->getSource(); const CallICFGNode* cs = getSrcCSID(source); - const SVFFunction* fun = cs->getCalledFunction(); + const CallGraphNode* fun = cs->getCalledFunction(); if(fun==nullptr) return; validateSuccessTests(slice,fun); validateExpectedFailureTests(slice,fun); } -void DoubleFreeChecker::validateSuccessTests(ProgSlice *slice, const SVFFunction *fun) +void DoubleFreeChecker::validateSuccessTests(ProgSlice *slice, const CallGraphNode *fun) { const SVFGNode* source = slice->getSource(); const CallICFGNode* cs = getSrcCSID(source); @@ -108,7 +109,7 @@ void DoubleFreeChecker::validateSuccessTests(ProgSlice *slice, const SVFFunction } } -void DoubleFreeChecker::validateExpectedFailureTests(ProgSlice *slice, const SVFFunction *fun) +void DoubleFreeChecker::validateExpectedFailureTests(ProgSlice *slice, const CallGraphNode *fun) { const SVFGNode* source = slice->getSource(); const CallICFGNode* cs = getSrcCSID(source); diff --git a/svf/lib/SABER/LeakChecker.cpp b/svf/lib/SABER/LeakChecker.cpp index 7cfc96c67..6ec98979e 100644 --- a/svf/lib/SABER/LeakChecker.cpp +++ b/svf/lib/SABER/LeakChecker.cpp @@ -29,6 +29,7 @@ #include "Util/Options.h" #include "SABER/LeakChecker.h" +#include "Graphs/CallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -179,7 +180,7 @@ void LeakChecker::testsValidation(const ProgSlice* slice) { const SVFGNode* source = slice->getSource(); const CallICFGNode* cs = getSrcCSID(source); - const SVFFunction* fun = cs->getCalledFunction(); + const CallGraphNode* fun = cs->getCalledFunction(); if(fun==nullptr) return; @@ -188,7 +189,7 @@ void LeakChecker::testsValidation(const ProgSlice* slice) } -void LeakChecker::validateSuccessTests(const SVFGNode* source, const SVFFunction* fun) +void LeakChecker::validateSuccessTests(const SVFGNode* source, const CallGraphNode* fun) { const CallICFGNode* cs = getSrcCSID(source); @@ -243,7 +244,7 @@ void LeakChecker::validateSuccessTests(const SVFGNode* source, const SVFFunction } } -void LeakChecker::validateExpectedFailureTests(const SVFGNode* source, const SVFFunction* fun) +void LeakChecker::validateExpectedFailureTests(const SVFGNode* source, const CallGraphNode* fun) { const CallICFGNode* cs = getSrcCSID(source); diff --git a/svf/lib/SABER/SaberCheckerAPI.cpp b/svf/lib/SABER/SaberCheckerAPI.cpp index 9baab29dc..cb4c1a031 100644 --- a/svf/lib/SABER/SaberCheckerAPI.cpp +++ b/svf/lib/SABER/SaberCheckerAPI.cpp @@ -28,6 +28,7 @@ */ #include "SABER/SaberCheckerAPI.h" #include +#include "Graphs/CallGraph.h" using namespace std; using namespace SVF; @@ -171,6 +172,17 @@ void SaberCheckerAPI::init() } } - +/// Get the function type of a function +SaberCheckerAPI::CHECKER_TYPE SaberCheckerAPI::getType( + const CallGraphNode* F) const +{ + if(F) + { + TDAPIMap::const_iterator it= tdAPIMap.find(F->getName()); + if(it != tdAPIMap.end()) + return it->second; + } + return CK_DUMMY; +} diff --git a/svf/lib/SABER/SaberSVFGBuilder.cpp b/svf/lib/SABER/SaberSVFGBuilder.cpp index 1b7bec223..4279340e7 100644 --- a/svf/lib/SABER/SaberSVFGBuilder.cpp +++ b/svf/lib/SABER/SaberSVFGBuilder.cpp @@ -304,8 +304,8 @@ void SaberSVFGBuilder::AddExtActualParmSVFGNodes(PTACallGraph* callgraph) { const SVFFunction* fun = *cit; - if (SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun) - || SaberCheckerAPI::getCheckerAPI()->isFClose(fun)) + if (SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun->getCallGraphNode()) + || SaberCheckerAPI::getCheckerAPI()->isFClose(fun->getCallGraphNode())) { SVFIR::SVFVarList& arglist = it->second; for(SVFIR::SVFVarList::const_iterator ait = arglist.begin(), aeit = arglist.end(); ait!=aeit; ++ait) diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index bc702f0b8..19c4eed7c 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -60,9 +60,9 @@ void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) if (SVFUtil::isNonInstricCallSite(inst)) { const CallICFGNode* callBlockNode = cast(inst); - if(const SVFFunction* callee = callBlockNode->getCalledFunction()) + if(const CallGraphNode* callee = callBlockNode->getCalledFunction()) { - callgraph->addDirectCallGraphEdge(callBlockNode,(item.second)->getFunction(),callee); + callgraph->addDirectCallGraphEdge(callBlockNode,(item.second)->getFunction(),callee->getFunction()); } } } diff --git a/svf/lib/Util/SVFBugReport.cpp b/svf/lib/Util/SVFBugReport.cpp index af6be8bb8..180a2c12e 100644 --- a/svf/lib/Util/SVFBugReport.cpp +++ b/svf/lib/Util/SVFBugReport.cpp @@ -31,6 +31,7 @@ #include "Util/SVFUtil.h" #include #include +#include "Graphs/CallGraph.h" using namespace std; using namespace SVF; @@ -304,7 +305,7 @@ const std::string SVFBugEvent::getEventDescription() const { std::string description("calls "); assert(SVFUtil::isa(eventInst) && "not a call ICFGNode?"); - const SVFFunction *callee = SVFUtil::cast(eventInst)->getCalledFunction(); + const CallGraphNode *callee = SVFUtil::cast(eventInst)->getCalledFunction(); if(callee == nullptr) { description += ""; diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index 08de0becf..bd533c3f2 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -335,7 +335,7 @@ bool SVFUtil::isIntrinsicInst(const ICFGNode* inst) { if (const CallICFGNode* call = SVFUtil::dyn_cast(inst)) { - const SVFFunction* func = call->getCalledFunction(); + const CallGraphNode* func = call->getCalledFunction(); if (func && func->isIntrinsic()) { return true; @@ -351,13 +351,16 @@ bool SVFUtil::isExtCall(const CallICFGNode* cs) bool SVFUtil::isHeapAllocExtCallViaArg(const CallICFGNode* cs) { - return isHeapAllocExtFunViaArg(cs->getCalledFunction()); + if (cs->getCalledFunction()) + return isHeapAllocExtFunViaArg(cs->getCalledFunction()->getFunction()); + else + return false; } u32_t SVFUtil::getHeapAllocHoldingArgPosition(const CallICFGNode* cs) { - return getHeapAllocHoldingArgPosition(cs->getCalledFunction()); + return getHeapAllocHoldingArgPosition(cs->getCalledFunction()->getFunction()); } @@ -376,13 +379,14 @@ bool SVFUtil::isHeapAllocExtCall(const ICFGNode* cs) bool SVFUtil::isHeapAllocExtCallViaRet(const CallICFGNode* cs) { bool isPtrTy = cs->getType()->isPointerTy(); - return isPtrTy && isHeapAllocExtFunViaRet(cs->getCalledFunction()); + const CallGraphNode* fun = cs->getCalledFunction(); + return fun && isPtrTy && isHeapAllocExtFunViaRet(fun->getFunction()); } bool SVFUtil::isReallocExtCall(const CallICFGNode* cs) { bool isPtrTy = cs->getType()->isPointerTy(); - return isPtrTy && isReallocExtFun(cs->getCalledFunction()); + return isPtrTy && isReallocExtFun(cs->getCalledFunction()->getFunction()); } @@ -439,3 +443,15 @@ const ObjVar* SVFUtil::getObjVarOfValVar(const SVF::ValVar* valVar) assert(valVar->getInEdges().size() == 1); return SVFUtil::dyn_cast((*valVar->getInEdges().begin())->getSrcNode()); } + +bool SVFUtil::isExtCall(const CallGraphNode* fun) +{ + return fun && ExtAPI::getExtAPI()->is_ext(fun->getFunction()); +} + +bool SVFUtil::isProgExitFunction (const CallGraphNode * fun) +{ + return fun && (fun->getName() == "exit" || + fun->getName() == "__assert_rtn" || + fun->getName() == "__assert_fail" ); +} \ No newline at end of file diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index a1fcae3c9..5bc080121 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -130,6 +130,18 @@ void ThreadAPI::init() } } +/// Get the function type if it is a threadAPI function +ThreadAPI::TD_TYPE ThreadAPI::getType(const CallGraphNode* F) const +{ + if(F) + { + TDAPIMap::const_iterator it= tdAPIMap.find(F->getName()); + if(it != tdAPIMap.end()) + return it->second; + } + return TD_DUMMY; +} + bool ThreadAPI::isTDFork(const CallICFGNode *inst) const { return getType(inst->getCalledFunction()) == TD_FORK; @@ -281,7 +293,7 @@ void ThreadAPI::performAPIStat(SVFModule* module) if (!SVFUtil::isCallSite(svfInst)) continue; - const SVFFunction* fun = SVFUtil::cast(svfInst)->getCalledFunction(); + const CallGraphNode* fun = SVFUtil::cast(svfInst)->getCalledFunction(); TD_TYPE type = getType(fun); switch (type) { From 82fac4712a066919ddfcda627c8fd4bae3cf1d89 Mon Sep 17 00:00:00 2001 From: hwg Date: Sat, 19 Oct 2024 18:34:10 +1100 Subject: [PATCH 06/45] rm Map FunToCallGraphNodeMap; in CallGraph.h --- svf-llvm/lib/LLVMModule.cpp | 9 ++++----- svf/include/Graphs/CallGraph.h | 14 +------------- svf/include/SVFIR/SVFValue.h | 2 +- svf/lib/Graphs/CallGraph.cpp | 8 +------- svf/lib/Util/CallGraphBuilder.cpp | 3 ++- 5 files changed, 9 insertions(+), 27 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index ea4eb93b2..1c73ab49f 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -181,12 +181,11 @@ void LLVMModuleSet::build() CallGraphBuilder callGraphBuilder; callgraph = callGraphBuilder.createSVFIRCallGraph(svfModule); - for (const SVFFunction* func : svfModule->getFunctionSet()) + for (const auto& it : *callgraph) { - SVFFunction* svffunc = const_cast(func); - CallGraphNode* callGraphNode = callgraph->getCallGraphNode(svffunc); - svffunc->setCallGraphNode(callGraphNode); - addFunctionMap(SVFUtil::cast(getLLVMValue(func)),callGraphNode); + SVFFunction* svffunc = const_cast(it.second->getFunction()); + svffunc->setCallGraphNode(it.second); + addFunctionMap(SVFUtil::cast(getLLVMValue(svffunc)), it.second); } ICFGBuilder icfgbuilder; diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 3ea2245ba..997a62ecf 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -353,13 +353,8 @@ class CallGraph : public GenericCallGraphTy public: typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; - typedef Map FunToCallGraphNodeMap; typedef Map CallInstToCallGraphEdgesMap; - typedef Set FunctionSet; - typedef OrderedMap CallEdgeMap; - protected: - FunToCallGraphNodeMap funToCallGraphNodeMap; ///< Call Graph node map CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap; ///< Map a call instruction to its corresponding call edges NodeID callGraphNodeNum; @@ -395,13 +390,6 @@ class CallGraph : public GenericCallGraphTy { return getGNode(id); } - inline CallGraphNode* getCallGraphNode(const SVFFunction* fun) const - { - FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun); - assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!"); - return it->second; - } - //@} /// Whether we have already created this call graph edge @@ -409,7 +397,7 @@ class CallGraph : public GenericCallGraphTy const CallICFGNode* callIcfgNode) const; /// Add direct call edges - void addDirectCallGraphEdge(const CallICFGNode* call, const SVFFunction* callerFun, const SVFFunction* calleeFun); + void addDirectCallGraphEdge(const CallICFGNode* call, CallGraphNode* callerFun, CallGraphNode* calleeFun); /// Dump the graph void dump(const std::string& filename); diff --git a/svf/include/SVFIR/SVFValue.h b/svf/include/SVFIR/SVFValue.h index 8be45bc15..1ad7098a3 100644 --- a/svf/include/SVFIR/SVFValue.h +++ b/svf/include/SVFIR/SVFValue.h @@ -322,7 +322,7 @@ class SVFFunction : public SVFValue BasicBlockGraph* bbGraph; /// the basic block graph of this function protected: - inline void setCallGraphNode(CallGraphNode *cgn) + inline void setCallGraphNode(const CallGraphNode *cgn) { callGraphNode = cgn; } diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index caee2dbb2..ffee50f50 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -107,7 +107,6 @@ void CallGraph::addCallGraphNode(const SVFFunction* fun) NodeID id = callGraphNodeNum; CallGraphNode *callGraphNode = new CallGraphNode(id, fun); addGNode(id, callGraphNode); - funToCallGraphNodeMap[callGraphNode->getFunction()] = callGraphNode; callGraphNodeNum++; } @@ -133,13 +132,8 @@ CallGraphEdge* CallGraph::hasGraphEdge(CallGraphNode* src, /*! * Add direct call edges */ -void CallGraph::addDirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) +void CallGraph::addDirectCallGraphEdge(const CallICFGNode* cs, CallGraphNode* caller, CallGraphNode* callee) { - - CallGraphNode* caller = getCallGraphNode(callerFun); - CallGraphNode* callee = getCallGraphNode(calleeFun); - - if(!hasGraphEdge(caller,callee, cs)) { CallGraphEdge* edge = new CallGraphEdge(caller,callee, cs); diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 19c4eed7c..46f4e0aba 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -62,7 +62,8 @@ void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) const CallICFGNode* callBlockNode = cast(inst); if(const CallGraphNode* callee = callBlockNode->getCalledFunction()) { - callgraph->addDirectCallGraphEdge(callBlockNode,(item.second)->getFunction(),callee->getFunction()); + callgraph->addDirectCallGraphEdge(callBlockNode,item.second, + const_cast(callee)); } } } From bbf2484bb062c7058ef6ae5d918483a30510befa Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 11:46:27 +1100 Subject: [PATCH 07/45] refactoring bool isSourceLikeFun(const CallGraphNode* fun) --- svf/include/SABER/FileChecker.h | 8 ++++---- svf/include/SABER/LeakChecker.h | 8 ++++---- svf/include/SABER/SrcSnkDDA.h | 4 ++-- svf/lib/SABER/LeakChecker.cpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/svf/include/SABER/FileChecker.h b/svf/include/SABER/FileChecker.h index 3e04b0323..44097796a 100644 --- a/svf/include/SABER/FileChecker.h +++ b/svf/include/SABER/FileChecker.h @@ -62,14 +62,14 @@ class FileChecker : public LeakChecker return false; } - inline bool isSourceLikeFun(const SVFFunction* fun) + inline bool isSourceLikeFun(const CallGraphNode* fun) { - return SaberCheckerAPI::getCheckerAPI()->isFOpen(fun->getCallGraphNode()); + return SaberCheckerAPI::getCheckerAPI()->isFOpen(fun); } /// Whether the function is a heap deallocator (free/release memory) - inline bool isSinkLikeFun(const SVFFunction* fun) + inline bool isSinkLikeFun(const CallGraphNode* fun) { - return SaberCheckerAPI::getCheckerAPI()->isFClose(fun->getCallGraphNode()); + return SaberCheckerAPI::getCheckerAPI()->isFClose(fun); } /// Report file/close bugs void reportBug(ProgSlice* slice); diff --git a/svf/include/SABER/LeakChecker.h b/svf/include/SABER/LeakChecker.h index f07eb903f..232b69c47 100644 --- a/svf/include/SABER/LeakChecker.h +++ b/svf/include/SABER/LeakChecker.h @@ -78,14 +78,14 @@ class LeakChecker : public SrcSnkDDA virtual void initSrcs() override; virtual void initSnks() override; /// Whether the function is a heap allocator/reallocator (allocate memory) - virtual inline bool isSourceLikeFun(const SVFFunction* fun) override + virtual inline bool isSourceLikeFun(const CallGraphNode* fun) override { - return SaberCheckerAPI::getCheckerAPI()->isMemAlloc(fun->getCallGraphNode()); + return SaberCheckerAPI::getCheckerAPI()->isMemAlloc(fun); } /// Whether the function is a heap deallocator (free/release memory) - virtual inline bool isSinkLikeFun(const SVFFunction* fun) override + virtual inline bool isSinkLikeFun(const CallGraphNode* fun) override { - return SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun->getCallGraphNode()); + return SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun); } //@} diff --git a/svf/include/SABER/SrcSnkDDA.h b/svf/include/SABER/SrcSnkDDA.h index 150946b47..0c191dafe 100644 --- a/svf/include/SABER/SrcSnkDDA.h +++ b/svf/include/SABER/SrcSnkDDA.h @@ -174,12 +174,12 @@ class SrcSnkDDA : public CFLSrcSnkSolver ///@{ virtual void initSrcs() = 0; virtual void initSnks() = 0; - virtual bool isSourceLikeFun(const SVFFunction* fun) + virtual bool isSourceLikeFun(const CallGraphNode* fun) { return false; } - virtual bool isSinkLikeFun(const SVFFunction* fun) + virtual bool isSinkLikeFun(const CallGraphNode* fun) { return false; } diff --git a/svf/lib/SABER/LeakChecker.cpp b/svf/lib/SABER/LeakChecker.cpp index 6ec98979e..aaba9027b 100644 --- a/svf/lib/SABER/LeakChecker.cpp +++ b/svf/lib/SABER/LeakChecker.cpp @@ -57,7 +57,7 @@ void LeakChecker::initSrcs() for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { const SVFFunction* fun = *cit; - if (isSourceLikeFun(fun)) + if (isSourceLikeFun(fun->getCallGraphNode())) { CSWorkList worklist; SVFGNodeBS visited; @@ -117,7 +117,7 @@ void LeakChecker::initSnks() for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { const SVFFunction* fun = *cit; - if (isSinkLikeFun(fun)) + if (isSinkLikeFun(fun->getCallGraphNode())) { SVFIR::SVFVarList &arglist = it->second; assert(!arglist.empty() && "no actual parameter at deallocation site?"); From 9186c86360baf7b6cd0171f865d965b1d3d7f2f9 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 13:05:02 +1100 Subject: [PATCH 08/45] refactoring connectCaller2ForkedFunParams(const CallICFGNode* cs, const SVFFunction* F, NodePairSet& cpySrcNodes); --- svf/include/Util/ThreadAPI.h | 2 +- svf/include/WPA/Andersen.h | 4 ++-- svf/lib/Util/ThreadAPI.cpp | 3 ++- svf/lib/WPA/Andersen.cpp | 27 ++++++++++++++------------- svf/lib/WPA/AndersenSCD.cpp | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/svf/include/Util/ThreadAPI.h b/svf/include/Util/ThreadAPI.h index 6ce49f38e..87408ddec 100644 --- a/svf/include/Util/ThreadAPI.h +++ b/svf/include/Util/ThreadAPI.h @@ -127,7 +127,7 @@ class ThreadAPI const ValVar* getActualParmAtForkSite(const CallICFGNode *inst) const; /// Return the formal parm of forked function (the first arg in pthread) - const SVFVar* getFormalParmOfForkedFun(const SVFFunction* F) const; + const SVFVar* getFormalParmOfForkedFun(const CallGraphNode* F) const; //@} diff --git a/svf/include/WPA/Andersen.h b/svf/include/WPA/Andersen.h index 1bcb7e069..462128c26 100644 --- a/svf/include/WPA/Andersen.h +++ b/svf/include/WPA/Andersen.h @@ -93,11 +93,11 @@ class AndersenBase: public WPAConstraintSolver, public BVDataPTAImpl virtual bool updateThreadCallGraph(const CallSiteToFunPtrMap&, NodePairSet&); /// Connect formal and actual parameters for indirect forksites - virtual void connectCaller2ForkedFunParams(const CallICFGNode* cs, const SVFFunction* F, + virtual void connectCaller2ForkedFunParams(const CallICFGNode* cs, const CallGraphNode* cgNode, NodePairSet& cpySrcNodes); /// Connect formal and actual parameters for indirect callsites - virtual void connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunction* F, + virtual void connectCaller2CalleeParams(const CallICFGNode* cs, const CallGraphNode* F, NodePairSet& cpySrcNodes); /// Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index 5bc080121..430e1518c 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -193,8 +193,9 @@ const ValVar* ThreadAPI::getActualParmAtForkSite(const CallICFGNode *inst) const return inst->getArgument(3); } -const SVFVar* ThreadAPI::getFormalParmOfForkedFun(const SVFFunction* F) const +const SVFVar* ThreadAPI::getFormalParmOfForkedFun(const CallGraphNode* cgNode) const { + const SVFFunction* F = cgNode->getFunction(); assert(PAG::getPAG()->hasFunArgsList(F) && "forked function has no args list!"); const SVFIR::SVFVarList& funArgList = PAG::getPAG()->getFunArgsList(F); // in pthread, forked functions are of type void *()(void *args) diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index 1c0e17de6..abbda8b54 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -33,6 +33,7 @@ #include "MemoryModel/PointsTo.h" #include "WPA/Andersen.h" #include "WPA/Steensgaard.h" +#include "Graphs/CallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -202,7 +203,7 @@ bool AndersenBase::updateCallGraph(const CallSiteToFunPtrMap& callsites) ecit = it->second.end(); cit != ecit; ++cit) { - connectCaller2CalleeParams(it->first, *cit, cpySrcNodes); + connectCaller2CalleeParams(it->first, (*cit)->getCallGraphNode(), cpySrcNodes); } } @@ -232,7 +233,7 @@ bool AndersenBase::updateThreadCallGraph(const CallSiteToFunPtrMap& callsites, ecit = it->second.end(); cit != ecit; ++cit) { - connectCaller2ForkedFunParams(it->first, *cit, cpySrcNodes); + connectCaller2ForkedFunParams(it->first, (*cit)->getCallGraphNode(), cpySrcNodes); } } return !newForkEdges.empty(); @@ -241,19 +242,19 @@ bool AndersenBase::updateThreadCallGraph(const CallSiteToFunPtrMap& callsites, /*! * Connect formal and actual parameters for indirect forksites */ -void AndersenBase::connectCaller2ForkedFunParams(const CallICFGNode* cs, const SVFFunction* F, +void AndersenBase::connectCaller2ForkedFunParams(const CallICFGNode* cs, const CallGraphNode* cgNode, NodePairSet& cpySrcNodes) { - assert(F); + assert(cgNode); DBOUT(DAndersen, outs() << "connect parameters from indirect forksite " << cs->valueOnlyToString() << " to forked function " - << *F << "\n"); + << *cgNode << "\n"); ThreadCallGraph *tdCallGraph = SVFUtil::dyn_cast(callgraph); const PAGNode *cs_arg = tdCallGraph->getThreadAPI()->getActualParmAtForkSite(cs); - const PAGNode *fun_arg = tdCallGraph->getThreadAPI()->getFormalParmOfForkedFun(F); + const PAGNode *fun_arg = tdCallGraph->getThreadAPI()->getFormalParmOfForkedFun(cgNode); if(cs_arg->isPointer() && fun_arg->isPointer()) { @@ -272,7 +273,7 @@ void AndersenBase::connectCaller2ForkedFunParams(const CallICFGNode* cs, const S // * Connect formal and actual parameters for indirect callsites // */ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, - const SVFFunction* F, NodePairSet &cpySrcNodes) + const CallGraphNode* F, NodePairSet &cpySrcNodes) { assert(F); @@ -281,15 +282,15 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, const CallICFGNode* callBlockNode = cs; const RetICFGNode* retBlockNode = cs->getRetICFGNode(); - if(SVFUtil::isHeapAllocExtFunViaRet(F) && pag->callsiteHasRet(retBlockNode)) + if(SVFUtil::isHeapAllocExtFunViaRet(F->getFunction()) && pag->callsiteHasRet(retBlockNode)) { heapAllocatorViaIndCall(cs,cpySrcNodes); } - if (pag->funHasRet(F) && pag->callsiteHasRet(retBlockNode)) + if (pag->funHasRet(F->getFunction()) && pag->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = pag->getFunRet(F); + const PAGNode* fun_return = pag->getFunRet(F->getFunction()); if (cs_return->isPointer() && fun_return->isPointer()) { NodeID dstrec = sccRepNode(cs_return->getId()); @@ -305,12 +306,12 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, } } - if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(F)) + if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(F->getFunction())) { // connect actual and formal param const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(F); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(F->getFunction()); //Go through the fixed parameters. DBOUT(DPAGBuild, outs() << " args:"); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); @@ -341,7 +342,7 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, //Any remaining actual args must be varargs. if (F->isVarArg()) { - NodeID vaF = sccRepNode(pag->getVarargNode(F)); + NodeID vaF = sccRepNode(pag->getVarargNode(F->getFunction())); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; csArgIt != csArgEit; ++csArgIt) { diff --git a/svf/lib/WPA/AndersenSCD.cpp b/svf/lib/WPA/AndersenSCD.cpp index 2e7538f0d..3e62d1364 100644 --- a/svf/lib/WPA/AndersenSCD.cpp +++ b/svf/lib/WPA/AndersenSCD.cpp @@ -283,7 +283,7 @@ bool AndersenSCD::updateCallGraph(const PointerAnalysis::CallSiteToFunPtrMap& ca { for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { - connectCaller2CalleeParams(it->first,*cit,cpySrcNodes); + connectCaller2CalleeParams(it->first,(*cit)->getCallGraphNode(),cpySrcNodes); } } From 25f302d7612f3d2e97b9806d414366770538c667 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 13:39:56 +1100 Subject: [PATCH 09/45] refactoring const SVFFunction* fun; --> CallGraphNode* fun; in PTACallGraphNode --- svf-llvm/lib/LLVMUtil.cpp | 2 +- svf/include/Graphs/PTACallGraph.h | 10 ++++++---- svf/include/Graphs/ThreadCallGraph.h | 8 ++++---- svf/lib/Graphs/PTACallGraph.cpp | 12 ++++++------ svf/lib/Graphs/ThreadCallGraph.cpp | 10 +++++----- svf/lib/MSSA/MemRegion.cpp | 4 ++-- svf/lib/MTA/LockAnalysis.cpp | 16 +++++++++------- svf/lib/MTA/MHP.cpp | 22 ++++++++++++---------- svf/lib/MTA/TCT.cpp | 8 ++++---- 9 files changed, 49 insertions(+), 43 deletions(-) diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index 174ec5927..82dfb97b1 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -757,7 +757,7 @@ const std::string SVFBaseNode::valueOnlyToString() const llvm::raw_string_ostream rawstr(str); if (const SVF::PTACallGraphNode* fun = SVFUtil::dyn_cast(this)) { - rawstr << "Function: " << fun->getFunction()->getName() << " "; + rawstr << "Function: " << fun->getCallNode()->getName() << " "; } else { diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 1cbc93351..952a2d723 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -33,6 +33,7 @@ #include "Graphs/GenericGraph.h" #include "SVFIR/SVFValue.h" #include "Graphs/ICFG.h" +#include "Graphs/CallGraph.h" #include namespace SVF @@ -175,11 +176,11 @@ typedef GenericNode GenericPTACallGraphNodeT class PTACallGraphNode : public GenericPTACallGraphNodeTy { private: - const SVFFunction* fun; + const CallGraphNode* fun; public: /// Constructor - PTACallGraphNode(NodeID i, const SVFFunction* f) : GenericPTACallGraphNodeTy(i,CallNodeKd), fun(f) + PTACallGraphNode(NodeID i, const CallGraphNode* f) : GenericPTACallGraphNodeTy(i,CallNodeKd), fun(f) { } @@ -190,7 +191,7 @@ class PTACallGraphNode : public GenericPTACallGraphNodeTy } /// Get function of this call node - inline const SVFFunction* getFunction() const + inline const CallGraphNode* getCallNode() const { return fun; } @@ -415,7 +416,8 @@ class PTACallGraph : public GenericPTACallGraphTy for (CallGraphEdgeSet::const_iterator it = getCallEdgeBegin(cs), eit = getCallEdgeEnd(cs); it != eit; ++it) { - callees.insert((*it)->getDstNode()->getFunction()); + callees.insert( + (*it)->getDstNode()->getCallNode()->getFunction()); } } } diff --git a/svf/include/Graphs/ThreadCallGraph.h b/svf/include/Graphs/ThreadCallGraph.h index ba48e0e9c..ec42f5266 100644 --- a/svf/include/Graphs/ThreadCallGraph.h +++ b/svf/include/Graphs/ThreadCallGraph.h @@ -73,8 +73,8 @@ class ThreadForkEdge: public PTACallGraphEdge std::stringstream rawstr(str); rawstr << "ThreadForkEdge "; rawstr << "CallSiteID: " << getCallSiteID(); - rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getFunction()->getName() << ")"; - rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getFunction()->getName() << ")"; + rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallNode()->getName() << ")"; + rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallNode()->getName() << ")"; return rawstr.str(); } @@ -113,8 +113,8 @@ class ThreadJoinEdge: public PTACallGraphEdge std::stringstream rawstr(str); rawstr << "ThreadJoinEdge "; rawstr << "CallSiteID: " << getCallSiteID(); - rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getFunction()->getName() << ")"; - rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getFunction()->getName() << ")"; + rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallNode()->getName() << ")"; + rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallNode()->getName() << ")"; return rawstr.str(); } diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 7d24d7644..c55917da5 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -91,7 +91,7 @@ bool PTACallGraphNode::isReachableFromProgEntry() const PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (SVFUtil::isProgEntryFunction(node->getFunction())) + if (SVFUtil::isProgEntryFunction(node->getCallNode()->getFunction())) return true; for (const_iterator it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) @@ -124,7 +124,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) for (const auto& item : other) { const CallGraphNode* cgn = item.second; - PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn->getFunction()); + PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn); addGNode(cgn->getId(),callGraphNode); funToCallGraphNodeMap[cgn->getFunction()] = callGraphNode; } @@ -137,7 +137,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) { PTACallGraphNode* src = getCallGraphNode(edge->getSrcID()); PTACallGraphNode* dst = getCallGraphNode(edge->getDstID()); - CallSiteID csId = addCallSite(cs, dst->getFunction()); + CallSiteID csId = addCallSite(cs, dst->getCallNode()->getFunction()); PTACallGraphEdge* newEdge = new PTACallGraphEdge(src,dst, PTACallGraphEdge::CallRetEdge,csId); newEdge->addDirectCallSite(cs); @@ -203,7 +203,7 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunc numOfResolvedIndCallEdge++; - CallSiteID csId = addCallSite(cs, callee->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId)) { @@ -307,7 +307,7 @@ bool PTACallGraph::isReachableBetweenFunctions(const SVFFunction* srcFn, const S PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (node->getFunction() == srcFn) + if (node->getCallNode()->getFunction() == srcFn) return true; for (CallGraphEdgeConstIter it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) @@ -364,7 +364,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits static std::string getNodeAttributes(PTACallGraphNode*node, PTACallGraph*) { - const SVFFunction* fun = node->getFunction(); + const SVFFunction* fun = node->getCallNode()->getFunction(); if (!SVFUtil::isExtCall(fun)) { return "shape=box"; diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 0d5d6848e..6d89ee9ec 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -131,11 +131,11 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) ->getCallGraphNode()->getFunction(); assert(forkee && "callee does not exist"); PTACallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()); - CallSiteID csId = addCallSite(cs, callee->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallNode()->getFunction() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addDirectCallSite(cs); @@ -156,11 +156,11 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunct PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()); PTACallGraphNode* callee = getCallGraphNode(calleefun); - CallSiteID csId = addCallSite(cs, callee->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallNode()->getFunction() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addInDirectCallSite(cs); @@ -197,7 +197,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) { - assert(cs->getCaller() == joinFunNode->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == joinFunNode->getCallNode()->getFunction() && "callee instruction not inside caller??"); ThreadJoinEdge* edge = new ThreadJoinEdge(joinFunNode,threadRoutineFunNode,csId); edge->addDirectCallSite(cs); diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 7ae7ebfb0..e85ba4eb3 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -649,7 +649,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()->getFunction()); if(modrefchanged) worklist.push(edge->getSrcID()); } @@ -659,7 +659,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getFunction()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()->getFunction()); if(modrefchanged) worklist.push(edge->getSrcID()); } diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index abbec8792..783aa9097 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -124,7 +124,7 @@ void LockAnalysis::buildCandidateFuncSetforLock() while (!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - lockcandidateFuncSet.insert(node->getFunction()); + lockcandidateFuncSet.insert(node->getCallNode()->getFunction()); for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -274,7 +274,7 @@ void LockAnalysis::collectCxtLock() CxtLockProc clp = popFromCTPWorkList(); PTACallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc()); // lzh TODO. - if (!isLockCandidateFun(cgNode->getFunction())) + if (!isLockCandidateFun(cgNode->getCallNode()->getFunction())) continue; for (PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++) @@ -316,7 +316,7 @@ void LockAnalysis::handleCallRelation(CxtLockProc& clp, const PTACallGraphEdge* addCxtLock(cxt,curNode); return; } - const SVFFunction* svfcallee = cgEdge->getDstNode()->getFunction(); + const SVFFunction* svfcallee = cgEdge->getDstNode()->getCallNode()->getFunction(); pushCxt(cxt, SVFUtil::cast(curNode), svfcallee); CxtLockProc newclp(cxt, svfcallee); @@ -414,7 +414,7 @@ void LockAnalysis::handleFork(const CxtStmt& cts) for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = getTCG()->getForkEdgeBegin(call), ecgIt = getTCG()->getForkEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); CallStrCxt newCxt = curCxt; pushCxt(newCxt,call,svfcallee); const ICFGNode* svfInst = svfcallee->getEntryBlock()->front(); @@ -436,7 +436,7 @@ void LockAnalysis::handleCall(const CxtStmt& cts) for (PTACallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); if (SVFUtil::isExtCall(svfcallee)) continue; CallStrCxt newCxt = curCxt; @@ -467,7 +467,8 @@ void LockAnalysis::handleRet(const CxtStmt& cts) { CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; - if (matchCxt(newCxt, SVFUtil::cast(inst), curFunNode->getFunction())) + if (matchCxt(newCxt, SVFUtil::cast(inst), + curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { @@ -484,7 +485,8 @@ void LockAnalysis::handleRet(const CxtStmt& cts) { CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; - if (matchCxt(newCxt, SVFUtil::cast(inst), curFunNode->getFunction())) + if (matchCxt(newCxt, SVFUtil::cast(inst), + curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index b104a6d25..a6a1cc6c1 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -188,7 +188,7 @@ void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) PTACallGraphNode* node = tcg->getCallGraphNode(curfun); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { - const SVFFunction* callee = (*nit)->getDstNode()->getFunction(); + const SVFFunction* callee = (*nit)->getDstNode()->getCallNode()->getFunction(); if (!isExtCall(callee)) { const ICFGNode* calleeInst = callee->getEntryBlock()->front(); @@ -216,7 +216,7 @@ void MHP::handleFork(const CxtThreadStmt& cts, NodeID rootTid) ecgIt = tcg->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfroutine = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* svfroutine = (*cgIt)->getDstNode()->getCallNode()->getFunction(); CallStrCxt newCxt = curCxt; pushCxt(newCxt, cbn, svfroutine); const ICFGNode* stmt = svfroutine->getEntryBlock()->front(); @@ -301,7 +301,7 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); if (isExtCall(svfcallee)) continue; CallStrCxt newCxt = curCxt; @@ -329,7 +329,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getFunction())) + if (matchCxt(newCxt, *cit, curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -346,7 +346,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getFunction())) + if (matchCxt(newCxt, *cit, curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -529,7 +529,7 @@ bool MHP::isConnectedfromMain(const SVFFunction* fun) while (!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - if ("main" == node->getFunction()->getName()) + if ("main" == node->getCallNode()->getName()) return true; for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++) { @@ -796,7 +796,7 @@ void ForkJoinAnalysis::handleFork(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* callee = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* callee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); CallStrCxt newCxt = curCxt; pushCxt(newCxt, cbn, callee); CxtThread ct(newCxt, call); @@ -887,7 +887,7 @@ void ForkJoinAnalysis::handleCall(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getCallEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getFunction(); + const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); if (isExtCall(svfcallee)) continue; CallStrCxt newCxt = curCxt; @@ -916,7 +916,8 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) { CallStrCxt newCxt = curCxt; const ICFGNode* curNode = (*cit); - if (matchCxt(newCxt, SVFUtil::cast(curNode), curFunNode->getFunction())) + if (matchCxt(newCxt, SVFUtil::cast(curNode), + curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { @@ -935,7 +936,8 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* curNode = (*cit); - if (matchCxt(newCxt, SVFUtil::cast(curNode), curFunNode->getFunction())) + if (matchCxt(newCxt, SVFUtil::cast(curNode), + curFunNode->getCallNode()->getFunction())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index 752654176..bdfe54e26 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -140,7 +140,7 @@ void TCT::markRelProcs() for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++) { const PTACallGraphNode* forkeeNode = (*nit)->getDstNode(); - candidateFuncSet.insert(forkeeNode->getFunction()); + candidateFuncSet.insert(forkeeNode->getCallNode()->getFunction()); } } @@ -168,7 +168,7 @@ void TCT::markRelProcs(const SVFFunction* svffun) while(!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - candidateFuncSet.insert(node->getFunction()); + candidateFuncSet.insert(node->getCallNode()->getFunction()); for(PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit!=neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -244,7 +244,7 @@ void TCT::collectMultiForkedThreads() */ void TCT::handleCallRelation(CxtThreadProc& ctp, const PTACallGraphEdge* cgEdge, const CallICFGNode* cs) { - const SVFFunction* callee = cgEdge->getDstNode()->getFunction(); + const SVFFunction* callee = cgEdge->getDstNode()->getCallNode()->getFunction(); CallStrCxt cxt(ctp.getContext()); CallStrCxt oldCxt = cxt; @@ -407,7 +407,7 @@ void TCT::build() { CxtThreadProc ctp = popFromCTPWorkList(); PTACallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc()); - if(isCandidateFun(cgNode->getFunction()) == false) + if(isCandidateFun(cgNode->getCallNode()->getFunction()) == false) continue; for(PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++) From 0bb927f86e5a3b994c6d784521945e8c0ff57462 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 14:02:24 +1100 Subject: [PATCH 10/45] refactoring Map FunToCallGraphNodeMap; --> Map FunToCallGraphNodeMap; in PTACallGraphNode --- svf/include/DDA/DDAVFSolver.h | 2 +- svf/include/Graphs/PTACallGraph.h | 5 +++-- svf/include/MemoryModel/PointerAnalysis.h | 6 +++--- svf/lib/DDA/DDAPass.cpp | 8 ++++---- svf/lib/Graphs/PTACallGraph.cpp | 16 ++++++++-------- svf/lib/Graphs/ThreadCallGraph.cpp | 17 ++++++++--------- svf/lib/MSSA/MemRegion.cpp | 2 +- svf/lib/MTA/LockAnalysis.cpp | 12 ++++++------ svf/lib/MTA/MHP.cpp | 8 ++++---- svf/lib/MTA/TCT.cpp | 16 ++++++++-------- svf/lib/MemoryModel/PointerAnalysis.cpp | 2 +- 11 files changed, 47 insertions(+), 47 deletions(-) diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index f76e73b70..080866a9f 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -477,7 +477,7 @@ class DDAVFSolver { if(const SVFFunction* svffun = _pag->getGNode(id)->getFunction()) { - return _callGraphSCC->isInCycle(_callGraph->getCallGraphNode(svffun)->getId()); + return _callGraphSCC->isInCycle(_callGraph->getCallGraphNode(svffun->getCallGraphNode())->getId()); } } return false; diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 952a2d723..dc42ed96a 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -239,7 +239,7 @@ class PTACallGraph : public GenericPTACallGraphTy public: typedef PTACallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; - typedef Map FunToCallGraphNodeMap; + typedef Map FunToCallGraphNodeMap; typedef Map CallInstToCallGraphEdgesMap; typedef std::pair CallSitePair; typedef Map CallSiteToIdMap; @@ -358,7 +358,8 @@ class PTACallGraph : public GenericPTACallGraphTy { return getGNode(id); } - inline PTACallGraphNode* getCallGraphNode(const SVFFunction* fun) const + + inline PTACallGraphNode* getCallGraphNode(const CallGraphNode* fun) const { FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun); assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!"); diff --git a/svf/include/MemoryModel/PointerAnalysis.h b/svf/include/MemoryModel/PointerAnalysis.h index 62b402ccf..5b3b135c8 100644 --- a/svf/include/MemoryModel/PointerAnalysis.h +++ b/svf/include/MemoryModel/PointerAnalysis.h @@ -398,13 +398,13 @@ class PointerAnalysis /// Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SCC on the SVFG. inline bool inSameCallGraphSCC(const SVFFunction* fun1,const SVFFunction* fun2) { - const PTACallGraphNode* src = callgraph->getCallGraphNode(fun1); - const PTACallGraphNode* dst = callgraph->getCallGraphNode(fun2); + const PTACallGraphNode* src = callgraph->getCallGraphNode(fun1->getCallGraphNode()); + const PTACallGraphNode* dst = callgraph->getCallGraphNode(fun2->getCallGraphNode()); return (getCallGraphSCCRepNode(src->getId()) == getCallGraphSCCRepNode(dst->getId())); } inline bool isInRecursion(const SVFFunction* fun) const { - return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun)->getId()); + return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun->getCallGraphNode())->getId()); } /// Whether a local variable is in function recursions bool isLocalVarInRecursiveFun(NodeID id) const; diff --git a/svf/lib/DDA/DDAPass.cpp b/svf/lib/DDA/DDAPass.cpp index 886df583c..eb61a23e2 100644 --- a/svf/lib/DDA/DDAPass.cpp +++ b/svf/lib/DDA/DDAPass.cpp @@ -239,8 +239,8 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(srcFun && dstFun) { - NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun)->getId(); - NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun)->getId(); + NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun->getCallGraphNode())->getId(); + NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun->getCallGraphNode())->getId(); insensitvefunPairs.insert(std::make_pair(src,dst)); insensitvefunPairs.insert(std::make_pair(dst,src)); } @@ -266,8 +266,8 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(srcFun && dstFun) { - NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun)->getId(); - NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun)->getId(); + NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun->getCallGraphNode())->getId(); + NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun->getCallGraphNode())->getId(); if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end()) insensitveEdges.insert(edge); else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end()) diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index c55917da5..27b4a5b2a 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -126,7 +126,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) const CallGraphNode* cgn = item.second; PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn); addGNode(cgn->getId(),callGraphNode); - funToCallGraphNodeMap[cgn->getFunction()] = callGraphNode; + funToCallGraphNodeMap[cgn] = callGraphNode; } /// copy edges @@ -198,8 +198,8 @@ PTACallGraphEdge* PTACallGraph::getGraphEdge(PTACallGraphNode* src, void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) { - PTACallGraphNode* caller = getCallGraphNode(callerFun); - PTACallGraphNode* callee = getCallGraphNode(calleeFun); + PTACallGraphNode* caller = getCallGraphNode(callerFun->getCallGraphNode()); + PTACallGraphNode* callee = getCallGraphNode(calleeFun->getCallGraphNode()); numOfResolvedIndCallEdge++; @@ -219,7 +219,7 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunc */ void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee); + PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -241,7 +241,7 @@ void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTAC */ void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee); + PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -258,7 +258,7 @@ void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTAC */ void PTACallGraph::getIndCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee); + PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -284,7 +284,7 @@ void PTACallGraph::verifyCallGraph() { const CallICFGNode* cs = it->first; const SVFFunction* func = cs->getCaller(); - if (getCallGraphNode(func)->isReachableFromProgEntry() == false) + if (getCallGraphNode(func->getCallGraphNode())->isReachableFromProgEntry() == false) writeWrnMsg(func->getName() + " has indirect call site but not reachable from main"); } } @@ -295,7 +295,7 @@ void PTACallGraph::verifyCallGraph() */ bool PTACallGraph::isReachableBetweenFunctions(const SVFFunction* srcFn, const SVFFunction* dstFn) const { - PTACallGraphNode* dstNode = getCallGraphNode(dstFn); + PTACallGraphNode* dstNode = getCallGraphNode(dstFn->getCallGraphNode()); std::stack nodeStack; NodeBS visitedNodes; diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 6d89ee9ec..0383b31f6 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -126,11 +126,11 @@ void ThreadCallGraph::updateJoinEdge(PointerAnalysis* pta) bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) { - PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()); + PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()->getCallGraphNode()); const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) ->getCallGraphNode()->getFunction(); assert(forkee && "callee does not exist"); - PTACallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()); + PTACallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()->getCallGraphNode()); CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) @@ -153,8 +153,8 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) */ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunction* calleefun) { - PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()); - PTACallGraphNode* callee = getCallGraphNode(calleefun); + PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()->getCallGraphNode()); + PTACallGraphNode* callee = getCallGraphNode(calleefun->getCallGraphNode()); CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); @@ -182,18 +182,17 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunct void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet& forkset) { - PTACallGraphNode* joinFunNode = getCallGraphNode(cs->getCaller()); + PTACallGraphNode* joinFunNode = getCallGraphNode(cs->getCaller()->getCallGraphNode()); for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it) { - const SVFFunction* threadRoutineFun = + const CallGraphNode* threadRoutineFun = SVFUtil::dyn_cast(tdAPI->getForkedFun(*it)) - ->getCallGraphNode() - ->getFunction(); + ->getCallGraphNode(); assert(threadRoutineFun && "thread routine function does not exist"); PTACallGraphNode* threadRoutineFunNode = getCallGraphNode(threadRoutineFun); - CallSiteID csId = addCallSite(cs, threadRoutineFun); + CallSiteID csId = addCallSite(cs, threadRoutineFun->getFunction()); if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) { diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index e85ba4eb3..6e1be0e5d 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -592,7 +592,7 @@ bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const if(svffun!=curFun) return true; else - return callGraphSCC->isInCycle(callGraph->getCallGraphNode(svffun)->getId()); + return callGraphSCC->isInCycle(callGraph->getCallGraphNode(svffun->getCallGraphNode())->getId()); } } diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 783aa9097..60e899d5d 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -104,7 +104,7 @@ void LockAnalysis::buildCandidateFuncSetforLock() for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it) { const SVFFunction* fun=(*it)->getFun(); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun); + PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -114,7 +114,7 @@ void LockAnalysis::buildCandidateFuncSetforLock() for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it) { const SVFFunction* fun = (*it)->getFun(); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun); + PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -272,7 +272,7 @@ void LockAnalysis::collectCxtLock() while (!clpList.empty()) { CxtLockProc clp = popFromCTPWorkList(); - PTACallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc()); + PTACallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc()->getCallGraphNode()); // lzh TODO. if (!isLockCandidateFun(cgNode->getCallNode()->getFunction())) continue; @@ -455,7 +455,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curInst = cts.getStmt(); const CallStrCxt& curCxt = cts.getContext(); const SVFFunction* svffun = curInst->getFun(); - PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(svffun); + PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(svffun->getCallGraphNode()); for (PTACallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it) { @@ -528,7 +528,7 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF // if (isLockCandidateFun(caller) == false) // return; - if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false) + if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller->getCallGraphNode()), getTCG()->getCallGraphNode(callee->getCallGraphNode())) == false) { tct->pushCxt(cxt,csId); DBOUT(DMTA, tct->dumpCxt(cxt)); @@ -548,7 +548,7 @@ bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVF if (cxt.empty()) return true; - if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller), getTCG()->getCallGraphNode(callee)) == false) + if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller->getCallGraphNode()), getTCG()->getCallGraphNode(callee->getCallGraphNode())) == false) { if (cxt.back() == csId) cxt.pop_back(); diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index a6a1cc6c1..ba5118eb8 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -185,7 +185,7 @@ void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) const SVFFunction* curfun = curInst->getFun(); assert((curInst == curfun->getEntryBlock()->front()) && "curInst is not the entry of non candidate function."); const CallStrCxt& curCxt = cts.getContext(); - PTACallGraphNode* node = tcg->getCallGraphNode(curfun); + PTACallGraphNode* node = tcg->getCallGraphNode(curfun->getCallGraphNode()); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { const SVFFunction* callee = (*nit)->getDstNode()->getCallNode()->getFunction(); @@ -319,7 +319,7 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) */ void MHP::handleRet(const CxtThreadStmt& cts) { - PTACallGraphNode* curFunNode = tcg->getCallGraphNode(cts.getStmt()->getFun()); + PTACallGraphNode* curFunNode = tcg->getCallGraphNode(cts.getStmt()->getFun()->getCallGraphNode()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) @@ -521,7 +521,7 @@ bool MHP::isHBPair(NodeID tid1, NodeID tid2) bool MHP::isConnectedfromMain(const SVFFunction* fun) { - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun); + PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); FIFOWorkList worklist; TCT::PTACGNodeSet visited; worklist.push(cgnode); @@ -905,7 +905,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curInst = cts.getStmt(); const CallStrCxt& curCxt = cts.getContext(); - PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(curInst->getFun()); + PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(curInst->getFun()->getCallGraphNode()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index bdfe54e26..e0af6cf4c 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -55,7 +55,7 @@ bool TCT::isInLoopInstruction(const ICFGNode* inst) { const ICFGNode* inst = worklist.pop(); insts.insert(inst); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(inst->getFun()); + PTACallGraphNode* cgnode = tcg->getCallGraphNode(inst->getFun()->getCallGraphNode()); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(), @@ -99,10 +99,10 @@ bool TCT::isInRecursion(const ICFGNode* inst) const { const SVFFunction* svffun = worklist.pop(); visits.insert(svffun); - if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun)->getId())) + if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun->getCallGraphNode())->getId())) return true; - const PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun); + const PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun->getCallGraphNode()); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { @@ -160,7 +160,7 @@ void TCT::markRelProcs() */ void TCT::markRelProcs(const SVFFunction* svffun) { - PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun); + PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun->getCallGraphNode()); FIFOWorkList worklist; PTACGNodeSet visited; worklist.push(cgnode); @@ -192,7 +192,7 @@ void TCT::collectEntryFunInCallGraph() const SVFFunction* fun = item.second->getFunction(); if (SVFUtil::isExtCall(fun)) continue; - PTACallGraphNode* node = tcg->getCallGraphNode(fun); + PTACallGraphNode* node = tcg->getCallGraphNode(fun->getCallGraphNode()); if (!node->hasIncomingEdge()) { entryFuncSet.insert(fun); @@ -406,7 +406,7 @@ void TCT::build() while(!ctpList.empty()) { CxtThreadProc ctp = popFromCTPWorkList(); - PTACallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc()); + PTACallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc()->getCallGraphNode()); if(isCandidateFun(cgNode->getCallNode()->getFunction()) == false) continue; @@ -452,7 +452,7 @@ void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* if(isCandidateFun(caller) == false) return; - if(inSameCallGraphSCC(tcg->getCallGraphNode(caller),tcg->getCallGraphNode(callee))==false) + if(inSameCallGraphSCC(tcg->getCallGraphNode(caller->getCallGraphNode()),tcg->getCallGraphNode(callee->getCallGraphNode()))==false) { pushCxt(cxt,csId); DBOUT(DMTA,dumpCxt(cxt)); @@ -477,7 +477,7 @@ bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* if(cxt.empty()) return true; - if(inSameCallGraphSCC(tcg->getCallGraphNode(caller),tcg->getCallGraphNode(callee))==false) + if(inSameCallGraphSCC(tcg->getCallGraphNode(caller->getCallGraphNode()),tcg->getCallGraphNode(callee->getCallGraphNode()))==false) { if(cxt.back() == csId) cxt.pop_back(); diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index a0e9e319a..85739a36e 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -139,7 +139,7 @@ bool PointerAnalysis::isLocalVarInRecursiveFun(NodeID id) const { if(const SVFFunction* svffun = pag->getGNode(id)->getFunction()) { - return callGraphSCC->isInCycle(getCallGraph()->getCallGraphNode(svffun)->getId()); + return callGraphSCC->isInCycle(getCallGraph()->getCallGraphNode(svffun->getCallGraphNode())->getId()); } } return false; From 81206eaf7664ef5f1c6e44fe0c5face8725f9625 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 14:10:37 +1100 Subject: [PATCH 11/45] rename FunToPTACallGraphNodeMap funToPtaCallGraphNodeMap; --> CgNodeToPTACallGraphNodeMap cgNodeToPtaCallGraphNodeMap; in PTACallGraphNode --- svf/include/DDA/DDAVFSolver.h | 3 ++- svf/include/Graphs/PTACallGraph.h | 11 +++++----- svf/include/MemoryModel/PointerAnalysis.h | 9 +++++--- svf/lib/DDA/DDAPass.cpp | 16 ++++++++++---- svf/lib/Graphs/PTACallGraph.cpp | 21 +++++++++++------- svf/lib/Graphs/ThreadCallGraph.cpp | 18 ++++++++++------ svf/lib/MSSA/MemRegion.cpp | 3 ++- svf/lib/MTA/LockAnalysis.cpp | 20 +++++++++++------ svf/lib/MTA/MHP.cpp | 12 +++++++---- svf/lib/MTA/TCT.cpp | 26 ++++++++++++++++------- svf/lib/MemoryModel/PointerAnalysis.cpp | 4 +++- 11 files changed, 96 insertions(+), 47 deletions(-) diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index 080866a9f..4abec7c9e 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -477,7 +477,8 @@ class DDAVFSolver { if(const SVFFunction* svffun = _pag->getGNode(id)->getFunction()) { - return _callGraphSCC->isInCycle(_callGraph->getCallGraphNode(svffun->getCallGraphNode())->getId()); + return _callGraphSCC->isInCycle( + _callGraph->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); } } return false; diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index dc42ed96a..e3959b31c 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -239,7 +239,7 @@ class PTACallGraph : public GenericPTACallGraphTy public: typedef PTACallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; - typedef Map FunToCallGraphNodeMap; + typedef Map CgNodeToPTACallGraphNodeMap; typedef Map CallInstToCallGraphEdgesMap; typedef std::pair CallSitePair; typedef Map CallSiteToIdMap; @@ -264,7 +264,7 @@ class PTACallGraph : public GenericPTACallGraphTy static CallSiteID totalCallSiteNum; ///< CallSiteIDs, start from 1; protected: - FunToCallGraphNodeMap funToCallGraphNodeMap; ///< Call Graph node map + CgNodeToPTACallGraphNodeMap cgNodeToPtaCallGraphNodeMap; ///< Call Graph node map CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap; ///< Map a call instruction to its corresponding call edges NodeID callGraphNodeNum; @@ -359,10 +359,11 @@ class PTACallGraph : public GenericPTACallGraphTy return getGNode(id); } - inline PTACallGraphNode* getCallGraphNode(const CallGraphNode* fun) const + inline PTACallGraphNode* getPTACallGraphNode(const CallGraphNode* fun) const { - FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun); - assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!"); + CgNodeToPTACallGraphNodeMap::const_iterator it = + cgNodeToPtaCallGraphNodeMap.find(fun); + assert(it!= cgNodeToPtaCallGraphNodeMap.end() && "call graph node not found!!"); return it->second; } diff --git a/svf/include/MemoryModel/PointerAnalysis.h b/svf/include/MemoryModel/PointerAnalysis.h index 5b3b135c8..559a8a27b 100644 --- a/svf/include/MemoryModel/PointerAnalysis.h +++ b/svf/include/MemoryModel/PointerAnalysis.h @@ -398,13 +398,16 @@ class PointerAnalysis /// Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SCC on the SVFG. inline bool inSameCallGraphSCC(const SVFFunction* fun1,const SVFFunction* fun2) { - const PTACallGraphNode* src = callgraph->getCallGraphNode(fun1->getCallGraphNode()); - const PTACallGraphNode* dst = callgraph->getCallGraphNode(fun2->getCallGraphNode()); + const PTACallGraphNode* src = + callgraph->getPTACallGraphNode(fun1->getCallGraphNode()); + const PTACallGraphNode* dst = + callgraph->getPTACallGraphNode(fun2->getCallGraphNode()); return (getCallGraphSCCRepNode(src->getId()) == getCallGraphSCCRepNode(dst->getId())); } inline bool isInRecursion(const SVFFunction* fun) const { - return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun->getCallGraphNode())->getId()); + return callGraphSCC->isInCycle( + callgraph->getPTACallGraphNode(fun->getCallGraphNode())->getId()); } /// Whether a local variable is in function recursions bool isLocalVarInRecursiveFun(NodeID id) const; diff --git a/svf/lib/DDA/DDAPass.cpp b/svf/lib/DDA/DDAPass.cpp index eb61a23e2..38bdc1804 100644 --- a/svf/lib/DDA/DDAPass.cpp +++ b/svf/lib/DDA/DDAPass.cpp @@ -239,8 +239,12 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(srcFun && dstFun) { - NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun->getCallGraphNode())->getId(); - NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun->getCallGraphNode())->getId(); + NodeID src = pta->getCallGraph() + ->getPTACallGraphNode( + srcFun->getCallGraphNode())->getId(); + NodeID dst = pta->getCallGraph() + ->getPTACallGraphNode( + dstFun->getCallGraphNode())->getId(); insensitvefunPairs.insert(std::make_pair(src,dst)); insensitvefunPairs.insert(std::make_pair(dst,src)); } @@ -266,8 +270,12 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(srcFun && dstFun) { - NodeID src = pta->getCallGraph()->getCallGraphNode(srcFun->getCallGraphNode())->getId(); - NodeID dst = pta->getCallGraph()->getCallGraphNode(dstFun->getCallGraphNode())->getId(); + NodeID src = + pta->getCallGraph() + ->getPTACallGraphNode(srcFun->getCallGraphNode())->getId(); + NodeID dst = + pta->getCallGraph() + ->getPTACallGraphNode(dstFun->getCallGraphNode())->getId(); if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end()) insensitveEdges.insert(edge); else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end()) diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 27b4a5b2a..9e5ffb455 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -126,7 +126,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) const CallGraphNode* cgn = item.second; PTACallGraphNode* callGraphNode = new PTACallGraphNode(cgn->getId(), cgn); addGNode(cgn->getId(),callGraphNode); - funToCallGraphNodeMap[cgn] = callGraphNode; + cgNodeToPtaCallGraphNodeMap[cgn] = callGraphNode; } /// copy edges @@ -198,8 +198,10 @@ PTACallGraphEdge* PTACallGraph::getGraphEdge(PTACallGraphNode* src, void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) { - PTACallGraphNode* caller = getCallGraphNode(callerFun->getCallGraphNode()); - PTACallGraphNode* callee = getCallGraphNode(calleeFun->getCallGraphNode()); + PTACallGraphNode* caller = + getPTACallGraphNode(callerFun->getCallGraphNode()); + PTACallGraphNode* callee = + getPTACallGraphNode(calleeFun->getCallGraphNode()); numOfResolvedIndCallEdge++; @@ -219,7 +221,8 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunc */ void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); + PTACallGraphNode* callGraphNode = + getPTACallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -241,7 +244,8 @@ void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTAC */ void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); + PTACallGraphNode* callGraphNode = + getPTACallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -258,7 +262,8 @@ void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTAC */ void PTACallGraph::getIndCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) { - PTACallGraphNode* callGraphNode = getCallGraphNode(callee->getCallGraphNode()); + PTACallGraphNode* callGraphNode = + getPTACallGraphNode(callee->getCallGraphNode()); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -284,7 +289,7 @@ void PTACallGraph::verifyCallGraph() { const CallICFGNode* cs = it->first; const SVFFunction* func = cs->getCaller(); - if (getCallGraphNode(func->getCallGraphNode())->isReachableFromProgEntry() == false) + if (getPTACallGraphNode(func->getCallGraphNode())->isReachableFromProgEntry() == false) writeWrnMsg(func->getName() + " has indirect call site but not reachable from main"); } } @@ -295,7 +300,7 @@ void PTACallGraph::verifyCallGraph() */ bool PTACallGraph::isReachableBetweenFunctions(const SVFFunction* srcFn, const SVFFunction* dstFn) const { - PTACallGraphNode* dstNode = getCallGraphNode(dstFn->getCallGraphNode()); + PTACallGraphNode* dstNode = getPTACallGraphNode(dstFn->getCallGraphNode()); std::stack nodeStack; NodeBS visitedNodes; diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 0383b31f6..0c5a7d398 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -126,11 +126,13 @@ void ThreadCallGraph::updateJoinEdge(PointerAnalysis* pta) bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) { - PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()->getCallGraphNode()); + PTACallGraphNode* caller = + getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) ->getCallGraphNode()->getFunction(); assert(forkee && "callee does not exist"); - PTACallGraphNode* callee = getCallGraphNode(forkee->getDefFunForMultipleModule()->getCallGraphNode()); + PTACallGraphNode* callee = getPTACallGraphNode( + forkee->getDefFunForMultipleModule()->getCallGraphNode()); CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) @@ -153,8 +155,10 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) */ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunction* calleefun) { - PTACallGraphNode* caller = getCallGraphNode(cs->getCaller()->getCallGraphNode()); - PTACallGraphNode* callee = getCallGraphNode(calleefun->getCallGraphNode()); + PTACallGraphNode* caller = + getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); + PTACallGraphNode* callee = + getPTACallGraphNode(calleefun->getCallGraphNode()); CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); @@ -182,7 +186,8 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunct void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet& forkset) { - PTACallGraphNode* joinFunNode = getCallGraphNode(cs->getCaller()->getCallGraphNode()); + PTACallGraphNode* joinFunNode = + getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it) { @@ -191,7 +196,8 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet SVFUtil::dyn_cast(tdAPI->getForkedFun(*it)) ->getCallGraphNode(); assert(threadRoutineFun && "thread routine function does not exist"); - PTACallGraphNode* threadRoutineFunNode = getCallGraphNode(threadRoutineFun); + PTACallGraphNode* threadRoutineFunNode = + getPTACallGraphNode(threadRoutineFun); CallSiteID csId = addCallSite(cs, threadRoutineFun->getFunction()); if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 6e1be0e5d..6915a838b 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -592,7 +592,8 @@ bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const if(svffun!=curFun) return true; else - return callGraphSCC->isInCycle(callGraph->getCallGraphNode(svffun->getCallGraphNode())->getId()); + return callGraphSCC->isInCycle( + callGraph->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); } } diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 60e899d5d..c3c9a8773 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -104,7 +104,8 @@ void LockAnalysis::buildCandidateFuncSetforLock() for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it) { const SVFFunction* fun=(*it)->getFun(); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); + PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(fun->getCallGraphNode()); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -114,7 +115,8 @@ void LockAnalysis::buildCandidateFuncSetforLock() for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it) { const SVFFunction* fun = (*it)->getFun(); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); + PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(fun->getCallGraphNode()); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -272,7 +274,8 @@ void LockAnalysis::collectCxtLock() while (!clpList.empty()) { CxtLockProc clp = popFromCTPWorkList(); - PTACallGraphNode* cgNode = getTCG()->getCallGraphNode(clp.getProc()->getCallGraphNode()); + PTACallGraphNode* cgNode = + getTCG()->getPTACallGraphNode(clp.getProc()->getCallGraphNode()); // lzh TODO. if (!isLockCandidateFun(cgNode->getCallNode()->getFunction())) continue; @@ -455,7 +458,8 @@ void LockAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curInst = cts.getStmt(); const CallStrCxt& curCxt = cts.getContext(); const SVFFunction* svffun = curInst->getFun(); - PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(svffun->getCallGraphNode()); + PTACallGraphNode* curFunNode = + getTCG()->getPTACallGraphNode(svffun->getCallGraphNode()); for (PTACallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it) { @@ -528,7 +532,9 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF // if (isLockCandidateFun(caller) == false) // return; - if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller->getCallGraphNode()), getTCG()->getCallGraphNode(callee->getCallGraphNode())) == false) + if (tct->inSameCallGraphSCC( + getTCG()->getPTACallGraphNode(svfcaller->getCallGraphNode()), + getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) { tct->pushCxt(cxt,csId); DBOUT(DMTA, tct->dumpCxt(cxt)); @@ -548,7 +554,9 @@ bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVF if (cxt.empty()) return true; - if (tct->inSameCallGraphSCC(getTCG()->getCallGraphNode(svfcaller->getCallGraphNode()), getTCG()->getCallGraphNode(callee->getCallGraphNode())) == false) + if (tct->inSameCallGraphSCC( + getTCG()->getPTACallGraphNode(svfcaller->getCallGraphNode()), + getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) { if (cxt.back() == csId) cxt.pop_back(); diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index ba5118eb8..7cfc7c375 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -185,7 +185,8 @@ void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) const SVFFunction* curfun = curInst->getFun(); assert((curInst == curfun->getEntryBlock()->front()) && "curInst is not the entry of non candidate function."); const CallStrCxt& curCxt = cts.getContext(); - PTACallGraphNode* node = tcg->getCallGraphNode(curfun->getCallGraphNode()); + PTACallGraphNode* node = + tcg->getPTACallGraphNode(curfun->getCallGraphNode()); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { const SVFFunction* callee = (*nit)->getDstNode()->getCallNode()->getFunction(); @@ -319,7 +320,8 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) */ void MHP::handleRet(const CxtThreadStmt& cts) { - PTACallGraphNode* curFunNode = tcg->getCallGraphNode(cts.getStmt()->getFun()->getCallGraphNode()); + PTACallGraphNode* curFunNode = + tcg->getPTACallGraphNode(cts.getStmt()->getFun()->getCallGraphNode()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) @@ -521,7 +523,8 @@ bool MHP::isHBPair(NodeID tid1, NodeID tid2) bool MHP::isConnectedfromMain(const SVFFunction* fun) { - PTACallGraphNode* cgnode = tcg->getCallGraphNode(fun->getCallGraphNode()); + PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(fun->getCallGraphNode()); FIFOWorkList worklist; TCT::PTACGNodeSet visited; worklist.push(cgnode); @@ -905,7 +908,8 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curInst = cts.getStmt(); const CallStrCxt& curCxt = cts.getContext(); - PTACallGraphNode* curFunNode = getTCG()->getCallGraphNode(curInst->getFun()->getCallGraphNode()); + PTACallGraphNode* curFunNode = + getTCG()->getPTACallGraphNode(curInst->getFun()->getCallGraphNode()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index e0af6cf4c..f04416cf9 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -55,7 +55,8 @@ bool TCT::isInLoopInstruction(const ICFGNode* inst) { const ICFGNode* inst = worklist.pop(); insts.insert(inst); - PTACallGraphNode* cgnode = tcg->getCallGraphNode(inst->getFun()->getCallGraphNode()); + PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(inst->getFun()->getCallGraphNode()); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(), @@ -99,10 +100,12 @@ bool TCT::isInRecursion(const ICFGNode* inst) const { const SVFFunction* svffun = worklist.pop(); visits.insert(svffun); - if(tcgSCC->isInCycle(tcg->getCallGraphNode(svffun->getCallGraphNode())->getId())) + if(tcgSCC->isInCycle( + tcg->getPTACallGraphNode(svffun->getCallGraphNode())->getId())) return true; - const PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun->getCallGraphNode()); + const PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(svffun->getCallGraphNode()); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { @@ -160,7 +163,8 @@ void TCT::markRelProcs() */ void TCT::markRelProcs(const SVFFunction* svffun) { - PTACallGraphNode* cgnode = tcg->getCallGraphNode(svffun->getCallGraphNode()); + PTACallGraphNode* cgnode = + tcg->getPTACallGraphNode(svffun->getCallGraphNode()); FIFOWorkList worklist; PTACGNodeSet visited; worklist.push(cgnode); @@ -192,7 +196,8 @@ void TCT::collectEntryFunInCallGraph() const SVFFunction* fun = item.second->getFunction(); if (SVFUtil::isExtCall(fun)) continue; - PTACallGraphNode* node = tcg->getCallGraphNode(fun->getCallGraphNode()); + PTACallGraphNode* node = + tcg->getPTACallGraphNode(fun->getCallGraphNode()); if (!node->hasIncomingEdge()) { entryFuncSet.insert(fun); @@ -406,7 +411,8 @@ void TCT::build() while(!ctpList.empty()) { CxtThreadProc ctp = popFromCTPWorkList(); - PTACallGraphNode* cgNode = tcg->getCallGraphNode(ctp.getProc()->getCallGraphNode()); + PTACallGraphNode* cgNode = + tcg->getPTACallGraphNode(ctp.getProc()->getCallGraphNode()); if(isCandidateFun(cgNode->getCallNode()->getFunction()) == false) continue; @@ -452,7 +458,9 @@ void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* if(isCandidateFun(caller) == false) return; - if(inSameCallGraphSCC(tcg->getCallGraphNode(caller->getCallGraphNode()),tcg->getCallGraphNode(callee->getCallGraphNode()))==false) + if(inSameCallGraphSCC( + tcg->getPTACallGraphNode(caller->getCallGraphNode()), + tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) { pushCxt(cxt,csId); DBOUT(DMTA,dumpCxt(cxt)); @@ -477,7 +485,9 @@ bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* if(cxt.empty()) return true; - if(inSameCallGraphSCC(tcg->getCallGraphNode(caller->getCallGraphNode()),tcg->getCallGraphNode(callee->getCallGraphNode()))==false) + if(inSameCallGraphSCC( + tcg->getPTACallGraphNode(caller->getCallGraphNode()), + tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) { if(cxt.back() == csId) cxt.pop_back(); diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 85739a36e..92f59656e 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -139,7 +139,9 @@ bool PointerAnalysis::isLocalVarInRecursiveFun(NodeID id) const { if(const SVFFunction* svffun = pag->getGNode(id)->getFunction()) { - return callGraphSCC->isInCycle(getCallGraph()->getCallGraphNode(svffun->getCallGraphNode())->getId()); + return callGraphSCC->isInCycle( + getCallGraph() + ->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); } } return false; From 25364821ebb1551461ecbd23d41bbd64fd63c24e Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 14:30:28 +1100 Subject: [PATCH 12/45] refactoring std::pair CallSitePair; --> std::pair CallSitePair; in PTACallGraphNode --- svf/include/DDA/ContextDDA.h | 4 ++-- svf/include/Graphs/PTACallGraph.h | 12 ++++++------ svf/include/Graphs/VFG.h | 2 +- svf/lib/DDA/ContextDDA.cpp | 8 ++++---- svf/lib/Graphs/PTACallGraph.cpp | 4 ++-- svf/lib/Graphs/ThreadCallGraph.cpp | 6 +++--- svf/lib/MTA/LockAnalysis.cpp | 4 ++-- svf/lib/MTA/TCT.cpp | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index 5aa8dc9e1..8db6483e4 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -134,8 +134,8 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolvergetCallerOfCallSite(csId); - const SVFFunction* callee = getCallGraph()->getCalleeOfCallSite(csId); - return inSameCallGraphSCC(caller, callee); + const CallGraphNode* callee = getCallGraph()->getCalleeOfCallSite(csId); + return inSameCallGraphSCC(caller, callee->getFunction()); } /// Update call graph. //@{ diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index e3959b31c..35a1c4640 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -241,7 +241,7 @@ class PTACallGraph : public GenericPTACallGraphTy typedef PTACallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet; typedef Map CgNodeToPTACallGraphNodeMap; typedef Map CallInstToCallGraphEdgesMap; - typedef std::pair CallSitePair; + typedef std::pair CallSitePair; typedef Map CallSiteToIdMap; typedef Map IdToCallSiteMap; typedef Set FunctionSet; @@ -276,9 +276,9 @@ class PTACallGraph : public GenericPTACallGraphTy protected: /// Add CallSiteID - inline CallSiteID addCallSite(const CallICFGNode* cs, const SVFFunction* callee) + inline CallSiteID addCallSite(const CallICFGNode* cs, const CallGraphNode* callee) { - std::pair newCS(std::make_pair(cs, callee)); + std::pair newCS(std::make_pair(cs, callee)); CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); //assert(it == csToIdMap.end() && "cannot add a callsite twice"); if(it == csToIdMap.end()) @@ -371,14 +371,14 @@ class PTACallGraph : public GenericPTACallGraphTy /// Get CallSiteID //@{ - inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* callee) const + inline CallSiteID getCallSiteID(const CallICFGNode* cs, const CallGraphNode* callee) const { CallSitePair newCS(std::make_pair(cs, callee)); CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); assert(it != csToIdMap.end() && "callsite id not found! This maybe a partially resolved callgraph, please check the indCallEdge limit"); return it->second; } - inline bool hasCallSiteID(const CallICFGNode* cs, const SVFFunction* callee) const + inline bool hasCallSiteID(const CallICFGNode* cs, const CallGraphNode* callee) const { CallSitePair newCS(std::make_pair(cs, callee)); CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS); @@ -398,7 +398,7 @@ class PTACallGraph : public GenericPTACallGraphTy { return getCallSite(id)->getCaller(); } - inline const SVFFunction* getCalleeOfCallSite(CallSiteID id) const + inline const CallGraphNode* getCalleeOfCallSite(CallSiteID id) const { return getCallSitePair(id).second; } diff --git a/svf/include/Graphs/VFG.h b/svf/include/Graphs/VFG.h index 63f2d3cec..ef69ba6a9 100644 --- a/svf/include/Graphs/VFG.h +++ b/svf/include/Graphs/VFG.h @@ -177,7 +177,7 @@ class VFG : public GenericVFGTy //@{ inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* func) const { - return callgraph->getCallSiteID(cs, func); + return callgraph->getCallSiteID(cs, func->getCallGraphNode()); } inline const CallICFGNode* getCallSite(CallSiteID id) const { diff --git a/svf/lib/DDA/ContextDDA.cpp b/svf/lib/DDA/ContextDDA.cpp index d4f7a7f73..2e5f3fe3a 100644 --- a/svf/lib/DDA/ContextDDA.cpp +++ b/svf/lib/DDA/ContextDDA.cpp @@ -219,9 +219,9 @@ CallSiteID ContextDDA::getCSIDAtCall(CxtLocDPItem&, const SVFGEdge* edge) const CallICFGNode* cbn = getSVFG()->getCallSite(svfg_csId); const SVFFunction* callee = edge->getDstNode()->getFun(); - if(getCallGraph()->hasCallSiteID(cbn,callee)) + if(getCallGraph()->hasCallSiteID(cbn,callee->getCallGraphNode())) { - return getCallGraph()->getCallSiteID(cbn,callee); + return getCallGraph()->getCallSiteID(cbn,callee->getCallGraphNode()); } return 0; @@ -243,9 +243,9 @@ CallSiteID ContextDDA::getCSIDAtRet(CxtLocDPItem&, const SVFGEdge* edge) const CallICFGNode* cbn = getSVFG()->getCallSite(svfg_csId); const SVFFunction* callee = edge->getSrcNode()->getFun(); - if(getCallGraph()->hasCallSiteID(cbn,callee)) + if(getCallGraph()->hasCallSiteID(cbn,callee->getCallGraphNode())) { - return getCallGraph()->getCallSiteID(cbn,callee); + return getCallGraph()->getCallSiteID(cbn,callee->getCallGraphNode()); } return 0; diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 9e5ffb455..5f0853e02 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -137,7 +137,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) { PTACallGraphNode* src = getCallGraphNode(edge->getSrcID()); PTACallGraphNode* dst = getCallGraphNode(edge->getDstID()); - CallSiteID csId = addCallSite(cs, dst->getCallNode()->getFunction()); + CallSiteID csId = addCallSite(cs, dst->getCallNode()); PTACallGraphEdge* newEdge = new PTACallGraphEdge(src,dst, PTACallGraphEdge::CallRetEdge,csId); newEdge->addDirectCallSite(cs); @@ -205,7 +205,7 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunc numOfResolvedIndCallEdge++; - CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()); if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId)) { diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 0c5a7d398..4f222e092 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -133,7 +133,7 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) assert(forkee && "callee does not exist"); PTACallGraphNode* callee = getPTACallGraphNode( forkee->getDefFunForMultipleModule()->getCallGraphNode()); - CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { @@ -160,7 +160,7 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunct PTACallGraphNode* callee = getPTACallGraphNode(calleefun->getCallGraphNode()); - CallSiteID csId = addCallSite(cs, callee->getCallNode()->getFunction()); + CallSiteID csId = addCallSite(cs, callee->getCallNode()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { @@ -198,7 +198,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet assert(threadRoutineFun && "thread routine function does not exist"); PTACallGraphNode* threadRoutineFunNode = getPTACallGraphNode(threadRoutineFun); - CallSiteID csId = addCallSite(cs, threadRoutineFun->getFunction()); + CallSiteID csId = addCallSite(cs, threadRoutineFun); if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) { diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index c3c9a8773..a0e846353 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -526,7 +526,7 @@ void LockAnalysis::handleIntra(const CxtStmt& cts) void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { const SVFFunction* svfcaller = call->getFun(); - CallSiteID csId = getTCG()->getCallSiteID(call, callee); + CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); // /// handle calling context for candidate functions only // if (isLockCandidateFun(caller) == false) @@ -544,7 +544,7 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { const SVFFunction* svfcaller = call->getFun(); - CallSiteID csId = getTCG()->getCallSiteID(call, callee); + CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); // /// handle calling context for candidate functions only // if (isLockCandidateFun(caller) == false) diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index f04416cf9..4b110b787 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -452,7 +452,7 @@ void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* { const SVFFunction* caller = call->getFun(); - CallSiteID csId = tcg->getCallSiteID(call, callee); + CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); /// handle calling context for candidate functions only if(isCandidateFun(caller) == false) @@ -475,7 +475,7 @@ bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* { const SVFFunction* caller = call->getFun(); - CallSiteID csId = tcg->getCallSiteID(call, callee); + CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); /// handle calling context for candidate functions only if(isCandidateFun(caller) == false) From 19692929c8b44b74e359bf8b1e1e4d016bc68148 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 15:14:21 +1100 Subject: [PATCH 13/45] refactoring typedef Set FunctionSet; --> Set FunctionSet; in PTACallGraphNode --- svf-llvm/lib/DCHG.cpp | 6 +++--- svf/include/DDA/ContextDDA.h | 2 +- svf/include/DDA/FlowDDA.h | 2 +- svf/include/Graphs/CHG.h | 2 +- svf/include/Graphs/PTACallGraph.h | 5 ++--- svf/include/MTA/TCT.h | 2 +- svf/include/MemoryModel/PointerAnalysis.h | 4 ++-- svf/lib/CFL/CFLAlias.cpp | 2 +- svf/lib/DDA/DDAClient.cpp | 4 ++-- svf/lib/DDA/FlowDDA.cpp | 2 +- svf/lib/Graphs/CHG.cpp | 6 +++--- svf/lib/Graphs/ICFG.cpp | 2 +- svf/lib/Graphs/ThreadCallGraph.cpp | 4 ++-- svf/lib/Graphs/VFG.cpp | 4 ++-- svf/lib/MemoryModel/PointerAnalysis.cpp | 14 +++++++------- svf/lib/MemoryModel/PointerAnalysisImpl.cpp | 6 +++--- svf/lib/SABER/LeakChecker.cpp | 8 ++++---- svf/lib/SABER/SaberSVFGBuilder.cpp | 6 +++--- svf/lib/WPA/Andersen.cpp | 4 ++-- svf/lib/WPA/AndersenSCD.cpp | 2 +- svf/lib/WPA/FlowSensitive.cpp | 6 +++--- 21 files changed, 46 insertions(+), 47 deletions(-) diff --git a/svf-llvm/lib/DCHG.cpp b/svf-llvm/lib/DCHG.cpp index 5ba449e72..e12a173ee 100644 --- a/svf-llvm/lib/DCHG.cpp +++ b/svf-llvm/lib/DCHG.cpp @@ -640,7 +640,7 @@ void DCHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &v */ if (funName.size() == 0) { - virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())); + virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode()); } else if (funName[0] == '~') { @@ -656,7 +656,7 @@ void DCHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &v */ if (calleeName[0] == '~') { - virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())); + virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode()); } } else @@ -667,7 +667,7 @@ void DCHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &v */ if (funName.compare(calleeName) == 0) { - virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())); + virtualFunctions.insert(LLVMUtil::getFunction(callee->getName().str())->getCallGraphNode()); } } } diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index 8db6483e4..d50cf2af5 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -149,7 +149,7 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolversecond; for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = *func_iter; + const SVFFunction* func = (*func_iter)->getFunction(); getSVFG()->connectCallerAndCallee(newcs, func, svfgEdges); } } diff --git a/svf/include/DDA/FlowDDA.h b/svf/include/DDA/FlowDDA.h index ed4d30441..67077ab2d 100644 --- a/svf/include/DDA/FlowDDA.h +++ b/svf/include/DDA/FlowDDA.h @@ -142,7 +142,7 @@ class FlowDDA : public BVDataPTAImpl, public DDAVFSolversecond; for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = *func_iter; + const SVFFunction* func = (*func_iter)->getFunction(); getSVFG()->connectCallerAndCallee(newcs, func, svfgEdges); } } diff --git a/svf/include/Graphs/CHG.h b/svf/include/Graphs/CHG.h index 87a014c4f..e7ccf260f 100644 --- a/svf/include/Graphs/CHG.h +++ b/svf/include/Graphs/CHG.h @@ -45,7 +45,7 @@ class CHNode; class GlobalObjVar; typedef Set VTableSet; -typedef Set VFunSet; +typedef Set VFunSet; /// Common base for class hierarchy graph. Only implements what PointerAnalysis needs. class CommonCHGraph diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 35a1c4640..d1cc54e5a 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -244,7 +244,7 @@ class PTACallGraph : public GenericPTACallGraphTy typedef std::pair CallSitePair; typedef Map CallSiteToIdMap; typedef Map IdToCallSiteMap; - typedef Set FunctionSet; + typedef Set FunctionSet; typedef OrderedMap CallEdgeMap; typedef CallGraphEdgeSet::iterator CallGraphEdgeIter; typedef CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter; @@ -418,8 +418,7 @@ class PTACallGraph : public GenericPTACallGraphTy for (CallGraphEdgeSet::const_iterator it = getCallEdgeBegin(cs), eit = getCallEdgeEnd(cs); it != eit; ++it) { - callees.insert( - (*it)->getDstNode()->getCallNode()->getFunction()); + callees.insert((*it)->getDstNode()->getCallNode()); } } } diff --git a/svf/include/MTA/TCT.h b/svf/include/MTA/TCT.h index 05eca06a1..c8be4583a 100644 --- a/svf/include/MTA/TCT.h +++ b/svf/include/MTA/TCT.h @@ -293,7 +293,7 @@ class TCT: public GenericThreadCreateTreeTy for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { - if(candidateFuncSet.find((*cit))!=candidateFuncSet.end()) + if(candidateFuncSet.find((*cit)->getFunction())!=candidateFuncSet.end()) return true; } return false; diff --git a/svf/include/MemoryModel/PointerAnalysis.h b/svf/include/MemoryModel/PointerAnalysis.h index 559a8a27b..730063432 100644 --- a/svf/include/MemoryModel/PointerAnalysis.h +++ b/svf/include/MemoryModel/PointerAnalysis.h @@ -101,11 +101,11 @@ class PointerAnalysis //@{ typedef Set CallSiteSet; typedef SVFIR::CallSiteToFunPtrMap CallSiteToFunPtrMap; - typedef Set FunctionSet; + typedef Set FunctionSet; typedef OrderedMap CallEdgeMap; typedef SCCDetection CallGraphSCC; typedef Set VTableSet; - typedef Set VFunSet; + typedef Set VFunSet; //@} static const std::string aliasTestMayAlias; diff --git a/svf/lib/CFL/CFLAlias.cpp b/svf/lib/CFL/CFLAlias.cpp index 28111b61a..852dbe7a5 100644 --- a/svf/lib/CFL/CFLAlias.cpp +++ b/svf/lib/CFL/CFLAlias.cpp @@ -179,7 +179,7 @@ bool CFLAlias::updateCallGraph(const CallSiteToFunPtrMap& callsites) { for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { - connectCaller2CalleeParams(it->first,(*cit)->getCallGraphNode()); + connectCaller2CalleeParams(it->first,*cit); } } diff --git a/svf/lib/DDA/DDAClient.cpp b/svf/lib/DDA/DDAClient.cpp index 5f159f34e..d069f98a2 100644 --- a/svf/lib/DDA/DDAClient.cpp +++ b/svf/lib/DDA/DDAClient.cpp @@ -138,8 +138,8 @@ void FunptrDDAClient::performStat(PointerAnalysis* pta) if(ddaPts.count() >= anderPts.count() || ddaPts.empty()) continue; - Set ander_vfns; - Set dda_vfns; + Set ander_vfns; + Set dda_vfns; ander->getVFnsFromPts(cbn,anderPts, ander_vfns); pta->getVFnsFromPts(cbn,ddaPts, dda_vfns); diff --git a/svf/lib/DDA/FlowDDA.cpp b/svf/lib/DDA/FlowDDA.cpp index d7a746835..f1bc3b178 100644 --- a/svf/lib/DDA/FlowDDA.cpp +++ b/svf/lib/DDA/FlowDDA.cpp @@ -88,7 +88,7 @@ bool FlowDDA::testIndCallReachability(LocDPItem&, const SVFFunction* callee, Cal if(getCallGraph()->hasIndCSCallees(cbn)) { const FunctionSet& funset = getCallGraph()->getIndCSCallees(cbn); - if(funset.find(callee)!=funset.end()) + if(funset.find(callee->getCallGraphNode())!=funset.end()) return true; } diff --git a/svf/lib/Graphs/CHG.cpp b/svf/lib/Graphs/CHG.cpp index 0673c63a6..de9585de7 100644 --- a/svf/lib/Graphs/CHG.cpp +++ b/svf/lib/Graphs/CHG.cpp @@ -169,7 +169,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (funName.size() == 0) { - virtualFunctions.insert(callee); + virtualFunctions.insert(callee->getCallGraphNode()); } else if (funName[0] == '~') { @@ -185,7 +185,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (calleeName[0] == '~') { - virtualFunctions.insert(callee); + virtualFunctions.insert(callee->getCallGraphNode()); } } else @@ -196,7 +196,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (funName.compare(calleeName) == 0) { - virtualFunctions.insert(callee); + virtualFunctions.insert(callee->getCallGraphNode()); } } } diff --git a/svf/lib/Graphs/ICFG.cpp b/svf/lib/Graphs/ICFG.cpp index 533cb2129..9a8052082 100644 --- a/svf/lib/Graphs/ICFG.cpp +++ b/svf/lib/Graphs/ICFG.cpp @@ -427,7 +427,7 @@ void ICFG::updateCallGraph(PTACallGraph* callgraph) const PTACallGraph::FunctionSet & functions = iter->second; for (PTACallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* callee = *func_iter; + const SVFFunction* callee = (*func_iter)->getFunction(); RetICFGNode* retBlockNode = const_cast(callBlockNode->getRetICFGNode()); /// if this is an external function (no function body), connect calleeEntryNode to calleeExitNode if (isExtCall(callee)) diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 4f222e092..e0876fb96 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -66,8 +66,8 @@ void ThreadCallGraph::updateCallGraph(PointerAnalysis* pta) for (PTACallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* callee = *func_iter; - this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee); + const CallGraphNode* callee = *func_iter; + this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee->getFunction()); } } diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index 6c73bab18..4c854dcf6 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -945,8 +945,8 @@ void VFG::updateCallGraph(PointerAnalysis* pta) const PointerAnalysis::FunctionSet & functions = iter->second; for (PointerAnalysis::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = *func_iter; - connectCallerAndCallee(newcs, func, vfEdgesAtIndCallSite); + const CallGraphNode* func = *func_iter; + connectCallerAndCallee(newcs, func->getFunction(), vfEdgesAtIndCallSite); } } } diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 92f59656e..114b8d8b0 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -325,7 +325,7 @@ void PointerAnalysis::printIndCSTargets(const CallICFGNode* cs, const FunctionSe FunctionSet::const_iterator feit = targets.end(); for (; fit != feit; ++fit) { - const SVFFunction* callee = *fit; + const CallGraphNode* callee = *fit; outs() << "\n\t" << callee->getName(); } } @@ -402,10 +402,10 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta if(SVFUtil::matchArgs(cs, callee) == false) continue; - if(0 == getIndCallMap()[cs].count(callee)) + if(0 == getIndCallMap()[cs].count(callee->getCallGraphNode())) { - newEdges[cs].insert(callee); - getIndCallMap()[cs].insert(callee); + newEdges[cs].insert(callee->getCallGraphNode()); + getIndCallMap()[cs].insert(callee->getCallGraphNode()); callgraph->addIndirectCallGraphEdge(cs, cs->getCaller(), callee); // FIXME: do we need to update llvm call graph here? @@ -471,8 +471,8 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & for (VFunSet::const_iterator fit = vfns.begin(), feit = vfns.end(); fit != feit; ++fit) { - const SVFFunction* callee = *fit; - callee = callee->getDefFunForMultipleModule(); + const CallGraphNode* callee = *fit; + callee = callee->getDefFunForMultipleModule()->getCallGraphNode(); if (getIndCallMap()[cs].count(callee) > 0) continue; if(cs->arg_size() == callee->arg_size() || @@ -481,7 +481,7 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & newEdges[cs].insert(callee); getIndCallMap()[cs].insert(callee); const CallICFGNode* callBlockNode = cs; - callgraph->addIndirectCallGraphEdge(callBlockNode, cs->getCaller(),callee); + callgraph->addIndirectCallGraphEdge(callBlockNode, cs->getCaller(),callee->getFunction()); } } } diff --git a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp index 0bb93092e..b4b58549a 100644 --- a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp +++ b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp @@ -541,9 +541,9 @@ void BVDataPTAImpl::onTheFlyThreadCallGraphSolve(const CallSiteToFunPtrMap& call const BaseObjVar* obj = pag->getBaseObject(objPN->getId()); if(obj->isFunction()) { - const SVFFunction *svfForkedFun = SVFUtil::cast(obj)->getFunction(); - if(tdCallGraph->addIndirectForkEdge(*it, svfForkedFun)) - newForkEdges[*it].insert(svfForkedFun); + const CallGraphNode *cgn = SVFUtil::cast(obj)->getCallGraphNode(); + if(tdCallGraph->addIndirectForkEdge(*it, cgn->getFunction())) + newForkEdges[*it].insert(cgn); } } } diff --git a/svf/lib/SABER/LeakChecker.cpp b/svf/lib/SABER/LeakChecker.cpp index aaba9027b..1fcbad259 100644 --- a/svf/lib/SABER/LeakChecker.cpp +++ b/svf/lib/SABER/LeakChecker.cpp @@ -56,8 +56,8 @@ void LeakChecker::initSrcs() getCallgraph()->getCallees(cs->getCallICFGNode(),callees); for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { - const SVFFunction* fun = *cit; - if (isSourceLikeFun(fun->getCallGraphNode())) + const CallGraphNode* fun = *cit; + if (isSourceLikeFun(fun)) { CSWorkList worklist; SVFGNodeBS visited; @@ -116,8 +116,8 @@ void LeakChecker::initSnks() getCallgraph()->getCallees(it->first,callees); for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { - const SVFFunction* fun = *cit; - if (isSinkLikeFun(fun->getCallGraphNode())) + const CallGraphNode* fun = *cit; + if (isSinkLikeFun(fun)) { SVFIR::SVFVarList &arglist = it->second; assert(!arglist.empty() && "no actual parameter at deallocation site?"); diff --git a/svf/lib/SABER/SaberSVFGBuilder.cpp b/svf/lib/SABER/SaberSVFGBuilder.cpp index 4279340e7..318f5214b 100644 --- a/svf/lib/SABER/SaberSVFGBuilder.cpp +++ b/svf/lib/SABER/SaberSVFGBuilder.cpp @@ -303,9 +303,9 @@ void SaberSVFGBuilder::AddExtActualParmSVFGNodes(PTACallGraph* callgraph) ecit = callees.end(); cit != ecit; cit++) { - const SVFFunction* fun = *cit; - if (SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun->getCallGraphNode()) - || SaberCheckerAPI::getCheckerAPI()->isFClose(fun->getCallGraphNode())) + const CallGraphNode* fun = *cit; + if (SaberCheckerAPI::getCheckerAPI()->isMemDealloc(fun) + || SaberCheckerAPI::getCheckerAPI()->isFClose(fun)) { SVFIR::SVFVarList& arglist = it->second; for(SVFIR::SVFVarList::const_iterator ait = arglist.begin(), aeit = arglist.end(); ait!=aeit; ++ait) diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index abbda8b54..3c9984fe7 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -203,7 +203,7 @@ bool AndersenBase::updateCallGraph(const CallSiteToFunPtrMap& callsites) ecit = it->second.end(); cit != ecit; ++cit) { - connectCaller2CalleeParams(it->first, (*cit)->getCallGraphNode(), cpySrcNodes); + connectCaller2CalleeParams(it->first, *cit, cpySrcNodes); } } @@ -233,7 +233,7 @@ bool AndersenBase::updateThreadCallGraph(const CallSiteToFunPtrMap& callsites, ecit = it->second.end(); cit != ecit; ++cit) { - connectCaller2ForkedFunParams(it->first, (*cit)->getCallGraphNode(), cpySrcNodes); + connectCaller2ForkedFunParams(it->first, *cit, cpySrcNodes); } } return !newForkEdges.empty(); diff --git a/svf/lib/WPA/AndersenSCD.cpp b/svf/lib/WPA/AndersenSCD.cpp index 3e62d1364..2e7538f0d 100644 --- a/svf/lib/WPA/AndersenSCD.cpp +++ b/svf/lib/WPA/AndersenSCD.cpp @@ -283,7 +283,7 @@ bool AndersenSCD::updateCallGraph(const PointerAnalysis::CallSiteToFunPtrMap& ca { for(FunctionSet::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { - connectCaller2CalleeParams(it->first,(*cit)->getCallGraphNode(),cpySrcNodes); + connectCaller2CalleeParams(it->first,*cit,cpySrcNodes); } } diff --git a/svf/lib/WPA/FlowSensitive.cpp b/svf/lib/WPA/FlowSensitive.cpp index c15b85631..997881952 100644 --- a/svf/lib/WPA/FlowSensitive.cpp +++ b/svf/lib/WPA/FlowSensitive.cpp @@ -713,7 +713,7 @@ bool FlowSensitive::updateCallGraph(const CallSiteToFunPtrMap& callsites) for (FunctionSet::iterator potentialFunctionIt = potentialFunctionSet.begin(); potentialFunctionIt != potentialFunctionSet.end(); ) { - const SVFFunction *potentialFunction = *potentialFunctionIt; + const CallGraphNode *potentialFunction = *potentialFunctionIt; if (andersFunctionSet.find(potentialFunction) == andersFunctionSet.end()) { // potentialFunction is not in the Andersen's call graph -- remove it. @@ -750,8 +750,8 @@ void FlowSensitive::connectCallerAndCallee(const CallEdgeMap& newEdges, SVFGEdge const FunctionSet & functions = iter->second; for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = *func_iter; - svfg->connectCallerAndCallee(cs, func, edges); + const CallGraphNode* func = *func_iter; + svfg->connectCallerAndCallee(cs, func->getFunction(), edges); } } } From fee8c91704b69cd0b4922a3d9757f2f1ebf2f01f Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 16:38:26 +1100 Subject: [PATCH 14/45] refactoring icfgNode->getFun()->getFunction() --> const CallGraphNode* fun; in ICFGNode --- svf/include/DDA/ContextDDA.h | 6 ++-- svf/include/Graphs/CDG.h | 1 + svf/include/Graphs/CallGraph.h | 7 ++++ svf/include/Graphs/ICFG.h | 4 +-- svf/include/Graphs/ICFGNode.h | 25 ++++++-------- svf/include/Graphs/PTACallGraph.h | 4 +-- svf/include/Graphs/SVFG.h | 8 ++--- svf/include/Graphs/VFG.h | 4 +-- svf/include/Graphs/VFGNode.h | 7 ++-- svf/include/MSSA/MemRegion.h | 4 +-- svf/include/MemoryModel/PointerAnalysis.h | 10 +++--- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 2 +- svf/lib/DDA/ContextDDA.cpp | 2 +- svf/lib/DDA/DDAPass.cpp | 20 ++++++------ svf/lib/Graphs/ICFG.cpp | 15 +++++++-- svf/lib/Graphs/PTACallGraph.cpp | 10 +++--- svf/lib/Graphs/ThreadCallGraph.cpp | 14 ++++---- svf/lib/MSSA/MemRegion.cpp | 12 +++---- svf/lib/MTA/LockAnalysis.cpp | 22 ++++++------- svf/lib/MTA/MHP.cpp | 14 ++++---- svf/lib/MTA/TCT.cpp | 34 ++++++++++---------- svf/lib/MemoryModel/PointerAnalysis.cpp | 4 +-- svf/lib/SVFIR/SVFVariables.cpp | 4 +-- 23 files changed, 124 insertions(+), 109 deletions(-) diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index d50cf2af5..436c2211b 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -133,9 +133,9 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolvergetCallerOfCallSite(csId); + const CallGraphNode* caller = getCallGraph()->getCallerOfCallSite(csId); const CallGraphNode* callee = getCallGraph()->getCalleeOfCallSite(csId); - return inSameCallGraphSCC(caller, callee->getFunction()); + return inSameCallGraphSCC(caller, callee); } /// Update call graph. //@{ @@ -163,7 +163,7 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolvergetDstNode()->getFun(); if(srcfun && dstfun) - return inSameCallGraphSCC(srcfun,dstfun); + return inSameCallGraphSCC(srcfun->getCallGraphNode(),dstfun->getCallGraphNode()); assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" ); diff --git a/svf/include/Graphs/CDG.h b/svf/include/Graphs/CDG.h index 394b825d4..0c457b26f 100644 --- a/svf/include/Graphs/CDG.h +++ b/svf/include/Graphs/CDG.h @@ -31,6 +31,7 @@ #define SVF_CONTROLDG_H #include "SVFIR/SVFIR.h" +#include "Graphs/CallGraph.h" namespace SVF { diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 997a62ecf..feda4a809 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -272,6 +272,13 @@ class CallGraphNode : public GenericCallGraphNodeTy return bbGraph && bbGraph->begin() != bbGraph->end(); } + inline const SVFBasicBlock* getEntryBlock() const + { + assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); + assert(bbGraph->begin()->second->getInEdges().size() == 0 && "the first basic block is not entry block"); + return bbGraph->begin()->second; + } + inline const SVFBasicBlock* getExitBB() const { assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); diff --git a/svf/include/Graphs/ICFG.h b/svf/include/Graphs/ICFG.h index b2f8deefe..e693e10bc 100644 --- a/svf/include/Graphs/ICFG.h +++ b/svf/include/Graphs/ICFG.h @@ -164,8 +164,8 @@ class ICFG : public GenericICFGTy /// sanitize Intra edges, verify that both nodes belong to the same function. inline void checkIntraEdgeParents(const ICFGNode *srcNode, const ICFGNode *dstNode) { - const SVFFunction* srcfun = srcNode->getFun(); - const SVFFunction* dstfun = dstNode->getFun(); + const CallGraphNode* srcfun = srcNode->getFun(); + const CallGraphNode* dstfun = dstNode->getFun(); if(srcfun != nullptr && dstfun != nullptr) { assert((srcfun == dstfun) && "src and dst nodes of an intra edge should in the same function!" ); diff --git a/svf/include/Graphs/ICFGNode.h b/svf/include/Graphs/ICFGNode.h index 88af9efb1..86fc550fd 100644 --- a/svf/include/Graphs/ICFGNode.h +++ b/svf/include/Graphs/ICFGNode.h @@ -73,7 +73,7 @@ class ICFGNode : public GenericICFGNodeTy } /// Return the function of this ICFGNode - virtual const SVFFunction* getFun() const + virtual const CallGraphNode* getFun() const { return fun; } @@ -145,7 +145,7 @@ class ICFGNode : public GenericICFGNodeTy protected: - const SVFFunction* fun; + const CallGraphNode* fun; const SVFBasicBlock* bb; VFGNodeList VFGNodes; //< a list of VFGNodes SVFStmtList pagEdges; //< a list of PAGEdges @@ -205,7 +205,7 @@ class IntraICFGNode : public ICFGNode public: IntraICFGNode(NodeID id, const SVFBasicBlock* b, bool isReturn) : ICFGNode(id, IntraBlock), isRet(isReturn) { - fun = b->getFunction(); + fun = b->getFunction()->getCallGraphNode(); bb = b; } @@ -292,7 +292,7 @@ class FunEntryICFGNode : public InterICFGNode FunEntryICFGNode(NodeID id, const SVFFunction* f); /// Return function - inline const SVFFunction* getFun() const override + inline const CallGraphNode* getFun() const override { return fun; } @@ -339,10 +339,8 @@ class FunEntryICFGNode : public InterICFGNode const std::string toString() const override; - const std::string getSourceLoc() const override - { - return "function entry: " + fun->getSourceLoc(); - } + const std::string getSourceLoc() const override; + }; /*! @@ -363,7 +361,7 @@ class FunExitICFGNode : public InterICFGNode FunExitICFGNode(NodeID id, const SVFFunction* f); /// Return function - inline const SVFFunction* getFun() const override + inline const CallGraphNode* getFun() const override { return fun; } @@ -410,10 +408,7 @@ class FunExitICFGNode : public InterICFGNode const std::string toString() const override; - const std::string getSourceLoc() const override - { - return "function ret: " + fun->getSourceLoc(); - } + const std::string getSourceLoc() const override; }; /*! @@ -448,7 +443,7 @@ class CallICFGNode : public InterICFGNode isvararg(iv), isVirCallInst(ivc), vtabPtr(nullptr), virtualFunIdx(vfi), funNameOfVcall(fnv) { - fun = b->getFunction(); + fun = b->getFunction()->getCallGraphNode(); bb = b; type = ty; } @@ -467,7 +462,7 @@ class CallICFGNode : public InterICFGNode } /// Return callsite - inline const SVFFunction* getCaller() const + inline const CallGraphNode* getCaller() const { return getFun(); } diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index d1cc54e5a..63df3bb7d 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -394,7 +394,7 @@ class PTACallGraph : public GenericPTACallGraphTy { return getCallSitePair(id).first; } - inline const SVFFunction* getCallerOfCallSite(CallSiteID id) const + inline const CallGraphNode* getCallerOfCallSite(CallSiteID id) const { return getCallSite(id)->getCaller(); } @@ -449,7 +449,7 @@ class PTACallGraph : public GenericPTACallGraphTy /// Add indirect call edges //@{ - void addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun); + void addIndirectCallGraphEdge(const CallICFGNode* cs,const CallGraphNode* callerFun, const CallGraphNode* calleeFun); //@} /// Get callsites invoking the callee diff --git a/svf/include/Graphs/SVFG.h b/svf/include/Graphs/SVFG.h index dad7fe3ba..b11e5dd20 100644 --- a/svf/include/Graphs/SVFG.h +++ b/svf/include/Graphs/SVFG.h @@ -403,17 +403,17 @@ class SVFG : public VFG inline void addFormalINSVFGNode(const FunEntryICFGNode* funEntry, const MRVer* resVer, const NodeID nodeId) { FormalINSVFGNode* sNode = new FormalINSVFGNode(nodeId, resVer, funEntry); - addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun())); + addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun()->getFunction())); setDef(resVer,sNode); - funToFormalINMap[funEntry->getFun()].set(sNode->getId()); + funToFormalINMap[funEntry->getFun()->getFunction()].set(sNode->getId()); } /// Add memory Function return mu SVFG node inline void addFormalOUTSVFGNode(const FunExitICFGNode* funExit, const MRVer* ver, const NodeID nodeId) { FormalOUTSVFGNode* sNode = new FormalOUTSVFGNode(nodeId, ver, funExit); - addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun())); - funToFormalOUTMap[funExit->getFun()].set(sNode->getId()); + addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun()->getFunction())); + funToFormalOUTMap[funExit->getFun()->getFunction()].set(sNode->getId()); } /// Add memory callsite mu SVFG node diff --git a/svf/include/Graphs/VFG.h b/svf/include/Graphs/VFG.h index ef69ba6a9..1e6637d28 100644 --- a/svf/include/Graphs/VFG.h +++ b/svf/include/Graphs/VFG.h @@ -467,8 +467,8 @@ class VFG : public GenericVFGTy vfgNode->setICFGNode(icfgNode); icfgNode->addVFGNode(vfgNode); - if(const SVFFunction* fun = icfgNode->getFun()) - funToVFGNodesMap[fun].insert(vfgNode); + if(const CallGraphNode* cgn = icfgNode->getFun()) + funToVFGNodesMap[cgn->getFunction()].insert(vfgNode); else globalVFGNodes.insert(vfgNode); } diff --git a/svf/include/Graphs/VFGNode.h b/svf/include/Graphs/VFGNode.h index ea06d56a4..a839a9be5 100644 --- a/svf/include/Graphs/VFGNode.h +++ b/svf/include/Graphs/VFGNode.h @@ -78,7 +78,10 @@ class VFGNode : public GenericVFGNodeTy /// Get the function of this SVFGNode virtual const SVFFunction* getFun() const { - return icfgNode->getFun(); + if (icfgNode->getFun() == nullptr) + return nullptr; + else + return icfgNode->getFun()->getFunction(); } /// Return the corresponding LLVM value, if possible, nullptr otherwise. @@ -1040,7 +1043,7 @@ class ActualRetVFGNode: public ArgumentVFGNode /// Receive parameter at callsite inline const SVFFunction* getCaller() const { - return cs->getCaller(); + return cs->getCaller()->getFunction(); } /// Receive parameter at callsite inline const PAGNode* getRev() const diff --git a/svf/include/MSSA/MemRegion.h b/svf/include/MSSA/MemRegion.h index 65f2543ba..b0f1b2b7f 100644 --- a/svf/include/MSSA/MemRegion.h +++ b/svf/include/MSSA/MemRegion.h @@ -353,12 +353,12 @@ class MRGenerator inline void addCPtsToCallSiteRefs(NodeBS& cpts, const CallICFGNode* cs) { callsiteToRefPointsToMap[cs] |= cpts; - funToPointsToMap[cs->getCaller()].insert(cpts); + funToPointsToMap[cs->getCaller()->getFunction()].insert(cpts); } inline void addCPtsToCallSiteMods(NodeBS& cpts, const CallICFGNode* cs) { callsiteToModPointsToMap[cs] |= cpts; - funToPointsToMap[cs->getCaller()].insert(cpts); + funToPointsToMap[cs->getCaller()->getFunction()].insert(cpts); } inline bool hasCPtsList(const SVFFunction* fun) const { diff --git a/svf/include/MemoryModel/PointerAnalysis.h b/svf/include/MemoryModel/PointerAnalysis.h index 730063432..24a857dad 100644 --- a/svf/include/MemoryModel/PointerAnalysis.h +++ b/svf/include/MemoryModel/PointerAnalysis.h @@ -396,18 +396,18 @@ class PointerAnalysis return callGraphSCC->repNode(id); } /// Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SCC on the SVFG. - inline bool inSameCallGraphSCC(const SVFFunction* fun1,const SVFFunction* fun2) + inline bool inSameCallGraphSCC(const CallGraphNode* fun1,const CallGraphNode* fun2) { const PTACallGraphNode* src = - callgraph->getPTACallGraphNode(fun1->getCallGraphNode()); + callgraph->getPTACallGraphNode(fun1); const PTACallGraphNode* dst = - callgraph->getPTACallGraphNode(fun2->getCallGraphNode()); + callgraph->getPTACallGraphNode(fun2); return (getCallGraphSCCRepNode(src->getId()) == getCallGraphSCCRepNode(dst->getId())); } - inline bool isInRecursion(const SVFFunction* fun) const + inline bool isInRecursion(const CallGraphNode* fun) const { return callGraphSCC->isInCycle( - callgraph->getPTACallGraphNode(fun->getCallGraphNode())->getId()); + callgraph->getPTACallGraphNode(fun)->getId()); } /// Whether a local variable is in function recursions bool isLocalVarInRecursiveFun(NodeID id) const; diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index d38e2c266..d67e2a49b 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -851,7 +851,7 @@ void AEStat::finializeStat() generalNumMap["ICFG_Node_Num"] = _ae->svfir->getICFG()->nodeNum; u32_t callSiteNum = 0; u32_t extCallSiteNum = 0; - Set funs; + Set funs; for (const auto &it: *_ae->svfir->getICFG()) { if (it.second->getFun()) diff --git a/svf/lib/DDA/ContextDDA.cpp b/svf/lib/DDA/ContextDDA.cpp index 1d6c6e02f..40561c600 100644 --- a/svf/lib/DDA/ContextDDA.cpp +++ b/svf/lib/DDA/ContextDDA.cpp @@ -358,7 +358,7 @@ bool ContextDDA::isHeapCondMemObj(const CxtVar& var, const StoreSVFGNode*) } else if(const ICFGNode* node = obj->getICFGNode()) { - const SVFFunction* svfFun = node->getFun(); + const CallGraphNode* svfFun = node->getFun(); if(_ander->isInRecursion(svfFun)) return true; if(var.get_cond().isConcreteCxt() == false) diff --git a/svf/lib/DDA/DDAPass.cpp b/svf/lib/DDA/DDAPass.cpp index 38bdc1804..2a78b93e4 100644 --- a/svf/lib/DDA/DDAPass.cpp +++ b/svf/lib/DDA/DDAPass.cpp @@ -177,8 +177,8 @@ bool DDAPass::edgeInSVFGSCC(const SVFGSCC* svfgSCC,const SVFGEdge* edge) */ bool DDAPass::edgeInCallGraphSCC(PointerAnalysis* pta,const SVFGEdge* edge) { - const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); - const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun(); + const CallGraphNode* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); + const CallGraphNode* dstFun = edge->getDstNode()->getICFGNode()->getFun(); if(srcFun && dstFun) { @@ -234,17 +234,17 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(this->edgeInSVFGSCC(svfgSCC,edge)) { - const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); - const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun(); + const CallGraphNode* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); + const CallGraphNode* dstFun = edge->getDstNode()->getICFGNode()->getFun(); if(srcFun && dstFun) { NodeID src = pta->getCallGraph() ->getPTACallGraphNode( - srcFun->getCallGraphNode())->getId(); + srcFun)->getId(); NodeID dst = pta->getCallGraph() ->getPTACallGraphNode( - dstFun->getCallGraphNode())->getId(); + dstFun)->getId(); insensitvefunPairs.insert(std::make_pair(src,dst)); insensitvefunPairs.insert(std::make_pair(dst,src)); } @@ -265,17 +265,17 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(edge->isCallVFGEdge() || edge->isRetVFGEdge()) { - const SVFFunction* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); - const SVFFunction* dstFun = edge->getDstNode()->getICFGNode()->getFun(); + const CallGraphNode* srcFun = edge->getSrcNode()->getICFGNode()->getFun(); + const CallGraphNode* dstFun = edge->getDstNode()->getICFGNode()->getFun(); if(srcFun && dstFun) { NodeID src = pta->getCallGraph() - ->getPTACallGraphNode(srcFun->getCallGraphNode())->getId(); + ->getPTACallGraphNode(srcFun)->getId(); NodeID dst = pta->getCallGraph() - ->getPTACallGraphNode(dstFun->getCallGraphNode())->getId(); + ->getPTACallGraphNode(dstFun)->getId(); if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end()) insensitveEdges.insert(edge); else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end()) diff --git a/svf/lib/Graphs/ICFG.cpp b/svf/lib/Graphs/ICFG.cpp index 9a8052082..af9f1ab70 100644 --- a/svf/lib/Graphs/ICFG.cpp +++ b/svf/lib/Graphs/ICFG.cpp @@ -39,7 +39,7 @@ using namespace SVFUtil; FunEntryICFGNode::FunEntryICFGNode(NodeID id, const SVFFunction* f) : InterICFGNode(id, FunEntryBlock) { - fun = f; + fun = f->getCallGraphNode(); // if function is implemented if (f->begin() != f->end()) { @@ -50,7 +50,7 @@ FunEntryICFGNode::FunEntryICFGNode(NodeID id, const SVFFunction* f) : InterICFGN FunExitICFGNode::FunExitICFGNode(NodeID id, const SVFFunction* f) : InterICFGNode(id, FunExitBlock), formalRet(nullptr) { - fun = f; + fun = f->getCallGraphNode(); // if function is implemented if (f->begin() != f->end()) { @@ -110,9 +110,14 @@ const std::string FunEntryICFGNode::toString() const return rawstr.str(); } +const std::string FunEntryICFGNode::getSourceLoc() const +{ + return "function entry: " + fun->getSourceLoc(); +} + const std::string FunExitICFGNode::toString() const { - const SVFFunction *fun = getFun(); + const CallGraphNode *fun = getFun(); std::string str; std::stringstream rawstr(str); rawstr << "FunExitICFGNode" << getId(); @@ -127,6 +132,10 @@ const std::string FunExitICFGNode::toString() const return rawstr.str(); } +const std::string FunExitICFGNode::getSourceLoc() const +{ + return "function ret: " + fun->getSourceLoc(); +} const std::string CallICFGNode::toString() const { diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 5f0853e02..3ad1501f5 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -195,13 +195,13 @@ PTACallGraphEdge* PTACallGraph::getGraphEdge(PTACallGraphNode* src, /*! * Add indirect call edge to update call graph */ -void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const SVFFunction* callerFun, const SVFFunction* calleeFun) +void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const CallGraphNode* callerFun, const CallGraphNode* calleeFun) { PTACallGraphNode* caller = - getPTACallGraphNode(callerFun->getCallGraphNode()); + getPTACallGraphNode(callerFun); PTACallGraphNode* callee = - getPTACallGraphNode(calleeFun->getCallGraphNode()); + getPTACallGraphNode(calleeFun); numOfResolvedIndCallEdge++; @@ -288,8 +288,8 @@ void PTACallGraph::verifyCallGraph() if (targets.empty() == false) { const CallICFGNode* cs = it->first; - const SVFFunction* func = cs->getCaller(); - if (getPTACallGraphNode(func->getCallGraphNode())->isReachableFromProgEntry() == false) + const CallGraphNode* func = cs->getCaller(); + if (getPTACallGraphNode(func)->isReachableFromProgEntry() == false) writeWrnMsg(func->getName() + " has indirect call site but not reachable from main"); } } diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index e0876fb96..9ebc641cf 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -67,7 +67,7 @@ void ThreadCallGraph::updateCallGraph(PointerAnalysis* pta) functions.begin(); func_iter != functions.end(); func_iter++) { const CallGraphNode* callee = *func_iter; - this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee->getFunction()); + this->addIndirectCallGraphEdge(cs, cs->getCaller(), callee); } } @@ -127,7 +127,7 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) { PTACallGraphNode* caller = - getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); + getPTACallGraphNode(cs->getCaller()); const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) ->getCallGraphNode()->getFunction(); assert(forkee && "callee does not exist"); @@ -137,7 +137,7 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getCallNode()->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallNode() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addDirectCallSite(cs); @@ -156,7 +156,7 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunction* calleefun) { PTACallGraphNode* caller = - getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); + getPTACallGraphNode(cs->getCaller()); PTACallGraphNode* callee = getPTACallGraphNode(calleefun->getCallGraphNode()); @@ -164,7 +164,7 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunct if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getCallNode()->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallNode() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addInDirectCallSite(cs); @@ -187,7 +187,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet { PTACallGraphNode* joinFunNode = - getPTACallGraphNode(cs->getCaller()->getCallGraphNode()); + getPTACallGraphNode(cs->getCaller()); for (CallSiteSet::const_iterator it = forkset.begin(), eit = forkset.end(); it != eit; ++it) { @@ -202,7 +202,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) { - assert(cs->getCaller() == joinFunNode->getCallNode()->getFunction() && "callee instruction not inside caller??"); + assert(cs->getCaller() == joinFunNode->getCallNode() && "callee instruction not inside caller??"); ThreadJoinEdge* edge = new ThreadJoinEdge(joinFunNode,threadRoutineFunNode,csId); edge->addDirectCallSite(cs); diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 6915a838b..7f49a7ca2 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -375,10 +375,10 @@ void MRGenerator::updateAliasMRs() for(CallSiteToPointsToMap::const_iterator it = callsiteToModPointsToMap.begin(), eit = callsiteToModPointsToMap.end(); it!=eit; ++it) { - const SVFFunction* fun = it->first->getCaller(); + const CallGraphNode* fun = it->first->getCaller(); MRSet aliasMRs; const NodeBS& callsiteModCPts = it->second; - getAliasMemRegions(aliasMRs,callsiteModCPts,fun); + getAliasMemRegions(aliasMRs,callsiteModCPts,fun->getFunction()); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) { callsiteToModMRsMap[it->first].insert(*ait); @@ -387,10 +387,10 @@ void MRGenerator::updateAliasMRs() for(CallSiteToPointsToMap::const_iterator it = callsiteToRefPointsToMap.begin(), eit = callsiteToRefPointsToMap.end(); it!=eit; ++it) { - const SVFFunction* fun = it->first->getCaller(); + const CallGraphNode* fun = it->first->getCaller(); MRSet aliasMRs; const NodeBS& callsiteRefCPts = it->second; - getMRsForCallSiteRef(aliasMRs, callsiteRefCPts, fun); + getMRsForCallSiteRef(aliasMRs, callsiteRefCPts, fun->getFunction()); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) { callsiteToRefMRsMap[it->first].insert(*ait); @@ -433,7 +433,7 @@ bool MRGenerator::addRefSideEffectOfCallSite(const CallICFGNode* cs, const NodeB NodeBS refset = refs; refset &= getCallSiteArgsPts(cs); getEscapObjviaGlobals(refset,refs); - addRefSideEffectOfFunction(cs->getCaller(),refset); + addRefSideEffectOfFunction(cs->getCaller()->getFunction(),refset); return csToRefsMap[cs] |= refset; } return false; @@ -449,7 +449,7 @@ bool MRGenerator::addModSideEffectOfCallSite(const CallICFGNode* cs, const NodeB NodeBS modset = mods; modset &= (getCallSiteArgsPts(cs) | getCallSiteRetPts(cs)); getEscapObjviaGlobals(modset,mods); - addModSideEffectOfFunction(cs->getCaller(),modset); + addModSideEffectOfFunction(cs->getCaller()->getFunction(),modset); return csToModsMap[cs] |= modset; } return false; diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index a0e846353..15cbfe6fa 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -103,9 +103,9 @@ void LockAnalysis::buildCandidateFuncSetforLock() for (InstSet::iterator it = locksites.begin(), eit = locksites.end(); it != eit; ++it) { - const SVFFunction* fun=(*it)->getFun(); + const CallGraphNode* fun=(*it)->getFun(); PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(fun->getCallGraphNode()); + tcg->getPTACallGraphNode(fun); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -114,9 +114,9 @@ void LockAnalysis::buildCandidateFuncSetforLock() } for (InstSet::iterator it = unlocksites.begin(), eit = unlocksites.end(); it != eit; ++it) { - const SVFFunction* fun = (*it)->getFun(); + const CallGraphNode* fun = (*it)->getFun(); PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(fun->getCallGraphNode()); + tcg->getPTACallGraphNode(fun); if (visited.find(cgnode) == visited.end()) { worklist.push(cgnode); @@ -174,7 +174,7 @@ void LockAnalysis::analyzeIntraProcedualLock() bool LockAnalysis::intraForwardTraverse(const ICFGNode* lockSite, InstSet& unlockSet, InstSet& forwardInsts) { - const SVFFunction* svfFun = lockSite->getFun(); + const CallGraphNode* svfFun = lockSite->getFun(); InstVec worklist; worklist.push_back(lockSite); @@ -457,9 +457,9 @@ void LockAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curInst = cts.getStmt(); const CallStrCxt& curCxt = cts.getContext(); - const SVFFunction* svffun = curInst->getFun(); + const CallGraphNode* svffun = curInst->getFun(); PTACallGraphNode* curFunNode = - getTCG()->getPTACallGraphNode(svffun->getCallGraphNode()); + getTCG()->getPTACallGraphNode(svffun); for (PTACallGraphNode::const_iterator it = curFunNode->getInEdges().begin(), eit = curFunNode->getInEdges().end(); it != eit; ++it) { @@ -525,7 +525,7 @@ void LockAnalysis::handleIntra(const CxtStmt& cts) void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { - const SVFFunction* svfcaller = call->getFun(); + const CallGraphNode* svfcaller = call->getFun(); CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); // /// handle calling context for candidate functions only @@ -533,7 +533,7 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF // return; if (tct->inSameCallGraphSCC( - getTCG()->getPTACallGraphNode(svfcaller->getCallGraphNode()), + getTCG()->getPTACallGraphNode(svfcaller), getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) { tct->pushCxt(cxt,csId); @@ -543,7 +543,7 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { - const SVFFunction* svfcaller = call->getFun(); + const CallGraphNode* svfcaller = call->getFun(); CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); // /// handle calling context for candidate functions only @@ -555,7 +555,7 @@ bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVF return true; if (tct->inSameCallGraphSCC( - getTCG()->getPTACallGraphNode(svfcaller->getCallGraphNode()), + getTCG()->getPTACallGraphNode(svfcaller), getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) { if (cxt.back() == csId) diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index 7cfc7c375..d863836c9 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -97,7 +97,7 @@ void MHP::analyzeInterleaving() DBOUT(DMTA, outs() << " >\n-----\n"); /// handle non-candidate function - if (!tct->isCandidateFun(curInst->getFun())) + if (!tct->isCandidateFun(curInst->getFun()->getFunction())) { handleNonCandidateFun(cts); } @@ -182,11 +182,11 @@ void MHP::updateNonCandidateFunInterleaving() void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) { const ICFGNode* curInst = cts.getStmt(); - const SVFFunction* curfun = curInst->getFun(); + const CallGraphNode* curfun = curInst->getFun(); assert((curInst == curfun->getEntryBlock()->front()) && "curInst is not the entry of non candidate function."); const CallStrCxt& curCxt = cts.getContext(); PTACallGraphNode* node = - tcg->getPTACallGraphNode(curfun->getCallGraphNode()); + tcg->getPTACallGraphNode(curfun); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { const SVFFunction* callee = (*nit)->getDstNode()->getCallNode()->getFunction(); @@ -321,7 +321,7 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) void MHP::handleRet(const CxtThreadStmt& cts) { PTACallGraphNode* curFunNode = - tcg->getPTACallGraphNode(cts.getStmt()->getFun()->getCallGraphNode()); + tcg->getPTACallGraphNode(cts.getStmt()->getFun()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) @@ -595,9 +595,9 @@ bool MHP::mayHappenInParallelInst(const ICFGNode* i1, const ICFGNode* i2) bool MHP::mayHappenInParallelCache(const ICFGNode* i1, const ICFGNode* i2) { - if (!tct->isCandidateFun(i1->getFun()) && !tct->isCandidateFun(i2->getFun())) + if (!tct->isCandidateFun(i1->getFun()->getFunction()) && !tct->isCandidateFun(i2->getFun()->getFunction())) { - FuncPair funpair = std::make_pair(i1->getFun(), i2->getFun()); + FuncPair funpair = std::make_pair(i1->getFun()->getFunction(), i2->getFun()->getFunction()); FuncPairToBool::const_iterator it = nonCandidateFuncMHPRelMap.find(funpair); if (it == nonCandidateFuncMHPRelMap.end()) { @@ -909,7 +909,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) const CallStrCxt& curCxt = cts.getContext(); PTACallGraphNode* curFunNode = - getTCG()->getPTACallGraphNode(curInst->getFun()->getCallGraphNode()); + getTCG()->getPTACallGraphNode(curInst->getFun()); for (PTACallGraphEdge* edge : curFunNode->getInEdges()) { if (SVFUtil::isa(edge)) diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index 4b110b787..ea7cccb6d 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -56,7 +56,7 @@ bool TCT::isInLoopInstruction(const ICFGNode* inst) const ICFGNode* inst = worklist.pop(); insts.insert(inst); PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(inst->getFun()->getCallGraphNode()); + tcg->getPTACallGraphNode(inst->getFun()); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(), @@ -91,35 +91,35 @@ bool TCT::isInLoopInstruction(const ICFGNode* inst) */ bool TCT::isInRecursion(const ICFGNode* inst) const { - const SVFFunction* f = inst->getFun(); - FIFOWorkList worklist; - Set visits; + const CallGraphNode* f = inst->getFun(); + FIFOWorkList worklist; + Set visits; worklist.push(f); while(!worklist.empty()) { - const SVFFunction* svffun = worklist.pop(); + const CallGraphNode* svffun = worklist.pop(); visits.insert(svffun); if(tcgSCC->isInCycle( - tcg->getPTACallGraphNode(svffun->getCallGraphNode())->getId())) + tcg->getPTACallGraphNode(svffun)->getId())) return true; const PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(svffun->getCallGraphNode()); + tcg->getPTACallGraphNode(svffun); for(PTACallGraphNode::const_iterator nit = cgnode->InEdgeBegin(), neit = cgnode->InEdgeEnd(); nit!=neit; nit++) { for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->directCallsBegin(), ecit = (*nit)->directCallsEnd(); cit!=ecit; ++cit) { - const SVFFunction* caller = (*cit)->getFun(); + const CallGraphNode* caller = (*cit)->getFun(); if(visits.find(caller)==visits.end()) worklist.push(caller); } for(PTACallGraphEdge::CallInstSet::const_iterator cit = (*nit)->indirectCallsBegin(), ecit = (*nit)->indirectCallsEnd(); cit!=ecit; ++cit) { - const SVFFunction* caller = (*cit)->getFun(); + const CallGraphNode* caller = (*cit)->getFun(); if(visits.find(caller)==visits.end()) worklist.push(caller); } @@ -296,7 +296,7 @@ void TCT::handleCallRelation(CxtThreadProc& ctp, const PTACallGraphEdge* cgEdge, bool TCT::isJoinMustExecutedInLoop(const LoopBBs& lp,const ICFGNode* join) { assert(!lp.empty() && "this is not a loop, empty basic block"); - const SVFFunction* svffun = join->getFun(); + const CallGraphNode* svffun = join->getFun(); const SVFBasicBlock* loopheadbb = svffun->getLoopHeader(lp); const SVFBasicBlock* joinbb = join->getBB(); assert(loopheadbb->getParent()==joinbb->getParent() && "should inside same function"); @@ -322,7 +322,7 @@ void TCT::collectLoopInfoForJoin() for(ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it!=eit; ++it) { const ICFGNode* join = *it; - const SVFFunction* svffun = join->getFun(); + const CallGraphNode* svffun = join->getFun(); const SVFBasicBlock* svfbb = join->getBB(); if(svffun->hasLoopInfo(svfbb)) @@ -451,15 +451,15 @@ void TCT::build() void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { - const SVFFunction* caller = call->getFun(); + const CallGraphNode* caller = call->getFun(); CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); /// handle calling context for candidate functions only - if(isCandidateFun(caller) == false) + if(isCandidateFun(caller->getFunction()) == false) return; if(inSameCallGraphSCC( - tcg->getPTACallGraphNode(caller->getCallGraphNode()), + tcg->getPTACallGraphNode(caller), tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) { pushCxt(cxt,csId); @@ -474,11 +474,11 @@ void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) { - const SVFFunction* caller = call->getFun(); + const CallGraphNode* caller = call->getFun(); CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); /// handle calling context for candidate functions only - if(isCandidateFun(caller) == false) + if(isCandidateFun(caller->getFunction()) == false) return true; /// partial match @@ -486,7 +486,7 @@ bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* return true; if(inSameCallGraphSCC( - tcg->getPTACallGraphNode(caller->getCallGraphNode()), + tcg->getPTACallGraphNode(caller), tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) { if(cxt.back() == csId) diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 0fb2f36a8..37e42f514 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -407,7 +407,7 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta newEdges[cs].insert(callee->getCallGraphNode()); getIndCallMap()[cs].insert(callee->getCallGraphNode()); - callgraph->addIndirectCallGraphEdge(cs, cs->getCaller(), callee); + callgraph->addIndirectCallGraphEdge(cs, cs->getCaller(), callee->getCallGraphNode()); // FIXME: do we need to update llvm call graph here? // The indirect call is maintained by ourself, We may update llvm's when we need to //PTACallGraphNode* callgraphNode = callgraph->getOrInsertFunction(cs.getCaller()); @@ -481,7 +481,7 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & newEdges[cs].insert(callee); getIndCallMap()[cs].insert(callee); const CallICFGNode* callBlockNode = cs; - callgraph->addIndirectCallGraphEdge(callBlockNode, cs->getCaller(),callee->getFunction()); + callgraph->addIndirectCallGraphEdge(callBlockNode, cs->getCaller(),callee); } } } diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index a2cb8da2d..5ff04600b 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -71,7 +71,7 @@ void SVFVar::dump() const const SVFFunction* ValVar::getFunction() const { if(icfgNode) - return icfgNode->getFun(); + return icfgNode->getFun()->getFunction(); return nullptr; } @@ -205,7 +205,7 @@ bool BaseObjVar::isBlackHoleObj() const const SVFFunction* BaseObjVar::getFunction() const { if(icfgNode) - return icfgNode->getFun(); + return icfgNode->getFun()->getFunction(); return nullptr; } const std::string BaseObjVar::toString() const From ee859522c44dedae6555f39ccaed3b0f0f325f14 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 16:52:41 +1100 Subject: [PATCH 15/45] refactoring FunToFunEntryNodeMapTy in ICFG,h --- svf-llvm/lib/ICFGBuilder.cpp | 4 ++-- svf/include/Graphs/CallGraph.h | 24 +++++++++++++++++++++++- svf/include/Graphs/ICFG.h | 12 ++++++------ svf/include/Graphs/ICFGNode.h | 4 ++-- svf/lib/Graphs/ICFG.cpp | 14 +++++++------- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index eb86750a3..3e9473369 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -353,11 +353,11 @@ IntraICFGNode* ICFGBuilder::addIntraBlockICFGNode(const Instruction* inst) FunEntryICFGNode* ICFGBuilder::addFunEntryBlock(const Function* fun) { return llvmModuleSet()->FunToFunEntryNodeMap[fun] = - icfg->addFunEntryICFGNode(llvmModuleSet()->getSVFFunction(fun)); + icfg->addFunEntryICFGNode(llvmModuleSet()->getCallGraphNode(fun)); } inline FunExitICFGNode* ICFGBuilder::addFunExitBlock(const Function* fun) { return llvmModuleSet()->FunToFunExitNodeMap[fun] = - icfg->addFunExitICFGNode(llvmModuleSet()->getSVFFunction(fun)); + icfg->addFunExitICFGNode(llvmModuleSet()->getCallGraphNode(fun)); } \ No newline at end of file diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index feda4a809..5cc6ed381 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -121,7 +121,9 @@ class CallGraphNode : public GenericCallGraphNodeTy typedef SVFLoopAndDomInfo::BBSet BBSet; typedef SVFLoopAndDomInfo::BBList BBList; typedef SVFLoopAndDomInfo::LoopBBs LoopBBs; - typedef std::vector::const_iterator bb_const_iterator; + + typedef BasicBlockGraph::IDToNodeMapTy::const_iterator const_bb_iterator; + private: const SVFFunction* fun; @@ -304,9 +306,29 @@ class CallGraphNode : public GenericCallGraphNodeTy return allArgs[idx]; } + inline const SVFBasicBlock* front() const + { + return getEntryBlock(); + } + inline const SVFBasicBlock* back() const + { + assert(hasBasicBlock() && "function does not have any Basicblock, external function?"); + /// Carefully! 'back' is just the last basic block of function, + /// but not necessarily a exit basic block + /// more refer to: https://github.com/SVF-tools/SVF/pull/1262 + return std::prev(bbGraph->end())->second; + } + inline const_bb_iterator begin() const + { + return bbGraph->begin(); + } + inline const_bb_iterator end() const + { + return bbGraph->end(); + } inline const std::string &getName() const { diff --git a/svf/include/Graphs/ICFG.h b/svf/include/Graphs/ICFG.h index e693e10bc..c37b3cb4e 100644 --- a/svf/include/Graphs/ICFG.h +++ b/svf/include/Graphs/ICFG.h @@ -58,8 +58,8 @@ class ICFG : public GenericICFGTy typedef ICFGNodeIDToNodeMapTy::iterator iterator; typedef ICFGNodeIDToNodeMapTy::const_iterator const_iterator; - typedef Map FunToFunEntryNodeMapTy; - typedef Map FunToFunExitNodeMapTy; + typedef Map FunToFunEntryNodeMapTy; + typedef Map FunToFunExitNodeMapTy; typedef std::vector SVFLoopVec; typedef Map ICFGNodeToSVFLoopVec; @@ -201,14 +201,14 @@ class ICFG : public GenericICFGTy return retICFGNode; } - virtual inline FunEntryICFGNode* addFunEntryICFGNode(const SVFFunction* svfFunc) + virtual inline FunEntryICFGNode* addFunEntryICFGNode(const CallGraphNode* svfFunc) { FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,svfFunc); addICFGNode(sNode); return FunToFunEntryNodeMap[svfFunc] = sNode; } - virtual inline FunExitICFGNode* addFunExitICFGNode(const SVFFunction* svfFunc) + virtual inline FunExitICFGNode* addFunExitICFGNode(const CallGraphNode* svfFunc) { FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, svfFunc); addICFGNode(sNode); @@ -284,7 +284,7 @@ class ICFG : public GenericICFGTy } /// Get/Add a function entry node - inline FunEntryICFGNode* getFunEntryBlock(const SVFFunction* fun) + inline FunEntryICFGNode* getFunEntryBlock(const CallGraphNode* fun) { FunToFunEntryNodeMapTy::const_iterator it = FunToFunEntryNodeMap.find(fun); if (it == FunToFunEntryNodeMap.end()) @@ -293,7 +293,7 @@ class ICFG : public GenericICFGTy } /// Get/Add a function exit node - inline FunExitICFGNode* getFunExitBlock(const SVFFunction* fun) + inline FunExitICFGNode* getFunExitBlock(const CallGraphNode* fun) { FunToFunExitNodeMapTy::const_iterator it = FunToFunExitNodeMap.find(fun); if (it == FunToFunExitNodeMap.end()) diff --git a/svf/include/Graphs/ICFGNode.h b/svf/include/Graphs/ICFGNode.h index 86fc550fd..6d28463b2 100644 --- a/svf/include/Graphs/ICFGNode.h +++ b/svf/include/Graphs/ICFGNode.h @@ -289,7 +289,7 @@ class FunEntryICFGNode : public InterICFGNode FunEntryICFGNode(NodeID id) : InterICFGNode(id, FunEntryBlock) {} public: - FunEntryICFGNode(NodeID id, const SVFFunction* f); + FunEntryICFGNode(NodeID id, const CallGraphNode* f); /// Return function inline const CallGraphNode* getFun() const override @@ -358,7 +358,7 @@ class FunExitICFGNode : public InterICFGNode FunExitICFGNode(NodeID id) : InterICFGNode(id, FunExitBlock), formalRet{} {} public: - FunExitICFGNode(NodeID id, const SVFFunction* f); + FunExitICFGNode(NodeID id, const CallGraphNode* f); /// Return function inline const CallGraphNode* getFun() const override diff --git a/svf/lib/Graphs/ICFG.cpp b/svf/lib/Graphs/ICFG.cpp index af9f1ab70..acd5ed1a6 100644 --- a/svf/lib/Graphs/ICFG.cpp +++ b/svf/lib/Graphs/ICFG.cpp @@ -37,9 +37,9 @@ using namespace SVF; using namespace SVFUtil; -FunEntryICFGNode::FunEntryICFGNode(NodeID id, const SVFFunction* f) : InterICFGNode(id, FunEntryBlock) +FunEntryICFGNode::FunEntryICFGNode(NodeID id, const CallGraphNode* f) : InterICFGNode(id, FunEntryBlock) { - fun = f->getCallGraphNode(); + fun = f; // if function is implemented if (f->begin() != f->end()) { @@ -47,10 +47,10 @@ FunEntryICFGNode::FunEntryICFGNode(NodeID id, const SVFFunction* f) : InterICFGN } } -FunExitICFGNode::FunExitICFGNode(NodeID id, const SVFFunction* f) +FunExitICFGNode::FunExitICFGNode(NodeID id, const CallGraphNode* f) : InterICFGNode(id, FunExitBlock), formalRet(nullptr) { - fun = f->getCallGraphNode(); + fun = f; // if function is implemented if (f->begin() != f->end()) { @@ -242,14 +242,14 @@ ICFG::~ICFG() /// Add a function entry node FunEntryICFGNode* ICFG::getFunEntryICFGNode(const SVFFunction* fun) { - FunEntryICFGNode* entry = getFunEntryBlock(fun); + FunEntryICFGNode* entry = getFunEntryBlock(fun->getCallGraphNode()); assert (entry && "fun entry not created in ICFGBuilder?"); return entry; } /// Add a function exit node FunExitICFGNode* ICFG::getFunExitICFGNode(const SVFFunction* fun) { - FunExitICFGNode* exit = getFunExitBlock(fun); + FunExitICFGNode* exit = getFunExitBlock(fun->getCallGraphNode()); assert (exit && "fun exit not created in ICFGBuilder?"); return exit; } @@ -436,7 +436,7 @@ void ICFG::updateCallGraph(PTACallGraph* callgraph) const PTACallGraph::FunctionSet & functions = iter->second; for (PTACallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* callee = (*func_iter)->getFunction(); + const CallGraphNode* callee = *func_iter; RetICFGNode* retBlockNode = const_cast(callBlockNode->getRetICFGNode()); /// if this is an external function (no function body), connect calleeEntryNode to calleeExitNode if (isExtCall(callee)) From 20ec9779c77663701a17d5143d4d8c2f04297e82 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 17:04:53 +1100 Subject: [PATCH 16/45] refactoring getIndCallSitesInvokingCallee in PTACallGraph.h,h --- svf/include/DDA/DDAVFSolver.h | 2 +- svf/include/Graphs/PTACallGraph.h | 8 ++++---- svf/lib/Graphs/PTACallGraph.cpp | 18 +++++++++--------- svf/lib/Graphs/SVFG.cpp | 4 ++-- svf/lib/Graphs/SVFGReadWrite.cpp | 4 ++-- svf/lib/WPA/VersionedFlowSensitive.cpp | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index 4abec7c9e..be7ad9343 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -506,7 +506,7 @@ class DDAVFSolver { CallInstSet csSet; /// use pre-analysis call graph to approximate all potential callsites - _ander->getCallGraph()->getIndCallSitesInvokingCallee(fun,csSet); + _ander->getCallGraph()->getIndCallSitesInvokingCallee(fun->getCallGraphNode(),csSet); for(CallInstSet::const_iterator it = csSet.begin(), eit = csSet.end(); it!=eit; ++it) { NodeID funPtr = _pag->getFunPtr(*it); diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 63df3bb7d..62f68de96 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -454,13 +454,13 @@ class PTACallGraph : public GenericPTACallGraphTy /// Get callsites invoking the callee //@{ - void getAllCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet); - void getDirCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet); - void getIndCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet); + void getAllCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet); + void getDirCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet); + void getIndCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet); //@} /// Whether its reachable between two functions - bool isReachableBetweenFunctions(const SVFFunction* srcFn, const SVFFunction* dstFn) const; + bool isReachableBetweenFunctions(const CallGraphNode* srcFn, const CallGraphNode* dstFn) const; /// Dump the graph void dump(const std::string& filename); diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 3ad1501f5..4df3885d6 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -219,10 +219,10 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const CallGra /*! * Get all callsite invoking this callee */ -void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) +void PTACallGraph::getAllCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet) { PTACallGraphNode* callGraphNode = - getPTACallGraphNode(callee->getCallGraphNode()); + getPTACallGraphNode(callee); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -242,10 +242,10 @@ void PTACallGraph::getAllCallSitesInvokingCallee(const SVFFunction* callee, PTAC /*! * Get direct callsite invoking this callee */ -void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) +void PTACallGraph::getDirCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet) { PTACallGraphNode* callGraphNode = - getPTACallGraphNode(callee->getCallGraphNode()); + getPTACallGraphNode(callee); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -260,10 +260,10 @@ void PTACallGraph::getDirCallSitesInvokingCallee(const SVFFunction* callee, PTAC /*! * Get indirect callsite invoking this callee */ -void PTACallGraph::getIndCallSitesInvokingCallee(const SVFFunction* callee, PTACallGraphEdge::CallInstSet& csSet) +void PTACallGraph::getIndCallSitesInvokingCallee(const CallGraphNode* callee, PTACallGraphEdge::CallInstSet& csSet) { PTACallGraphNode* callGraphNode = - getPTACallGraphNode(callee->getCallGraphNode()); + getPTACallGraphNode(callee); for(PTACallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd(); it!=eit; ++it) { @@ -298,9 +298,9 @@ void PTACallGraph::verifyCallGraph() /*! * Whether its reachable between two functions */ -bool PTACallGraph::isReachableBetweenFunctions(const SVFFunction* srcFn, const SVFFunction* dstFn) const +bool PTACallGraph::isReachableBetweenFunctions(const CallGraphNode* srcFn, const CallGraphNode* dstFn) const { - PTACallGraphNode* dstNode = getPTACallGraphNode(dstFn->getCallGraphNode()); + PTACallGraphNode* dstNode = getPTACallGraphNode(dstFn); std::stack nodeStack; NodeBS visitedNodes; @@ -312,7 +312,7 @@ bool PTACallGraph::isReachableBetweenFunctions(const SVFFunction* srcFn, const S PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (node->getCallNode()->getFunction() == srcFn) + if (node->getCallNode() == srcFn) return true; for (CallGraphEdgeConstIter it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index da55360de..425dc20d5 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -361,7 +361,7 @@ void SVFG::connectIndirectSVFGEdges() else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun()->getCallGraphNode(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; @@ -379,7 +379,7 @@ void SVFG::connectIndirectSVFGEdges() { PTACallGraphEdge::CallInstSet callInstSet; // const MemSSA::RETMU* retMu = formalOut->getRetMU(); - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun()->getCallGraphNode(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; diff --git a/svf/lib/Graphs/SVFGReadWrite.cpp b/svf/lib/Graphs/SVFGReadWrite.cpp index 4b0eb0c78..4cb969880 100644 --- a/svf/lib/Graphs/SVFGReadWrite.cpp +++ b/svf/lib/Graphs/SVFGReadWrite.cpp @@ -145,7 +145,7 @@ void SVFG::writeToFile(const string& filename) else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun()->getCallGraphNode(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; @@ -162,7 +162,7 @@ void SVFG::writeToFile(const string& filename) else if(const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun()->getCallGraphNode(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; diff --git a/svf/lib/WPA/VersionedFlowSensitive.cpp b/svf/lib/WPA/VersionedFlowSensitive.cpp index 551bf000a..90950173d 100644 --- a/svf/lib/WPA/VersionedFlowSensitive.cpp +++ b/svf/lib/WPA/VersionedFlowSensitive.cpp @@ -485,7 +485,7 @@ void VersionedFlowSensitive::buildDeltaMaps(void) { PTACallGraphEdge::CallInstSet callsites; /// use pre-analysis call graph to approximate all potential callsites - ander->getCallGraph()->getIndCallSitesInvokingCallee(fn, callsites); + ander->getCallGraph()->getIndCallSitesInvokingCallee(fn->getCallGraphNode(), callsites); isDelta = !callsites.empty(); if (isDelta) From 6db5bad48b90561fdff61c72f70680f905f2c12c Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 17:19:53 +1100 Subject: [PATCH 17/45] refactoring getFunEntryICFGNode in ICFG.h --- svf-llvm/include/SVF-LLVM/SVFIRBuilder.h | 8 ++++---- svf-llvm/lib/SVFIRBuilder.cpp | 18 +++++++++--------- svf-llvm/lib/SVFIRExtAPI.cpp | 2 +- svf/include/Graphs/ICFG.h | 16 ++++++++-------- svf/include/Graphs/SVFG.h | 4 ++-- svf/include/Graphs/SVFGOPT.h | 2 +- svf/include/Graphs/VFG.h | 4 ++-- svf/include/SVFIR/SVFIR.h | 4 ++-- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 2 +- svf/lib/Graphs/ICFG.cpp | 8 ++++---- svf/lib/Graphs/SVFG.cpp | 4 ++-- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h index bdf2dac5e..41982042a 100644 --- a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +++ b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h @@ -102,15 +102,15 @@ class SVFIRBuilder: public llvm::InstVisitor } /// getReturnNode - Return the node representing the unique return value of a function. - inline NodeID getReturnNode(const SVFFunction *func) + inline NodeID getReturnNode(const CallGraphNode *func) { - return pag->getReturnNode(func); + return pag->getReturnNode(func->getFunction()); } /// getVarargNode - Return the node representing the unique variadic argument of a function. - inline NodeID getVarargNode(const SVFFunction *func) + inline NodeID getVarargNode(const CallGraphNode *func) { - return pag->getVarargNode(func); + return pag->getVarargNode(func->getFunction()); } //@} diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 54cb025f7..366443290 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -1040,7 +1040,7 @@ void SVFIRBuilder::visitReturnInst(ReturnInst &inst) if(Value* src = inst.getReturnValue()) { - const SVFFunction *F = llvmModuleSet()->getSVFFunction(inst.getParent()->getParent()); + const CallGraphNode *F = llvmModuleSet()->getCallGraphNode(inst.getParent()->getParent()); NodeID rnF = getReturnNode(F); NodeID vnS = getValueNode(src); @@ -1233,7 +1233,7 @@ void SVFIRBuilder::handleDirectCall(CallBase* cs, const Function *F) assert(F); CallICFGNode* callICFGNode = llvmModuleSet()->getCallICFGNode(cs); - const SVFFunction* svffun = llvmModuleSet()->getSVFFunction(F); + const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(F); DBOUT(DPAGBuild, outs() << "handle direct call " << LLVMUtil::dumpValue(cs) << " callee " << F->getName().str() << "\n"); @@ -1242,8 +1242,8 @@ void SVFIRBuilder::handleDirectCall(CallBase* cs, const Function *F) //Does it actually return a ptr? if (!cs->getType()->isVoidTy()) { - NodeID srcret = getReturnNode(svffun); - FunExitICFGNode* exitICFGNode = pag->getICFG()->getFunExitICFGNode(svffun); + NodeID srcret = getReturnNode(cgn); + FunExitICFGNode* exitICFGNode = pag->getICFG()->getFunExitICFGNode(cgn); addRetEdge(srcret, dstrec,callICFGNode, exitICFGNode); } //Iterators for the actual and formal parameters @@ -1265,19 +1265,19 @@ void SVFIRBuilder::handleDirectCall(CallBase* cs, const Function *F) NodeID dstFA = getValueNode(FA); NodeID srcAA = getValueNode(AA); - FunEntryICFGNode* entry = pag->getICFG()->getFunEntryICFGNode(svffun); + FunEntryICFGNode* entry = pag->getICFG()->getFunEntryICFGNode(cgn); addCallEdge(srcAA, dstFA, callICFGNode, entry); } //Any remaining actual args must be varargs. if (F->isVarArg()) { - NodeID vaF = getVarargNode(svffun); + NodeID vaF = getVarargNode(cgn); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; itA != ieA; ++itA) { const Value* AA = cs->getArgOperand(itA); NodeID vnAA = getValueNode(AA); - FunEntryICFGNode* entry = pag->getICFG()->getFunEntryICFGNode(svffun); + FunEntryICFGNode* entry = pag->getICFG()->getFunEntryICFGNode(cgn); addCallEdge(vnAA,vaF, callICFGNode,entry); } } @@ -1466,7 +1466,7 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge) /// We will have one unique function exit ICFGNode for all returns if(curInst->isRetInst()) { - icfgNode = pag->getICFG()->getFunExitICFGNode(curInst->getFunction()); + icfgNode = pag->getICFG()->getFunExitICFGNode(curInst->getFunction()->getCallGraphNode()); } else { @@ -1479,7 +1479,7 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge) else if (const SVFArgument* arg = SVFUtil::dyn_cast(curVal)) { assert(curBB && (curBB->getParent()->getEntryBlock() == curBB)); - icfgNode = pag->getICFG()->getFunEntryICFGNode(arg->getParent()); + icfgNode = pag->getICFG()->getFunEntryICFGNode(arg->getParent()->getCallGraphNode()); } else if (SVFUtil::isa(curVal) || SVFUtil::isa(curVal) || diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index 776dc599d..26176c53a 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -276,7 +276,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle /// Connect actual parameter to formal parameter of the start routine if (actualParm->isPointer() && formalParm->getType()->isPointerTy()) { - FunEntryICFGNode *entry = pag->getICFG()->getFunEntryICFGNode(forkedFun); + FunEntryICFGNode *entry = pag->getICFG()->getFunEntryICFGNode(forkedFun->getCallGraphNode()); addThreadForkEdge(actualParm->getId(), llvmModuleSet()->getValueNode(formalParm), callICFGNode, entry); } } diff --git a/svf/include/Graphs/ICFG.h b/svf/include/Graphs/ICFG.h index c37b3cb4e..5be398d5c 100644 --- a/svf/include/Graphs/ICFG.h +++ b/svf/include/Graphs/ICFG.h @@ -201,18 +201,18 @@ class ICFG : public GenericICFGTy return retICFGNode; } - virtual inline FunEntryICFGNode* addFunEntryICFGNode(const CallGraphNode* svfFunc) + virtual inline FunEntryICFGNode* addFunEntryICFGNode(const CallGraphNode* cgn) { - FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,svfFunc); + FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++, cgn); addICFGNode(sNode); - return FunToFunEntryNodeMap[svfFunc] = sNode; + return FunToFunEntryNodeMap[cgn] = sNode; } - virtual inline FunExitICFGNode* addFunExitICFGNode(const CallGraphNode* svfFunc) + virtual inline FunExitICFGNode* addFunExitICFGNode(const CallGraphNode* cgn) { - FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, svfFunc); + FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, cgn); addICFGNode(sNode); - return FunToFunExitNodeMap[svfFunc] = sNode; + return FunToFunExitNodeMap[cgn] = sNode; } /// Add a ICFG node @@ -229,9 +229,9 @@ class ICFG : public GenericICFGTy //@{ - FunEntryICFGNode* getFunEntryICFGNode(const SVFFunction* fun); + FunEntryICFGNode* getFunEntryICFGNode(const CallGraphNode* fun); - FunExitICFGNode* getFunExitICFGNode(const SVFFunction* fun); + FunExitICFGNode* getFunExitICFGNode(const CallGraphNode* fun); inline GlobalICFGNode* getGlobalICFGNode() const { diff --git a/svf/include/Graphs/SVFG.h b/svf/include/Graphs/SVFG.h index b11e5dd20..db44d35a8 100644 --- a/svf/include/Graphs/SVFG.h +++ b/svf/include/Graphs/SVFG.h @@ -403,7 +403,7 @@ class SVFG : public VFG inline void addFormalINSVFGNode(const FunEntryICFGNode* funEntry, const MRVer* resVer, const NodeID nodeId) { FormalINSVFGNode* sNode = new FormalINSVFGNode(nodeId, resVer, funEntry); - addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun()->getFunction())); + addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun())); setDef(resVer,sNode); funToFormalINMap[funEntry->getFun()->getFunction()].set(sNode->getId()); } @@ -412,7 +412,7 @@ class SVFG : public VFG inline void addFormalOUTSVFGNode(const FunExitICFGNode* funExit, const MRVer* ver, const NodeID nodeId) { FormalOUTSVFGNode* sNode = new FormalOUTSVFGNode(nodeId, ver, funExit); - addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun()->getFunction())); + addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun())); funToFormalOUTMap[funExit->getFun()->getFunction()].set(sNode->getId()); } diff --git a/svf/include/Graphs/SVFGOPT.h b/svf/include/Graphs/SVFGOPT.h index b9814a970..c3960a572 100644 --- a/svf/include/Graphs/SVFGOPT.h +++ b/svf/include/Graphs/SVFGOPT.h @@ -244,7 +244,7 @@ class SVFGOPT : public SVFG inline InterPHISVFGNode* addInterPHIForFP(const FormalParmSVFGNode* fp) { InterPHISVFGNode* sNode = new InterPHISVFGNode(totalVFGNode++,fp); - addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fp->getFun())); + addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fp->getFun()->getCallGraphNode())); resetDef(fp->getParam(),sNode); return sNode; } diff --git a/svf/include/Graphs/VFG.h b/svf/include/Graphs/VFG.h index 1e6637d28..1b013af55 100644 --- a/svf/include/Graphs/VFG.h +++ b/svf/include/Graphs/VFG.h @@ -538,7 +538,7 @@ class VFG : public GenericVFGTy inline void addFormalParmVFGNode(const PAGNode* fparm, const SVFFunction* fun, CallPESet& callPEs) { FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun); - addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun)); + addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun->getCallGraphNode())); for(CallPESet::const_iterator it = callPEs.begin(), eit=callPEs.end(); it!=eit; ++it) sNode->addCallPE(*it); @@ -552,7 +552,7 @@ class VFG : public GenericVFGTy inline void addFormalRetVFGNode(const PAGNode* uniqueFunRet, const SVFFunction* fun, RetPESet& retPEs) { FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun); - addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun)); + addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun->getCallGraphNode())); for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it) sNode->addRetPE(*it); diff --git a/svf/include/SVFIR/SVFIR.h b/svf/include/SVFIR/SVFIR.h index f8cda4c74..92202532b 100644 --- a/svf/include/SVFIR/SVFIR.h +++ b/svf/include/SVFIR/SVFIR.h @@ -506,14 +506,14 @@ class SVFIR : public IRGraph /// Add function arguments inline void addFunArgs(const SVFFunction* fun, const SVFVar* arg) { - FunEntryICFGNode* funEntryBlockNode = icfg->getFunEntryICFGNode(fun); + FunEntryICFGNode* funEntryBlockNode = icfg->getFunEntryICFGNode(fun->getCallGraphNode()); funEntryBlockNode->addFormalParms(arg); funArgsListMap[fun].push_back(arg); } /// Add function returns inline void addFunRet(const SVFFunction* fun, const SVFVar* ret) { - FunExitICFGNode* funExitBlockNode = icfg->getFunExitICFGNode(fun); + FunExitICFGNode* funExitBlockNode = icfg->getFunExitICFGNode(fun->getCallGraphNode()); funExitBlockNode->addFormalRet(ret); funRetMap[fun] = ret; } diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index d67e2a49b..6f13d1f5e 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -94,7 +94,7 @@ void AbstractInterpretation::initWTO() recursiveFuns.insert(it->second); // Mark the function as recursive if (it->second->getFunction()->isDeclaration()) continue; - auto* wto = new ICFGWTO(icfg, icfg->getFunEntryICFGNode(it->second->getFunction())); + auto* wto = new ICFGWTO(icfg, icfg->getFunEntryICFGNode(it->second)); wto->init(); funcToWTO[it->second] = wto; } diff --git a/svf/lib/Graphs/ICFG.cpp b/svf/lib/Graphs/ICFG.cpp index acd5ed1a6..ef2241b27 100644 --- a/svf/lib/Graphs/ICFG.cpp +++ b/svf/lib/Graphs/ICFG.cpp @@ -240,16 +240,16 @@ ICFG::~ICFG() /// Add a function entry node -FunEntryICFGNode* ICFG::getFunEntryICFGNode(const SVFFunction* fun) +FunEntryICFGNode* ICFG::getFunEntryICFGNode(const CallGraphNode* fun) { - FunEntryICFGNode* entry = getFunEntryBlock(fun->getCallGraphNode()); + FunEntryICFGNode* entry = getFunEntryBlock(fun); assert (entry && "fun entry not created in ICFGBuilder?"); return entry; } /// Add a function exit node -FunExitICFGNode* ICFG::getFunExitICFGNode(const SVFFunction* fun) +FunExitICFGNode* ICFG::getFunExitICFGNode(const CallGraphNode* fun) { - FunExitICFGNode* exit = getFunExitBlock(fun->getCallGraphNode()); + FunExitICFGNode* exit = getFunExitBlock(fun); assert (exit && "fun exit not created in ICFGBuilder?"); return exit; } diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index 425dc20d5..585d6ba1d 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -286,7 +286,7 @@ void SVFG::addSVFGNodesForAddrTakenVars() for(CHISet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi) { const MemSSA::ENTRYCHI* chi = SVFUtil::cast(*pi); - addFormalINSVFGNode(pag->getICFG()->getFunEntryICFGNode(chi->getFunction()), chi->getResVer(), totalVFGNode++); + addFormalINSVFGNode(pag->getICFG()->getFunEntryICFGNode(chi->getFunction()->getCallGraphNode()), chi->getResVer(), totalVFGNode++); } } /// initialize memory SSA return mu nodes @@ -296,7 +296,7 @@ void SVFG::addSVFGNodesForAddrTakenVars() for(MUSet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi) { const MemSSA::RETMU* mu = SVFUtil::cast(*pi); - addFormalOUTSVFGNode(pag->getICFG()->getFunExitICFGNode(mu->getFunction()), mu->getMRVer(), totalVFGNode++); + addFormalOUTSVFGNode(pag->getICFG()->getFunExitICFGNode(mu->getFunction()->getCallGraphNode()), mu->getMRVer(), totalVFGNode++); } } /// initialize memory SSA callsite mu nodes From 2536485433b487636982cdb3b99a1e3ef28c67a8 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 17:39:25 +1100 Subject: [PATCH 18/45] rm SVFFunction in CHG.h --- svf-llvm/lib/CHGBuilder.cpp | 24 ++++++++++++------------ svf/include/Graphs/CHG.h | 12 ++++++------ svf/lib/Graphs/CHG.cpp | 11 ++++++----- svf/lib/WPA/TypeAnalysis.cpp | 6 +++--- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/svf-llvm/lib/CHGBuilder.cpp b/svf-llvm/lib/CHGBuilder.cpp index 25505e944..11c8e1b9c 100644 --- a/svf-llvm/lib/CHGBuilder.cpp +++ b/svf-llvm/lib/CHGBuilder.cpp @@ -539,7 +539,7 @@ void CHGBuilder::analyzeVTables(const Module &M) { for (int i = 0; i < null_ptr_num; ++i) { - const SVFFunction* fun = virtualFunctions[i]; + const CallGraphNode* fun = virtualFunctions[i]; virtualFunctions.insert(virtualFunctions.begin(), fun); } } @@ -607,7 +607,7 @@ void CHGBuilder::buildVirtualFunctionToIDMap() /* * get all virtual functions in a specific group */ - set virtualFunctions; + set virtualFunctions; for (CHGraph::CHNodeSetTy::iterator it = group.begin(), eit = group.end(); it != eit; ++it) { @@ -615,7 +615,7 @@ void CHGBuilder::buildVirtualFunctionToIDMap() for (vector::const_iterator vit = vecs.begin(), veit = vecs.end(); vit != veit; ++vit) { - for (vector::const_iterator fit = (*vit).begin(), + for (vector::const_iterator fit = (*vit).begin(), feit = (*vit).end(); fit != feit; ++fit) { virtualFunctions.insert(*fit); @@ -638,15 +638,15 @@ void CHGBuilder::buildVirtualFunctionToIDMap() * <~C, C::~C> * ... */ - set > fNameSet; - for (set::iterator fit = virtualFunctions.begin(), + set > fNameSet; + for (set::iterator fit = virtualFunctions.begin(), feit = virtualFunctions.end(); fit != feit; ++fit) { - const SVFFunction* f = *fit; + const CallGraphNode* f = *fit; struct DemangledName dname = demangle(f->getName()); - fNameSet.insert(pair(dname.funcName, f)); + fNameSet.insert(pair(dname.funcName, f)); } - for (set>::iterator it = fNameSet.begin(), + for (set>::iterator it = fNameSet.begin(), eit = fNameSet.end(); it != eit; ++it) { chg->virtualFunctionToIDMap[it->second] = chg->vfID++; @@ -742,15 +742,15 @@ void CHGBuilder::addFuncToFuncVector(CHNode::FuncVector &v, const Function *lf) { if (const auto* tf = cppUtil::getThunkTarget(lf)) { - SVFFunction* pFunction = - llvmModuleSet()->getSVFFunction(tf); + CallGraphNode* pFunction = + llvmModuleSet()->getCallGraphNode(tf); v.push_back(pFunction); } } else { - SVFFunction* pFunction = - llvmModuleSet()->getSVFFunction(lf); + CallGraphNode* pFunction = + llvmModuleSet()->getCallGraphNode(lf); v.push_back(pFunction); } } diff --git a/svf/include/Graphs/CHG.h b/svf/include/Graphs/CHG.h index e7ccf260f..1ae8ff2a7 100644 --- a/svf/include/Graphs/CHG.h +++ b/svf/include/Graphs/CHG.h @@ -119,7 +119,7 @@ class CHNode: public GenericCHNodeTy TEMPLATE = 0x04 // template class } CLASSATTR; - typedef std::vector FuncVector; + typedef std::vector FuncVector; CHNode (const std::string& name, NodeID i = 0, GNodeK k = CHNodeKd): GenericCHNodeTy(i, k), vtable(nullptr), className(name), flags(0) @@ -267,18 +267,18 @@ class CHGraph: public CommonCHGraph, public GenericCHGraphTy void view(); void printCH(); - inline u32_t getVirtualFunctionID(const SVFFunction* vfn) const + inline u32_t getVirtualFunctionID(const CallGraphNode* vfn) const { - Map::const_iterator it = + Map::const_iterator it = virtualFunctionToIDMap.find(vfn); if (it != virtualFunctionToIDMap.end()) return it->second; else return -1; } - inline const SVFFunction* getVirtualFunctionBasedonID(u32_t id) const + inline const CallGraphNode* getVirtualFunctionBasedonID(u32_t id) const { - Map::const_iterator it, eit; + Map::const_iterator it, eit; for (it = virtualFunctionToIDMap.begin(), eit = virtualFunctionToIDMap.end(); it != eit; ++it) { @@ -329,7 +329,7 @@ class CHGraph: public CommonCHGraph, public GenericCHGraphTy NameToCHNodesMap templateNameToInstancesMap; CallNodeToCHNodesMap callNodeToClassesMap; - Map virtualFunctionToIDMap; + Map virtualFunctionToIDMap; CallNodeToVTableSetMap callNodeToCHAVtblsMap; CallNodeToVFunSetMap callNodeToCHAVFnsMap; diff --git a/svf/lib/Graphs/CHG.cpp b/svf/lib/Graphs/CHG.cpp index de9585de7..232e8ce9c 100644 --- a/svf/lib/Graphs/CHG.cpp +++ b/svf/lib/Graphs/CHG.cpp @@ -31,6 +31,7 @@ #include "Util/SVFUtil.h" #include "Graphs/ICFG.h" #include "SVFIR/SVFIR.h" +#include "Graphs/CallGraph.h" using namespace SVF; using namespace SVFUtil; @@ -50,7 +51,7 @@ static bool hasEdge(const CHNode *src, const CHNode *dst, return false; } -static bool checkArgTypes(const CallICFGNode* cs, const SVFFunction* fn) +static bool checkArgTypes(const CallICFGNode* cs, const CallGraphNode* fn) { // here we skip the first argument (i.e., this pointer) @@ -137,7 +138,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt for (CHNode::FuncVector::const_iterator fit = vfns.begin(), feit = vfns.end(); fit != feit; ++fit) { - const SVFFunction* callee = *fit; + const CallGraphNode* callee = *fit; if (callsite->arg_size() == callee->arg_size() || (callsite->isVarArg() && callee->isVarArg())) { @@ -169,7 +170,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (funName.size() == 0) { - virtualFunctions.insert(callee->getCallGraphNode()); + virtualFunctions.insert(callee); } else if (funName[0] == '~') { @@ -185,7 +186,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (calleeName[0] == '~') { - virtualFunctions.insert(callee->getCallGraphNode()); + virtualFunctions.insert(callee); } } else @@ -196,7 +197,7 @@ void CHGraph::getVFnsFromVtbls(const CallICFGNode* callsite, const VTableSet &vt */ if (funName.compare(calleeName) == 0) { - virtualFunctions.insert(callee->getCallGraphNode()); + virtualFunctions.insert(callee); } } } diff --git a/svf/lib/WPA/TypeAnalysis.cpp b/svf/lib/WPA/TypeAnalysis.cpp index 8da85d424..d2a1500c1 100644 --- a/svf/lib/WPA/TypeAnalysis.cpp +++ b/svf/lib/WPA/TypeAnalysis.cpp @@ -127,7 +127,7 @@ void TypeAnalysis::dumpCHAStats() vfunc_total = 0, vtbl_max = 0, pure_abstract = 0; - set allVirtualFunctions; + set allVirtualFunctions; for (CHGraph::const_iterator it = chgraph->begin(), eit = chgraph->end(); it != eit; ++it) { @@ -141,10 +141,10 @@ void TypeAnalysis::dumpCHAStats() veit = vecs.end(); vit != veit; ++vit) { vfuncs_size += (*vit).size(); - for (vector::const_iterator fit = (*vit).begin(), + for (vector::const_iterator fit = (*vit).begin(), feit = (*vit).end(); fit != feit; ++fit) { - const SVFFunction* func = *fit; + const CallGraphNode* func = *fit; allVirtualFunctions.insert(func); } } From ffcab193a5e4028b113b11cd09bc4664cbabd68f Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 18:08:38 +1100 Subject: [PATCH 19/45] rm SVFFunction in SVFGNode.h & VFGNode.h --- svf/include/DDA/ContextDDA.h | 6 +++--- svf/include/DDA/DDAVFSolver.h | 4 ++-- svf/include/Graphs/SVFG.h | 6 +++--- svf/include/Graphs/SVFGNode.h | 4 ++-- svf/include/Graphs/SVFGOPT.h | 2 +- svf/include/Graphs/VFG.h | 14 ++++++------- svf/include/Graphs/VFGNode.h | 27 ++++++++++++-------------- svf/lib/DDA/ContextDDA.cpp | 12 ++++++------ svf/lib/Graphs/SVFG.cpp | 10 +++++----- svf/lib/Graphs/SVFGReadWrite.cpp | 4 ++-- svf/lib/Graphs/VFG.cpp | 6 +++--- svf/lib/WPA/VersionedFlowSensitive.cpp | 4 ++-- 12 files changed, 48 insertions(+), 51 deletions(-) diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index 436c2211b..130dfc975 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -159,11 +159,11 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolvergetSrcNode()->getFun(); - const SVFFunction* dstfun = edge->getDstNode()->getFun(); + const CallGraphNode* srcfun = edge->getSrcNode()->getFun(); + const CallGraphNode* dstfun = edge->getDstNode()->getFun(); if(srcfun && dstfun) - return inSameCallGraphSCC(srcfun->getCallGraphNode(),dstfun->getCallGraphNode()); + return inSameCallGraphSCC(srcfun,dstfun); assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" ); diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index be7ad9343..08c48a1fb 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -502,11 +502,11 @@ class DDAVFSolver findPT(funPtrDpm); } } - else if(const SVFFunction* fun = getSVFG()->isFunEntrySVFGNode(dpm.getLoc())) + else if(const CallGraphNode* fun = getSVFG()->isFunEntrySVFGNode(dpm.getLoc())) { CallInstSet csSet; /// use pre-analysis call graph to approximate all potential callsites - _ander->getCallGraph()->getIndCallSitesInvokingCallee(fun->getCallGraphNode(),csSet); + _ander->getCallGraph()->getIndCallSitesInvokingCallee(fun,csSet); for(CallInstSet::const_iterator it = csSet.begin(), eit = csSet.end(); it!=eit; ++it) { NodeID funPtr = _pag->getFunPtr(*it); diff --git a/svf/include/Graphs/SVFG.h b/svf/include/Graphs/SVFG.h index db44d35a8..70dc6629d 100644 --- a/svf/include/Graphs/SVFG.h +++ b/svf/include/Graphs/SVFG.h @@ -229,7 +229,7 @@ class SVFG : public VFG //@} /// Whether a node is function entry SVFGNode - const SVFFunction* isFunEntrySVFGNode(const SVFGNode* node) const; + const CallGraphNode* isFunEntrySVFGNode(const SVFGNode* node) const; /// Whether a node is callsite return SVFGNode const CallICFGNode* isCallSiteRetSVFGNode(const SVFGNode* node) const; @@ -330,7 +330,7 @@ class SVFG : public VFG for (SVFGNode::const_iterator outIt = actualIn->OutEdgeBegin(), outEit = actualIn->OutEdgeEnd(); outIt != outEit; ++outIt) { SVFGEdge* edge = *outIt; - if (edge->getDstNode()->getFun() == callee) + if (edge->getDstNode()->getFun()->getFunction() == callee) edges.insert(edge); } } @@ -340,7 +340,7 @@ class SVFG : public VFG for (SVFGNode::const_iterator inIt = actualOut->InEdgeBegin(), inEit = actualOut->InEdgeEnd(); inIt != inEit; ++inIt) { SVFGEdge* edge = *inIt; - if (edge->getSrcNode()->getFun() == callee) + if (edge->getSrcNode()->getFun()->getFunction() == callee) edges.insert(edge); } } diff --git a/svf/include/Graphs/SVFGNode.h b/svf/include/Graphs/SVFGNode.h index 97d87a384..feb560811 100644 --- a/svf/include/Graphs/SVFGNode.h +++ b/svf/include/Graphs/SVFGNode.h @@ -408,7 +408,7 @@ class InterMSSAPHISVFGNode : public MSSAPHISVFGNode return (fun==nullptr) && (callInst != nullptr); } - inline const SVFFunction* getFun() const + inline const CallGraphNode* getFun() const { assert(isFormalINPHI() && "expect a formal parameter phi"); return fun; @@ -447,7 +447,7 @@ class InterMSSAPHISVFGNode : public MSSAPHISVFGNode virtual const std::string toString() const; private: - const SVFFunction* fun; + const CallGraphNode* fun; const CallICFGNode* callInst; }; diff --git a/svf/include/Graphs/SVFGOPT.h b/svf/include/Graphs/SVFGOPT.h index c3960a572..b9814a970 100644 --- a/svf/include/Graphs/SVFGOPT.h +++ b/svf/include/Graphs/SVFGOPT.h @@ -244,7 +244,7 @@ class SVFGOPT : public SVFG inline InterPHISVFGNode* addInterPHIForFP(const FormalParmSVFGNode* fp) { InterPHISVFGNode* sNode = new InterPHISVFGNode(totalVFGNode++,fp); - addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fp->getFun()->getCallGraphNode())); + addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fp->getFun())); resetDef(fp->getParam(),sNode); return sNode; } diff --git a/svf/include/Graphs/VFG.h b/svf/include/Graphs/VFG.h index 1b013af55..89d35b31d 100644 --- a/svf/include/Graphs/VFG.h +++ b/svf/include/Graphs/VFG.h @@ -175,9 +175,9 @@ class VFG : public GenericVFGTy /// Get callsite given a callsiteID //@{ - inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* func) const + inline CallSiteID getCallSiteID(const CallICFGNode* cs, const CallGraphNode* func) const { - return callgraph->getCallSiteID(cs, func->getCallGraphNode()); + return callgraph->getCallSiteID(cs, func); } inline const CallICFGNode* getCallSite(CallSiteID id) const { @@ -259,7 +259,7 @@ class VFG : public GenericVFGTy //@} /// Whether a node is function entry VFGNode - const SVFFunction* isFunEntryVFGNode(const VFGNode* node) const; + const CallGraphNode* isFunEntryVFGNode(const VFGNode* node) const; /// Whether a PAGNode has a blackhole or const object as its definition inline bool hasBlackHoleConstObjAddrAsDef(const PAGNode* pagNode) const @@ -350,8 +350,8 @@ class VFG : public GenericVFGTy /// sanitize Intra edges, verify that both nodes belong to the same function. inline void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode) { - const SVFFunction *srcfun = srcNode->getFun(); - const SVFFunction *dstfun = dstNode->getFun(); + const CallGraphNode *srcfun = srcNode->getFun(); + const CallGraphNode *dstfun = dstNode->getFun(); if(srcfun != nullptr && dstfun != nullptr) { assert((srcfun == dstfun) && "src and dst nodes of an intra VFG edge are not in the same function?"); @@ -537,7 +537,7 @@ class VFG : public GenericVFGTy /// Add a formal parameter VFG node inline void addFormalParmVFGNode(const PAGNode* fparm, const SVFFunction* fun, CallPESet& callPEs) { - FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun); + FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun->getCallGraphNode()); addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun->getCallGraphNode())); for(CallPESet::const_iterator it = callPEs.begin(), eit=callPEs.end(); it!=eit; ++it) @@ -551,7 +551,7 @@ class VFG : public GenericVFGTy /// Otherwise, we need to handle formalRet using pair to find FormalRetVFG node same as handling actual parameters inline void addFormalRetVFGNode(const PAGNode* uniqueFunRet, const SVFFunction* fun, RetPESet& retPEs) { - FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun); + FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun->getCallGraphNode()); addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun->getCallGraphNode())); for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it) sNode->addRetPE(*it); diff --git a/svf/include/Graphs/VFGNode.h b/svf/include/Graphs/VFGNode.h index a839a9be5..ee0ba38e5 100644 --- a/svf/include/Graphs/VFGNode.h +++ b/svf/include/Graphs/VFGNode.h @@ -76,12 +76,9 @@ class VFGNode : public GenericVFGNodeTy } /// Get the function of this SVFGNode - virtual const SVFFunction* getFun() const + virtual const CallGraphNode* getFun() const { - if (icfgNode->getFun() == nullptr) - return nullptr; - else - return icfgNode->getFun()->getFunction(); + return icfgNode->getFun(); } /// Return the corresponding LLVM value, if possible, nullptr otherwise. @@ -950,12 +947,12 @@ class ActualParmVFGNode : public ArgumentVFGNode class FormalParmVFGNode : public ArgumentVFGNode { private: - const SVFFunction* fun; + const CallGraphNode* fun; CallPESet callPEs; public: /// Constructor - FormalParmVFGNode(NodeID id, const PAGNode* n, const SVFFunction* f): + FormalParmVFGNode(NodeID id, const PAGNode* n, const CallGraphNode* f): ArgumentVFGNode(id, n, FParm), fun(f) { } @@ -967,7 +964,7 @@ class FormalParmVFGNode : public ArgumentVFGNode } /// Return function - inline const SVFFunction* getFun() const override + inline const CallGraphNode* getFun() const override { return fun; } @@ -1041,9 +1038,9 @@ class ActualRetVFGNode: public ArgumentVFGNode return cs; } /// Receive parameter at callsite - inline const SVFFunction* getCaller() const + inline const CallGraphNode* getCaller() const { - return cs->getCaller()->getFunction(); + return cs->getCaller(); } /// Receive parameter at callsite inline const PAGNode* getRev() const @@ -1085,7 +1082,7 @@ class ActualRetVFGNode: public ArgumentVFGNode class FormalRetVFGNode: public ArgumentVFGNode { private: - const SVFFunction* fun; + const CallGraphNode* fun; RetPESet retPEs; FormalRetVFGNode(); ///< place holder @@ -1094,7 +1091,7 @@ class FormalRetVFGNode: public ArgumentVFGNode public: /// Constructor - FormalRetVFGNode(NodeID id, const PAGNode* n, const SVFFunction* f); + FormalRetVFGNode(NodeID id, const PAGNode* n, const CallGraphNode* f); /// Return value at callee inline const PAGNode* getRet() const @@ -1102,7 +1099,7 @@ class FormalRetVFGNode: public ArgumentVFGNode return param; } /// Function - inline const SVFFunction* getFun() const override + inline const CallGraphNode* getFun() const override { return fun; } @@ -1171,7 +1168,7 @@ class InterPHIVFGNode : public PHIVFGNode return (fun!=nullptr) && (callInst != nullptr); } - inline const SVFFunction* getFun() const override + inline const CallGraphNode* getFun() const override { assert((isFormalParmPHI() || isActualRetPHI()) && "expect a formal parameter phi"); return fun; @@ -1210,7 +1207,7 @@ class InterPHIVFGNode : public PHIVFGNode const std::string toString() const override; private: - const SVFFunction* fun; + const CallGraphNode* fun; const CallICFGNode* callInst; }; diff --git a/svf/lib/DDA/ContextDDA.cpp b/svf/lib/DDA/ContextDDA.cpp index 40561c600..17e82c8fb 100644 --- a/svf/lib/DDA/ContextDDA.cpp +++ b/svf/lib/DDA/ContextDDA.cpp @@ -217,11 +217,11 @@ CallSiteID ContextDDA::getCSIDAtCall(CxtLocDPItem&, const SVFGEdge* edge) svfg_csId = SVFUtil::cast(edge)->getCallSiteId(); const CallICFGNode* cbn = getSVFG()->getCallSite(svfg_csId); - const SVFFunction* callee = edge->getDstNode()->getFun(); + const CallGraphNode* callee = edge->getDstNode()->getFun(); - if(getCallGraph()->hasCallSiteID(cbn,callee->getCallGraphNode())) + if(getCallGraph()->hasCallSiteID(cbn,callee)) { - return getCallGraph()->getCallSiteID(cbn,callee->getCallGraphNode()); + return getCallGraph()->getCallSiteID(cbn,callee); } return 0; @@ -241,11 +241,11 @@ CallSiteID ContextDDA::getCSIDAtRet(CxtLocDPItem&, const SVFGEdge* edge) svfg_csId = SVFUtil::cast(edge)->getCallSiteId(); const CallICFGNode* cbn = getSVFG()->getCallSite(svfg_csId); - const SVFFunction* callee = edge->getSrcNode()->getFun(); + const CallGraphNode* callee = edge->getSrcNode()->getFun(); - if(getCallGraph()->hasCallSiteID(cbn,callee->getCallGraphNode())) + if(getCallGraph()->hasCallSiteID(cbn,callee)) { - return getCallGraph()->getCallSiteID(cbn,callee->getCallGraphNode()); + return getCallGraph()->getCallSiteID(cbn,callee); } return 0; diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index 585d6ba1d..ab3275a52 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -361,7 +361,7 @@ void SVFG::connectIndirectSVFGEdges() else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun()->getCallGraphNode(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; @@ -379,7 +379,7 @@ void SVFG::connectIndirectSVFGEdges() { PTACallGraphEdge::CallInstSet callInstSet; // const MemSSA::RETMU* retMu = formalOut->getRetMU(); - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun()->getCallGraphNode(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; @@ -583,7 +583,7 @@ void SVFG::dump(const std::string& file, bool simple) */ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, const SVFFunction* callee, SVFGEdgeSetTy& edges) { - CallSiteID csId = getCallSiteID(callICFGNode, callee); + CallSiteID csId = getCallSiteID(callICFGNode, callee->getCallGraphNode()); const RetICFGNode* retICFGNode = callICFGNode->getRetICFGNode(); // Find inter direct call edges between actual param and formal param. @@ -659,7 +659,7 @@ void SVFG::connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* cal { VFG::connectCallerAndCallee(cs,callee,edges); - CallSiteID csId = getCallSiteID(cs, callee); + CallSiteID csId = getCallSiteID(cs, callee->getCallGraphNode()); // connect actual in and formal in if (hasFuncEntryChi(callee) && hasCallSiteMu(cs)) @@ -703,7 +703,7 @@ void SVFG::connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* cal /*! * Whether this is an function entry SVFGNode (formal parameter, formal In) */ -const SVFFunction* SVFG::isFunEntrySVFGNode(const SVFGNode* node) const +const CallGraphNode* SVFG::isFunEntrySVFGNode(const SVFGNode* node) const { if(const FormalParmSVFGNode* fp = SVFUtil::dyn_cast(node)) { diff --git a/svf/lib/Graphs/SVFGReadWrite.cpp b/svf/lib/Graphs/SVFGReadWrite.cpp index 4cb969880..4b0eb0c78 100644 --- a/svf/lib/Graphs/SVFGReadWrite.cpp +++ b/svf/lib/Graphs/SVFGReadWrite.cpp @@ -145,7 +145,7 @@ void SVFG::writeToFile(const string& filename) else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun()->getCallGraphNode(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; @@ -162,7 +162,7 @@ void SVFG::writeToFile(const string& filename) else if(const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast(node)) { PTACallGraphEdge::CallInstSet callInstSet; - mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun()->getCallGraphNode(),callInstSet); + mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet); for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it) { const CallICFGNode* cs = *it; diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index 4c854dcf6..fb1b53c26 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -405,7 +405,7 @@ const std::string RetDirSVFGEdge::toString() const -FormalRetVFGNode::FormalRetVFGNode(NodeID id, const PAGNode* n, const SVFFunction* f) : +FormalRetVFGNode::FormalRetVFGNode(NodeID id, const PAGNode* n, const CallGraphNode* f) : ArgumentVFGNode(id, n, FRet), fun(f) { } @@ -958,7 +958,7 @@ void VFG::updateCallGraph(PointerAnalysis* pta) void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const SVFFunction* callee, VFGEdgeSetTy& edges) { SVFIR * pag = SVFIR::getPAG(); - CallSiteID csId = getCallSiteID(callBlockNode, callee); + CallSiteID csId = getCallSiteID(callBlockNode, callee->getCallGraphNode()); const RetICFGNode* retBlockNode = callBlockNode->getRetICFGNode(); // connect actual and formal param if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) && @@ -1043,7 +1043,7 @@ const PAGNode* VFG::getLHSTopLevPtr(const VFGNode* node) const /*! * Whether this is an function entry VFGNode (formal parameter, formal In) */ -const SVFFunction* VFG::isFunEntryVFGNode(const VFGNode* node) const +const CallGraphNode* VFG::isFunEntryVFGNode(const VFGNode* node) const { if(const FormalParmVFGNode* fp = SVFUtil::dyn_cast(node)) { diff --git a/svf/lib/WPA/VersionedFlowSensitive.cpp b/svf/lib/WPA/VersionedFlowSensitive.cpp index 90950173d..cbd860857 100644 --- a/svf/lib/WPA/VersionedFlowSensitive.cpp +++ b/svf/lib/WPA/VersionedFlowSensitive.cpp @@ -481,11 +481,11 @@ void VersionedFlowSensitive::buildDeltaMaps(void) // * Callsite returns: can get new incoming indirect edges if the callsite is indirect. // * Otherwise: static. bool isDelta = false; - if (const SVFFunction *fn = svfg->isFunEntrySVFGNode(s)) + if (const CallGraphNode *fn = svfg->isFunEntrySVFGNode(s)) { PTACallGraphEdge::CallInstSet callsites; /// use pre-analysis call graph to approximate all potential callsites - ander->getCallGraph()->getIndCallSitesInvokingCallee(fn->getCallGraphNode(), callsites); + ander->getCallGraph()->getIndCallSitesInvokingCallee(fn, callsites); isDelta = !callsites.empty(); if (isDelta) From 02cd1430de7b6de2ba8c8f1a0d3ebe6ed66ec00a Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 18:37:33 +1100 Subject: [PATCH 20/45] rm SVFFunction in SVFG.h & VFG.h --- svf/include/DDA/ContextDDA.h | 2 +- svf/include/DDA/FlowDDA.h | 2 +- svf/include/Graphs/SVFG.h | 32 ++++++++++++++++---------------- svf/include/Graphs/VFG.h | 30 +++++++++++++++--------------- svf/lib/Graphs/SVFG.cpp | 22 ++++++++++++---------- svf/lib/Graphs/VFG.cpp | 24 ++++++++++++------------ svf/lib/WPA/FlowSensitive.cpp | 2 +- 7 files changed, 58 insertions(+), 56 deletions(-) diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index 130dfc975..85810cf03 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -149,7 +149,7 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolversecond; for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = (*func_iter)->getFunction(); + const CallGraphNode* func = *func_iter; getSVFG()->connectCallerAndCallee(newcs, func, svfgEdges); } } diff --git a/svf/include/DDA/FlowDDA.h b/svf/include/DDA/FlowDDA.h index 67077ab2d..cb54c8948 100644 --- a/svf/include/DDA/FlowDDA.h +++ b/svf/include/DDA/FlowDDA.h @@ -142,7 +142,7 @@ class FlowDDA : public BVDataPTAImpl, public DDAVFSolversecond; for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { - const SVFFunction* func = (*func_iter)->getFunction(); + const CallGraphNode* func = *func_iter; getSVFG()->connectCallerAndCallee(newcs, func, svfgEdges); } } diff --git a/svf/include/Graphs/SVFG.h b/svf/include/Graphs/SVFG.h index 70dc6629d..ca760596d 100644 --- a/svf/include/Graphs/SVFG.h +++ b/svf/include/Graphs/SVFG.h @@ -82,8 +82,8 @@ class SVFG : public VFG typedef NodeBS FormalOUTSVFGNodeSet; typedef Map CallSiteToActualINsMapTy; typedef Map CallSiteToActualOUTsMapTy; - typedef Map FunctionToFormalINsMapTy; - typedef Map FunctionToFormalOUTsMapTy; + typedef Map FunctionToFormalINsMapTy; + typedef Map FunctionToFormalOUTsMapTy; typedef MemSSA::MUSet MUSet; typedef MemSSA::CHISet CHISet; typedef MemSSA::PHISet PHISet; @@ -159,13 +159,13 @@ class SVFG : public VFG } /// Get all inter value flow edges of a indirect call site - void getInterVFEdgesForIndirectCallSite(const CallICFGNode* cs, const SVFFunction* callee, SVFGEdgeSetTy& edges); + void getInterVFEdgesForIndirectCallSite(const CallICFGNode* cs, const CallGraphNode* callee, SVFGEdgeSetTy& edges); /// Dump graph into dot file void dump(const std::string& file, bool simple = false); /// Connect SVFG nodes between caller and callee for indirect call site - virtual void connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* callee, SVFGEdgeSetTy& edges); + virtual void connectCallerAndCallee(const CallICFGNode* cs, const CallGraphNode* callee, SVFGEdgeSetTy& edges); /// Given a pagNode, return its definition site inline const SVFGNode* getDefSVFGNode(const PAGNode* pagNode) const @@ -194,12 +194,12 @@ class SVFG : public VFG return callSiteToActualOUTMap.find(cs)!=callSiteToActualOUTMap.end(); } - inline bool hasFormalINSVFGNodes(const SVFFunction* fun) const + inline bool hasFormalINSVFGNodes(const CallGraphNode* fun) const { return funToFormalINMap.find(fun)!=funToFormalINMap.end(); } - inline bool hasFormalOUTSVFGNodes(const SVFFunction* fun) const + inline bool hasFormalOUTSVFGNodes(const CallGraphNode* fun) const { return funToFormalOUTMap.find(fun)!=funToFormalOUTMap.end(); } @@ -217,12 +217,12 @@ class SVFG : public VFG return callSiteToActualOUTMap[cs]; } - inline FormalINSVFGNodeSet& getFormalINSVFGNodes(const SVFFunction* fun) + inline FormalINSVFGNodeSet& getFormalINSVFGNodes(const CallGraphNode* fun) { return funToFormalINMap[fun]; } - inline FormalOUTSVFGNodeSet& getFormalOUTSVFGNodes(const SVFFunction* fun) + inline FormalOUTSVFGNodeSet& getFormalOUTSVFGNodes(const CallGraphNode* fun) { return funToFormalOUTMap[fun]; } @@ -325,22 +325,22 @@ class SVFG : public VFG edges.insert(edge); } - virtual inline void getInterVFEdgeAtIndCSFromAInToFIn(ActualINSVFGNode* actualIn, const SVFFunction* callee, SVFGEdgeSetTy& edges) + virtual inline void getInterVFEdgeAtIndCSFromAInToFIn(ActualINSVFGNode* actualIn, const CallGraphNode* callee, SVFGEdgeSetTy& edges) { for (SVFGNode::const_iterator outIt = actualIn->OutEdgeBegin(), outEit = actualIn->OutEdgeEnd(); outIt != outEit; ++outIt) { SVFGEdge* edge = *outIt; - if (edge->getDstNode()->getFun()->getFunction() == callee) + if (edge->getDstNode()->getFun() == callee) edges.insert(edge); } } - virtual inline void getInterVFEdgeAtIndCSFromFOutToAOut(ActualOUTSVFGNode* actualOut, const SVFFunction* callee, SVFGEdgeSetTy& edges) + virtual inline void getInterVFEdgeAtIndCSFromFOutToAOut(ActualOUTSVFGNode* actualOut, const CallGraphNode* callee, SVFGEdgeSetTy& edges) { for (SVFGNode::const_iterator inIt = actualOut->InEdgeBegin(), inEit = actualOut->InEdgeEnd(); inIt != inEit; ++inIt) { SVFGEdge* edge = *inIt; - if (edge->getSrcNode()->getFun()->getFunction() == callee) + if (edge->getSrcNode()->getFun() == callee) edges.insert(edge); } } @@ -405,7 +405,7 @@ class SVFG : public VFG FormalINSVFGNode* sNode = new FormalINSVFGNode(nodeId, resVer, funEntry); addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun())); setDef(resVer,sNode); - funToFormalINMap[funEntry->getFun()->getFunction()].set(sNode->getId()); + funToFormalINMap[funEntry->getFun()].set(sNode->getId()); } /// Add memory Function return mu SVFG node @@ -413,7 +413,7 @@ class SVFG : public VFG { FormalOUTSVFGNode* sNode = new FormalOUTSVFGNode(nodeId, ver, funExit); addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun())); - funToFormalOUTMap[funExit->getFun()->getFunction()].set(sNode->getId()); + funToFormalOUTMap[funExit->getFun()].set(sNode->getId()); } /// Add memory callsite mu SVFG node @@ -446,11 +446,11 @@ class SVFG : public VFG /// Has function for EntryCHI/RetMU/CallCHI/CallMU //@{ - inline bool hasFuncEntryChi(const SVFFunction* func) const + inline bool hasFuncEntryChi(const CallGraphNode* func) const { return (funToFormalINMap.find(func) != funToFormalINMap.end()); } - inline bool hasFuncRetMu(const SVFFunction* func) const + inline bool hasFuncRetMu(const CallGraphNode* func) const { return (funToFormalOUTMap.find(func) != funToFormalOUTMap.end()); } diff --git a/svf/include/Graphs/VFG.h b/svf/include/Graphs/VFG.h index 89d35b31d..78d7091c1 100644 --- a/svf/include/Graphs/VFG.h +++ b/svf/include/Graphs/VFG.h @@ -70,7 +70,7 @@ class VFG : public GenericVFGTy typedef Map PAGNodeToUnaryOPVFGNodeMapTy; typedef Map PAGNodeToBranchVFGNodeMapTy; typedef Map PAGNodeToCmpVFGNodeMapTy; - typedef Map FunToVFGNodesMapTy; + typedef Map FunToVFGNodesMapTy; typedef FormalParmVFGNode::CallPESet CallPESet; typedef FormalRetVFGNode::RetPESet RetPESet; @@ -171,7 +171,7 @@ class VFG : public GenericVFGTy void updateCallGraph(PointerAnalysis* pta); /// Connect VFG nodes between caller and callee for indirect call site - virtual void connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* callee, VFGEdgeSetTy& edges); + virtual void connectCallerAndCallee(const CallICFGNode* cs, const CallGraphNode* callee, VFGEdgeSetTy& edges); /// Get callsite given a callsiteID //@{ @@ -283,25 +283,25 @@ class VFG : public GenericVFGTy /// Return all the VFGNodes of a function ///@{ - inline VFGNodeSet& getVFGNodes(const SVFFunction *fun) + inline VFGNodeSet& getVFGNodes(const CallGraphNode *fun) { return funToVFGNodesMap[fun]; } - inline bool hasVFGNodes(const SVFFunction *fun) const + inline bool hasVFGNodes(const CallGraphNode *fun) const { return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end(); } - inline bool VFGNodes(const SVFFunction *fun) const + inline bool VFGNodes(const CallGraphNode *fun) const { return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end(); } - inline VFGNodeSet::const_iterator getVFGNodeBegin(const SVFFunction *fun) const + inline VFGNodeSet::const_iterator getVFGNodeBegin(const CallGraphNode *fun) const { FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun); assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode"); return it->second.begin(); } - inline VFGNodeSet::const_iterator getVFGNodeEnd(const SVFFunction *fun) const + inline VFGNodeSet::const_iterator getVFGNodeEnd(const CallGraphNode *fun) const { FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun); assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode"); @@ -453,7 +453,7 @@ class VFG : public GenericVFGTy void connectDirectVFGEdges(); /// Create edges between VFG nodes across functions - void addVFGInterEdges(const CallICFGNode* cs, const SVFFunction* callee); + void addVFGInterEdges(const CallICFGNode* cs, const CallGraphNode* callee); inline bool isPhiCopyEdge(const PAGEdge* copy) const { @@ -468,7 +468,7 @@ class VFG : public GenericVFGTy icfgNode->addVFGNode(vfgNode); if(const CallGraphNode* cgn = icfgNode->getFun()) - funToVFGNodesMap[cgn->getFunction()].insert(vfgNode); + funToVFGNodesMap[cgn].insert(vfgNode); else globalVFGNodes.insert(vfgNode); } @@ -535,10 +535,10 @@ class VFG : public GenericVFGTy /// do not set def here, this node is not a variable definition } /// Add a formal parameter VFG node - inline void addFormalParmVFGNode(const PAGNode* fparm, const SVFFunction* fun, CallPESet& callPEs) + inline void addFormalParmVFGNode(const PAGNode* fparm, const CallGraphNode* fun, CallPESet& callPEs) { - FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun->getCallGraphNode()); - addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun->getCallGraphNode())); + FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun); + addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun)); for(CallPESet::const_iterator it = callPEs.begin(), eit=callPEs.end(); it!=eit; ++it) sNode->addCallPE(*it); @@ -549,10 +549,10 @@ class VFG : public GenericVFGTy /// Add a callee Return VFG node /// To be noted that here we assume returns of a procedure have already been unified into one /// Otherwise, we need to handle formalRet using pair to find FormalRetVFG node same as handling actual parameters - inline void addFormalRetVFGNode(const PAGNode* uniqueFunRet, const SVFFunction* fun, RetPESet& retPEs) + inline void addFormalRetVFGNode(const PAGNode* uniqueFunRet, const CallGraphNode* fun, RetPESet& retPEs) { - FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun->getCallGraphNode()); - addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun->getCallGraphNode())); + FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun); + addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun)); for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it) sNode->addRetPE(*it); diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index ab3275a52..dc3e4bab2 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -428,7 +428,9 @@ void SVFG::connectIndirectSVFGEdges() void SVFG::connectFromGlobalToProgEntry() { const SVFFunction* mainFunc = SVFUtil::getProgEntryFunction(); - FormalINSVFGNodeSet& formalIns = getFormalINSVFGNodes(mainFunc); + if (!mainFunc) + return; + FormalINSVFGNodeSet& formalIns = getFormalINSVFGNodes(mainFunc->getCallGraphNode()); if (formalIns.empty()) return; @@ -581,16 +583,16 @@ void SVFG::dump(const std::string& file, bool simple) /** * Get all inter value flow edges at this indirect call site, including call and return edges. */ -void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, const SVFFunction* callee, SVFGEdgeSetTy& edges) +void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, const CallGraphNode* callee, SVFGEdgeSetTy& edges) { - CallSiteID csId = getCallSiteID(callICFGNode, callee->getCallGraphNode()); + CallSiteID csId = getCallSiteID(callICFGNode, callee); const RetICFGNode* retICFGNode = callICFGNode->getRetICFGNode(); // Find inter direct call edges between actual param and formal param. - if (pag->hasCallSiteArgsMap(callICFGNode) && pag->hasFunArgsList(callee)) + if (pag->hasCallSiteArgsMap(callICFGNode) && pag->hasFunArgsList(callee->getFunction())) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callICFGNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee->getFunction()); SVFIR::SVFVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end(); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++) @@ -603,7 +605,7 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, assert(funArgIt == funArgEit && "function has more arguments than call site"); if (callee->isVarArg()) { - NodeID varFunArg = pag->getVarargNode(callee); + NodeID varFunArg = pag->getVarargNode(callee->getFunction()); const PAGNode* varFunArgNode = pag->getGNode(varFunArg); if (isInterestedPAGNode(varFunArgNode)) { @@ -618,10 +620,10 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, } // Find inter direct return edges between actual return and formal return. - if (pag->funHasRet(callee) && pag->callsiteHasRet(retICFGNode)) + if (pag->funHasRet(callee->getFunction()) && pag->callsiteHasRet(retICFGNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retICFGNode); - const PAGNode* fun_return = pag->getFunRet(callee); + const PAGNode* fun_return = pag->getFunRet(callee->getFunction()); if (isInterestedPAGNode(cs_return) && isInterestedPAGNode(fun_return)) getInterVFEdgeAtIndCSFromFRToAR(fun_return, cs_return, csId, edges); } @@ -655,11 +657,11 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, * Connect actual params/return to formal params/return for top-level variables. * Also connect indirect actual in/out and formal in/out. */ -void SVFG::connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* callee, SVFGEdgeSetTy& edges) +void SVFG::connectCallerAndCallee(const CallICFGNode* cs, const CallGraphNode* callee, SVFGEdgeSetTy& edges) { VFG::connectCallerAndCallee(cs,callee,edges); - CallSiteID csId = getCallSiteID(cs, callee->getCallGraphNode()); + CallSiteID csId = getCallSiteID(cs, callee); // connect actual in and formal in if (hasFuncEntryChi(callee) && hasCallSiteMu(cs)) diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index fb1b53c26..5c8b64abc 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -550,7 +550,7 @@ void VFG::addVFGNodes() callPEs.insert(callPE); } } - addFormalParmVFGNode(param,func,callPEs); + addFormalParmVFGNode(param,func->getCallGraphNode(),callPEs); } if (func->isVarArg()) @@ -570,7 +570,7 @@ void VFG::addVFGNodes() callPEs.insert(callPE); } } - addFormalParmVFGNode(varParam,func,callPEs); + addFormalParmVFGNode(varParam,func->getCallGraphNode(),callPEs); } } @@ -595,7 +595,7 @@ void VFG::addVFGNodes() } if(isInterestedPAGNode(uniqueFunRetNode)) - addFormalRetVFGNode(uniqueFunRetNode, func, retPEs); + addFormalRetVFGNode(uniqueFunRetNode, func->getCallGraphNode(), retPEs); } // initialize llvm phi nodes (phi of top level pointers) @@ -946,7 +946,7 @@ void VFG::updateCallGraph(PointerAnalysis* pta) for (PointerAnalysis::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { const CallGraphNode* func = *func_iter; - connectCallerAndCallee(newcs, func->getFunction(), vfEdgesAtIndCallSite); + connectCallerAndCallee(newcs, func, vfEdgesAtIndCallSite); } } } @@ -955,17 +955,17 @@ void VFG::updateCallGraph(PointerAnalysis* pta) * Connect actual params/return to formal params/return for top-level variables. * Also connect indirect actual in/out and formal in/out. */ -void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const SVFFunction* callee, VFGEdgeSetTy& edges) +void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const CallGraphNode* callee, VFGEdgeSetTy& edges) { SVFIR * pag = SVFIR::getPAG(); - CallSiteID csId = getCallSiteID(callBlockNode, callee->getCallGraphNode()); + CallSiteID csId = getCallSiteID(callBlockNode, callee); const RetICFGNode* retBlockNode = callBlockNode->getRetICFGNode(); // connect actual and formal param - if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) && - matchArgs(callBlockNode, callee)) + if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee->getFunction()) && + matchArgs(callBlockNode, callee->getFunction())) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee->getFunction()); SVFIR::SVFVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end(); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++) @@ -979,7 +979,7 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const SVFFun if (callee->isVarArg()) { - NodeID varFunArg = pag->getVarargNode(callee); + NodeID varFunArg = pag->getVarargNode(callee->getFunction()); const PAGNode* varFunArgNode = pag->getGNode(varFunArg); if (isInterestedPAGNode(varFunArgNode)) { @@ -994,10 +994,10 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const SVFFun } // connect actual return and formal return - if (pag->funHasRet(callee) && pag->callsiteHasRet(retBlockNode)) + if (pag->funHasRet(callee->getFunction()) && pag->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = pag->getFunRet(callee); + const PAGNode* fun_return = pag->getFunRet(callee->getFunction()); if (isInterestedPAGNode(cs_return) && isInterestedPAGNode(fun_return)) connectFRetAndARet(fun_return, cs_return, csId, edges); } diff --git a/svf/lib/WPA/FlowSensitive.cpp b/svf/lib/WPA/FlowSensitive.cpp index 997881952..255749268 100644 --- a/svf/lib/WPA/FlowSensitive.cpp +++ b/svf/lib/WPA/FlowSensitive.cpp @@ -751,7 +751,7 @@ void FlowSensitive::connectCallerAndCallee(const CallEdgeMap& newEdges, SVFGEdge for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++) { const CallGraphNode* func = *func_iter; - svfg->connectCallerAndCallee(cs, func->getFunction(), edges); + svfg->connectCallerAndCallee(cs, func, edges); } } } From c87f0a4149acf81e9e1dd87698866575caca5092 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 19:08:00 +1100 Subject: [PATCH 21/45] remove SVFFunction in SVFIR.h --- svf-llvm/include/SVF-LLVM/SVFIRBuilder.h | 4 ++-- svf-llvm/lib/SVFIRBuilder.cpp | 8 ++++---- svf-llvm/lib/SymbolTableBuilder.cpp | 8 ++++---- svf/include/Graphs/ConsG.h | 4 ++-- svf/include/Graphs/IRGraph.h | 6 +++--- svf/include/SVFIR/SVFIR.h | 24 ++++++++++++------------ svf/lib/CFL/CFLAlias.cpp | 10 +++++----- svf/lib/Graphs/IRGraph.cpp | 4 ++-- svf/lib/Graphs/SVFG.cpp | 10 +++++----- svf/lib/Graphs/VFG.cpp | 20 ++++++++++---------- svf/lib/MSSA/SVFGBuilder.cpp | 4 ++-- svf/lib/Util/ThreadAPI.cpp | 5 ++--- svf/lib/WPA/Andersen.cpp | 10 +++++----- 13 files changed, 58 insertions(+), 59 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h index 41982042a..50b5c6cf8 100644 --- a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +++ b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h @@ -104,13 +104,13 @@ class SVFIRBuilder: public llvm::InstVisitor /// getReturnNode - Return the node representing the unique return value of a function. inline NodeID getReturnNode(const CallGraphNode *func) { - return pag->getReturnNode(func->getFunction()); + return pag->getReturnNode(func); } /// getVarargNode - Return the node representing the unique variadic argument of a function. inline NodeID getVarargNode(const CallGraphNode *func) { - return pag->getVarargNode(func->getFunction()); + return pag->getVarargNode(func); } //@} diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 366443290..61a68eacd 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -96,7 +96,7 @@ SVFIR* SVFIRBuilder::build() for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F) { const Function& fun = *F; - const SVFFunction* svffun = llvmModuleSet()->getSVFFunction(&fun); + const CallGraphNode* cgn = llvmModuleSet()->getCallGraphNode(&fun); /// collect return node of function fun if(!fun.isDeclaration()) { @@ -108,8 +108,8 @@ SVFIR* SVFIRBuilder::build() if (fun.doesNotReturn() == false && fun.getReturnType()->isVoidTy() == false) { - pag->addFunRet(svffun, - pag->getGNode(pag->getReturnNode(svffun))); + pag->addFunRet(cgn, + pag->getGNode(pag->getReturnNode(cgn))); } /// To be noted, we do not record arguments which are in declared function without body @@ -126,7 +126,7 @@ SVFIR* SVFIRBuilder::build() // if(I->getType()->isPointerTy()) // addBlackHoleAddrEdge(argValNodeId); //} - pag->addFunArgs(svffun,pag->getGNode(argValNodeId)); + pag->addFunArgs(cgn,pag->getGNode(argValNodeId)); } } for (Function::const_iterator bit = fun.begin(), ebit = fun.end(); diff --git a/svf-llvm/lib/SymbolTableBuilder.cpp b/svf-llvm/lib/SymbolTableBuilder.cpp index 54dc2e630..aa21aa1f9 100644 --- a/svf-llvm/lib/SymbolTableBuilder.cpp +++ b/svf-llvm/lib/SymbolTableBuilder.cpp @@ -352,8 +352,8 @@ void SymbolTableBuilder::collectObj(const Value* val) */ void SymbolTableBuilder::collectRet(const Function* val) { - const SVFFunction* svffun = - llvmModuleSet()->getSVFFunction(val); + const CallGraphNode* svffun = + llvmModuleSet()->getCallGraphNode(val); IRGraph::FunToIDMapTy::iterator iter = svfir->returnSymMap.find(svffun); if (iter == svfir->returnSymMap.end()) @@ -369,8 +369,8 @@ void SymbolTableBuilder::collectRet(const Function* val) */ void SymbolTableBuilder::collectVararg(const Function* val) { - const SVFFunction* svffun = - llvmModuleSet()->getSVFFunction(val); + const CallGraphNode* svffun = + llvmModuleSet()->getCallGraphNode(val); IRGraph::FunToIDMapTy::iterator iter = svfir->varargSymMap.find(svffun); if (iter == svfir->varargSymMap.end()) diff --git a/svf/include/Graphs/ConsG.h b/svf/include/Graphs/ConsG.h index 715347d77..b2c0a8a7f 100644 --- a/svf/include/Graphs/ConsG.h +++ b/svf/include/Graphs/ConsG.h @@ -76,12 +76,12 @@ class ConstraintGraph : public GenericGraph /// Wrappers used internally, not expose to Andersen Pass //@{ - inline NodeID getReturnNode(const SVFFunction* value) const + inline NodeID getReturnNode(const CallGraphNode* value) const { return pag->getReturnNode(value); } - inline NodeID getVarargNode(const SVFFunction* value) const + inline NodeID getVarargNode(const CallGraphNode* value) const { return pag->getVarargNode(value); } diff --git a/svf/include/Graphs/IRGraph.h b/svf/include/Graphs/IRGraph.h index 65f6e6e0f..379eea0db 100644 --- a/svf/include/Graphs/IRGraph.h +++ b/svf/include/Graphs/IRGraph.h @@ -75,7 +75,7 @@ class IRGraph : public GenericGraph typedef OrderedMap IDToTypeInfoMapTy; /// function to sym id map - typedef OrderedMap FunToIDMapTy; + typedef OrderedMap FunToIDMapTy; /// struct type to struct info map typedef Set SVFTypeSet; //@} @@ -237,10 +237,10 @@ class IRGraph : public GenericGraph } /// GetReturnNode - Return the unique node representing the return value of a function - NodeID getReturnNode(const SVFFunction* func) const; + NodeID getReturnNode(const CallGraphNode* func) const; /// getVarargNode - Return the unique node representing the variadic argument of a variadic function. - NodeID getVarargNode(const SVFFunction* func) const; + NodeID getVarargNode(const CallGraphNode* func) const; inline NodeID getBlackHoleNode() const { diff --git a/svf/include/SVFIR/SVFIR.h b/svf/include/SVFIR/SVFIR.h index 92202532b..660e4b958 100644 --- a/svf/include/SVFIR/SVFIR.h +++ b/svf/include/SVFIR/SVFIR.h @@ -58,12 +58,12 @@ class SVFIR : public IRGraph typedef std::vector SVFStmtList; typedef std::vector SVFVarList; typedef Map PHINodeMap; - typedef Map FunToArgsListMap; + typedef Map FunToArgsListMap; typedef Map CSToArgsListMap; typedef Map CSToRetMap; - typedef Map FunToRetMap; + typedef Map FunToRetMap; typedef Map FunToFunObjVarMap; - typedef Map FunToPAGEdgeSetMap; + typedef Map FunToPAGEdgeSetMap; typedef Map ICFGNode2SVFStmtsMap; typedef Map NodeToNodeMap; typedef std::pair NodeOffset; @@ -264,7 +264,7 @@ class SVFIR : public IRGraph } /// Function has arguments list - inline bool hasFunArgsList(const SVFFunction* func) const + inline bool hasFunArgsList(const CallGraphNode* func) const { return (funArgsListMap.find(func) != funArgsListMap.end()); } @@ -274,7 +274,7 @@ class SVFIR : public IRGraph return funArgsListMap; } /// Get function arguments list - inline const SVFVarList& getFunArgsList(const SVFFunction* func) const + inline const SVFVarList& getFunArgsList(const CallGraphNode* func) const { FunToArgsListMap::const_iterator it = funArgsListMap.find(func); assert(it != funArgsListMap.end() && "this function doesn't have arguments"); @@ -319,13 +319,13 @@ class SVFIR : public IRGraph return funRetMap; } /// Get function return list - inline const SVFVar* getFunRet(const SVFFunction* func) const + inline const SVFVar* getFunRet(const CallGraphNode* func) const { FunToRetMap::const_iterator it = funRetMap.find(func); assert(it != funRetMap.end() && "this function doesn't have return"); return it->second; } - inline bool funHasRet(const SVFFunction* func) const + inline bool funHasRet(const CallGraphNode* func) const { return funRetMap.find(func) != funRetMap.end(); } @@ -504,16 +504,16 @@ class SVFIR : public IRGraph /// Get/set method for function/callsite arguments and returns //@{ /// Add function arguments - inline void addFunArgs(const SVFFunction* fun, const SVFVar* arg) + inline void addFunArgs(const CallGraphNode* fun, const SVFVar* arg) { - FunEntryICFGNode* funEntryBlockNode = icfg->getFunEntryICFGNode(fun->getCallGraphNode()); + FunEntryICFGNode* funEntryBlockNode = icfg->getFunEntryICFGNode(fun); funEntryBlockNode->addFormalParms(arg); funArgsListMap[fun].push_back(arg); } /// Add function returns - inline void addFunRet(const SVFFunction* fun, const SVFVar* ret) + inline void addFunRet(const CallGraphNode* fun, const SVFVar* ret) { - FunExitICFGNode* funExitBlockNode = icfg->getFunExitICFGNode(fun->getCallGraphNode()); + FunExitICFGNode* funExitBlockNode = icfg->getFunExitICFGNode(fun); funExitBlockNode->addFormalRet(ret); funRetMap[fun] = ret; } @@ -763,7 +763,7 @@ class SVFIR : public IRGraph return addNode(node); } /// Add a unique vararg node for a procedure - inline NodeID addVarargNode(const SVFFunction*, SVFVar *node) + inline NodeID addVarargNode(const CallGraphNode*, SVFVar *node) { return addNode(node); } diff --git a/svf/lib/CFL/CFLAlias.cpp b/svf/lib/CFL/CFLAlias.cpp index 852dbe7a5..0645664fc 100644 --- a/svf/lib/CFL/CFLAlias.cpp +++ b/svf/lib/CFL/CFLAlias.cpp @@ -74,10 +74,10 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const CallGrap heapAllocatorViaIndCall(cs); } - if (svfir->funHasRet(F->getFunction()) && svfir->callsiteHasRet(retBlockNode)) + if (svfir->funHasRet(F) && svfir->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = svfir->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = svfir->getFunRet(F->getFunction()); + const PAGNode* fun_return = svfir->getFunRet(F); if (cs_return->isPointer() && fun_return->isPointer()) { NodeID dstrec = cs_return->getId(); @@ -90,12 +90,12 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const CallGrap } } - if (svfir->hasCallSiteArgsMap(callBlockNode) && svfir->hasFunArgsList(F->getFunction())) + if (svfir->hasCallSiteArgsMap(callBlockNode) && svfir->hasFunArgsList(F)) { // connect actual and formal param const SVFIR::SVFVarList& csArgList = svfir->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = svfir->getFunArgsList(F->getFunction()); + const SVFIR::SVFVarList& funArgList = svfir->getFunArgsList(F); //Go through the fixed parameters. DBOUT(DPAGBuild, outs() << " args:"); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); @@ -123,7 +123,7 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const CallGrap //Any remaining actual args must be varargs. if (F->isVarArg()) { - NodeID vaF = svfir->getVarargNode(F->getFunction()); + NodeID vaF = svfir->getVarargNode(F); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; csArgIt != csArgEit; ++csArgIt) { diff --git a/svf/lib/Graphs/IRGraph.cpp b/svf/lib/Graphs/IRGraph.cpp index a3b4b2013..0c7196b45 100644 --- a/svf/lib/Graphs/IRGraph.cpp +++ b/svf/lib/Graphs/IRGraph.cpp @@ -56,14 +56,14 @@ IRGraph::~IRGraph() destorySymTable(); } -NodeID IRGraph::getReturnNode(const SVFFunction *func) const +NodeID IRGraph::getReturnNode(const CallGraphNode *func) const { FunToIDMapTy::const_iterator iter = returnSymMap.find(func); assert(iter!=returnSymMap.end() && "ret sym not found"); return iter->second; } -NodeID IRGraph::getVarargNode(const SVFFunction *func) const +NodeID IRGraph::getVarargNode(const CallGraphNode *func) const { FunToIDMapTy::const_iterator iter = varargSymMap.find(func); assert(iter!=varargSymMap.end() && "vararg sym not found"); diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index dc3e4bab2..6244f9294 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -589,10 +589,10 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, const RetICFGNode* retICFGNode = callICFGNode->getRetICFGNode(); // Find inter direct call edges between actual param and formal param. - if (pag->hasCallSiteArgsMap(callICFGNode) && pag->hasFunArgsList(callee->getFunction())) + if (pag->hasCallSiteArgsMap(callICFGNode) && pag->hasFunArgsList(callee)) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callICFGNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee->getFunction()); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); SVFIR::SVFVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end(); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++) @@ -605,7 +605,7 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, assert(funArgIt == funArgEit && "function has more arguments than call site"); if (callee->isVarArg()) { - NodeID varFunArg = pag->getVarargNode(callee->getFunction()); + NodeID varFunArg = pag->getVarargNode(callee); const PAGNode* varFunArgNode = pag->getGNode(varFunArg); if (isInterestedPAGNode(varFunArgNode)) { @@ -620,10 +620,10 @@ void SVFG::getInterVFEdgesForIndirectCallSite(const CallICFGNode* callICFGNode, } // Find inter direct return edges between actual return and formal return. - if (pag->funHasRet(callee->getFunction()) && pag->callsiteHasRet(retICFGNode)) + if (pag->funHasRet(callee) && pag->callsiteHasRet(retICFGNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retICFGNode); - const PAGNode* fun_return = pag->getFunRet(callee->getFunction()); + const PAGNode* fun_return = pag->getFunRet(callee); if (isInterestedPAGNode(cs_return) && isInterestedPAGNode(fun_return)) getInterVFEdgeAtIndCSFromFRToAR(fun_return, cs_return, csId, edges); } diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index 5c8b64abc..abeebf1e3 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -531,7 +531,7 @@ void VFG::addVFGNodes() // initialize formal parameter nodes for(SVFIR::FunToArgsListMap::iterator it = pag->getFunArgsMap().begin(), eit = pag->getFunArgsMap().end(); it !=eit; ++it) { - const SVFFunction* func = it->first; + const CallGraphNode* func = it->first; for(SVFIR::SVFVarList::iterator pit = it->second.begin(), epit = it->second.end(); pit!=epit; ++pit) { @@ -550,7 +550,7 @@ void VFG::addVFGNodes() callPEs.insert(callPE); } } - addFormalParmVFGNode(param,func->getCallGraphNode(),callPEs); + addFormalParmVFGNode(param,func,callPEs); } if (func->isVarArg()) @@ -570,14 +570,14 @@ void VFG::addVFGNodes() callPEs.insert(callPE); } } - addFormalParmVFGNode(varParam,func->getCallGraphNode(),callPEs); + addFormalParmVFGNode(varParam,func,callPEs); } } // initialize formal return nodes (callee return) for (SVFIR::FunToRetMap::iterator it = pag->getFunRets().begin(), eit = pag->getFunRets().end(); it != eit; ++it) { - const SVFFunction* func = it->first; + const CallGraphNode* func = it->first; const PAGNode* uniqueFunRetNode = it->second; @@ -595,7 +595,7 @@ void VFG::addVFGNodes() } if(isInterestedPAGNode(uniqueFunRetNode)) - addFormalRetVFGNode(uniqueFunRetNode, func->getCallGraphNode(), retPEs); + addFormalRetVFGNode(uniqueFunRetNode, func, retPEs); } // initialize llvm phi nodes (phi of top level pointers) @@ -961,11 +961,11 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const CallGr CallSiteID csId = getCallSiteID(callBlockNode, callee); const RetICFGNode* retBlockNode = callBlockNode->getRetICFGNode(); // connect actual and formal param - if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee->getFunction()) && + if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) && matchArgs(callBlockNode, callee->getFunction())) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee->getFunction()); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); SVFIR::SVFVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end(); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++) @@ -979,7 +979,7 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const CallGr if (callee->isVarArg()) { - NodeID varFunArg = pag->getVarargNode(callee->getFunction()); + NodeID varFunArg = pag->getVarargNode(callee); const PAGNode* varFunArgNode = pag->getGNode(varFunArg); if (isInterestedPAGNode(varFunArgNode)) { @@ -994,10 +994,10 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const CallGr } // connect actual return and formal return - if (pag->funHasRet(callee->getFunction()) && pag->callsiteHasRet(retBlockNode)) + if (pag->funHasRet(callee) && pag->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = pag->getFunRet(callee->getFunction()); + const PAGNode* fun_return = pag->getFunRet(callee); if (isInterestedPAGNode(cs_return) && isInterestedPAGNode(fun_return)) connectFRetAndARet(fun_return, cs_return, csId, edges); } diff --git a/svf/lib/MSSA/SVFGBuilder.cpp b/svf/lib/MSSA/SVFGBuilder.cpp index 95a181f3c..0d66490f5 100644 --- a/svf/lib/MSSA/SVFGBuilder.cpp +++ b/svf/lib/MSSA/SVFGBuilder.cpp @@ -107,11 +107,11 @@ std::unique_ptr SVFGBuilder::buildMSSA(BVDataPTAImpl* pta, bool ptrOnlyM for (const auto& item: *svfirCallGraph) { - const SVFFunction *fun = item.second->getFunction(); + const CallGraphNode *fun = item.second; if (isExtCall(fun)) continue; - mssa->buildMemSSA(*fun); + mssa->buildMemSSA(*(fun->getFunction())); } mssa->performStat(); diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index 430e1518c..c4536dec5 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -195,9 +195,8 @@ const ValVar* ThreadAPI::getActualParmAtForkSite(const CallICFGNode *inst) const const SVFVar* ThreadAPI::getFormalParmOfForkedFun(const CallGraphNode* cgNode) const { - const SVFFunction* F = cgNode->getFunction(); - assert(PAG::getPAG()->hasFunArgsList(F) && "forked function has no args list!"); - const SVFIR::SVFVarList& funArgList = PAG::getPAG()->getFunArgsList(F); + assert(PAG::getPAG()->hasFunArgsList(cgNode) && "forked function has no args list!"); + const SVFIR::SVFVarList& funArgList = PAG::getPAG()->getFunArgsList(cgNode); // in pthread, forked functions are of type void *()(void *args) assert(funArgList.size() == 1 && "num of pthread forked function args is not 1!"); return funArgList[0]; diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index 3c9984fe7..090a0db05 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -287,10 +287,10 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, heapAllocatorViaIndCall(cs,cpySrcNodes); } - if (pag->funHasRet(F->getFunction()) && pag->callsiteHasRet(retBlockNode)) + if (pag->funHasRet(F) && pag->callsiteHasRet(retBlockNode)) { const PAGNode* cs_return = pag->getCallSiteRet(retBlockNode); - const PAGNode* fun_return = pag->getFunRet(F->getFunction()); + const PAGNode* fun_return = pag->getFunRet(F); if (cs_return->isPointer() && fun_return->isPointer()) { NodeID dstrec = sccRepNode(cs_return->getId()); @@ -306,12 +306,12 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, } } - if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(F->getFunction())) + if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(F)) { // connect actual and formal param const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); - const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(F->getFunction()); + const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(F); //Go through the fixed parameters. DBOUT(DPAGBuild, outs() << " args:"); SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end(); @@ -342,7 +342,7 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, //Any remaining actual args must be varargs. if (F->isVarArg()) { - NodeID vaF = sccRepNode(pag->getVarargNode(F->getFunction())); + NodeID vaF = sccRepNode(pag->getVarargNode(F)); DBOUT(DPAGBuild, outs() << "\n varargs:"); for (; csArgIt != csArgEit; ++csArgIt) { From f6c079352f38f1ba1b5a89b96f1a06dcdd810f58 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 19:17:14 +1100 Subject: [PATCH 22/45] rm SVFFunction in CDGBuilder.h --- svf/include/Util/CDGBuilder.h | 2 +- svf/lib/Util/CDGBuilder.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/svf/include/Util/CDGBuilder.h b/svf/include/Util/CDGBuilder.h index d7135f175..a76bd32ae 100644 --- a/svf/include/Util/CDGBuilder.h +++ b/svf/include/Util/CDGBuilder.h @@ -67,7 +67,7 @@ class CDGBuilder /// extract basic block edges to be processed static void - extractBBS(const SVFFunction *func, + extractBBS(const CallGraphNode *func, Map> &res); /// extract nodes between two nodes in pdom tree diff --git a/svf/lib/Util/CDGBuilder.cpp b/svf/lib/Util/CDGBuilder.cpp index 96c5b78b6..08ec30024 100644 --- a/svf/lib/Util/CDGBuilder.cpp +++ b/svf/lib/Util/CDGBuilder.cpp @@ -126,11 +126,11 @@ void CDGBuilder::buildControlDependence(const SVFModule *svfgModule) CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction *svfFun = (item.second)->getFunction(); - if (SVFUtil::isExtCall(svfFun)) continue; + CallGraphNode* cgn = item.second; + if (SVFUtil::isExtCall(cgn)) continue; // extract basic block edges to be processed Map> BBS; - extractBBS(svfFun, BBS); + extractBBS(cgn, BBS); for (const auto &item: BBS) { @@ -138,8 +138,7 @@ void CDGBuilder::buildControlDependence(const SVFModule *svfgModule) // for each bb pair for (const SVFBasicBlock *succ: item.second) { - const SVFBasicBlock *SVFLCA = const_cast(svfFun)-> - getLoopAndDomInfo()->findNearestCommonPDominator(pred, succ); + const SVFBasicBlock *SVFLCA = cgn->getLoopAndDomInfo()->findNearestCommonPDominator(pred, succ); std::vector tgtNodes; // no common ancestor, may be exit() if (SVFLCA == NULL) @@ -168,7 +167,7 @@ void CDGBuilder::buildControlDependence(const SVFModule *svfgModule) * @param func * @param res */ -void CDGBuilder::extractBBS(const SVF::SVFFunction *func, +void CDGBuilder::extractBBS(const SVF::CallGraphNode *func, Map> &res) { for (const auto &it: *func) From 3459f67196b58fa7df83a8b267eb7205df14f54e Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 19:20:05 +1100 Subject: [PATCH 23/45] rm SVFFunction in ThreadCallGraph.h --- svf/include/Graphs/ThreadCallGraph.h | 2 +- svf/lib/Graphs/ThreadCallGraph.cpp | 6 +++--- svf/lib/MemoryModel/PointerAnalysisImpl.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/svf/include/Graphs/ThreadCallGraph.h b/svf/include/Graphs/ThreadCallGraph.h index ec42f5266..c06b0e908 100644 --- a/svf/include/Graphs/ThreadCallGraph.h +++ b/svf/include/Graphs/ThreadCallGraph.h @@ -350,7 +350,7 @@ class ThreadCallGraph: public PTACallGraph /// Add direct/indirect thread fork edges //@{ bool addDirectForkEdge(const CallICFGNode* cs); - bool addIndirectForkEdge(const CallICFGNode* cs, const SVFFunction* callee); + bool addIndirectForkEdge(const CallICFGNode* cs, const CallGraphNode* callee); //@} /// Add thread join edges diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 9ebc641cf..3e84b4796 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -86,7 +86,7 @@ void ThreadCallGraph::updateCallGraph(PointerAnalysis* pta) const BaseObjVar* obj = pag->getBaseObject(objPN->getId()); if(obj->isFunction()) { - const SVFFunction* svfCallee = SVFUtil::cast(obj)->getFunction(); + const CallGraphNode* svfCallee = SVFUtil::cast(obj)->getCallGraphNode(); this->addIndirectForkEdge(*it, svfCallee); } } @@ -153,12 +153,12 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) /*! * Add indirect fork edge to update call graph */ -bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const SVFFunction* calleefun) +bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const CallGraphNode* calleefun) { PTACallGraphNode* caller = getPTACallGraphNode(cs->getCaller()); PTACallGraphNode* callee = - getPTACallGraphNode(calleefun->getCallGraphNode()); + getPTACallGraphNode(calleefun); CallSiteID csId = addCallSite(cs, callee->getCallNode()); diff --git a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp index b4b58549a..bef6cddc2 100644 --- a/svf/lib/MemoryModel/PointerAnalysisImpl.cpp +++ b/svf/lib/MemoryModel/PointerAnalysisImpl.cpp @@ -542,7 +542,7 @@ void BVDataPTAImpl::onTheFlyThreadCallGraphSolve(const CallSiteToFunPtrMap& call if(obj->isFunction()) { const CallGraphNode *cgn = SVFUtil::cast(obj)->getCallGraphNode(); - if(tdCallGraph->addIndirectForkEdge(*it, cgn->getFunction())) + if(tdCallGraph->addIndirectForkEdge(*it, cgn)) newForkEdges[*it].insert(cgn); } } From 6f96b93228bb58c44179424ba77e8d7955d9256b Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 22:55:52 +1100 Subject: [PATCH 24/45] rm SVFFunction in FlowDDA and ContextDDA --- svf/include/DDA/ContextDDA.h | 2 +- svf/include/DDA/FlowDDA.h | 2 +- svf/lib/DDA/ContextDDA.cpp | 4 ++-- svf/lib/DDA/FlowDDA.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/svf/include/DDA/ContextDDA.h b/svf/include/DDA/ContextDDA.h index 85810cf03..586a19035 100644 --- a/svf/include/DDA/ContextDDA.h +++ b/svf/include/DDA/ContextDDA.h @@ -110,7 +110,7 @@ class ContextDDA : public CondPTAImpl, public DDAVFSolverisIndirectCallSites(cs)) { @@ -195,7 +195,7 @@ bool ContextDDA::testIndCallReachability(CxtLocDPItem& dpm, const SVFFunction* c CxtVar funptrVar(dpm.getCondVar().get_cond(), id); CxtLocDPItem funptrDpm = getDPIm(funptrVar,getDefSVFGNode(node)); PointsTo pts = getBVPointsTo(findPT(funptrDpm)); - if(pts.test(getPAG()->getFunObjVar(callee->getCallGraphNode())->getId())) + if(pts.test(getPAG()->getFunObjVar(callee)->getId())) return true; else return false; diff --git a/svf/lib/DDA/FlowDDA.cpp b/svf/lib/DDA/FlowDDA.cpp index f1bc3b178..feba0d6e2 100644 --- a/svf/lib/DDA/FlowDDA.cpp +++ b/svf/lib/DDA/FlowDDA.cpp @@ -78,7 +78,7 @@ void FlowDDA::handleOutOfBudgetDpm(const LocDPItem& dpm) addOutOfBudgetDpm(dpm); } -bool FlowDDA::testIndCallReachability(LocDPItem&, const SVFFunction* callee, CallSiteID csId) +bool FlowDDA::testIndCallReachability(LocDPItem&, const CallGraphNode* callee, CallSiteID csId) { const CallICFGNode* cbn = getSVFG()->getCallSite(csId); @@ -88,7 +88,7 @@ bool FlowDDA::testIndCallReachability(LocDPItem&, const SVFFunction* callee, Cal if(getCallGraph()->hasIndCSCallees(cbn)) { const FunctionSet& funset = getCallGraph()->getIndCSCallees(cbn); - if(funset.find(callee->getCallGraphNode())!=funset.end()) + if(funset.find(callee)!=funset.end()) return true; } From c3271c3d4ef7a11930b184635c4787e4f1a8c8d3 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 23:17:52 +1100 Subject: [PATCH 25/45] rm SVFFunction in TCT.h --- svf/include/MTA/LockAnalysis.h | 8 +++---- svf/include/MTA/MHP.h | 10 ++++---- svf/include/MTA/TCT.h | 20 ++++++++-------- svf/include/Util/CxtStmt.h | 12 +++++----- svf/lib/MTA/LockAnalysis.cpp | 28 +++++++++++------------ svf/lib/MTA/MHP.cpp | 42 +++++++++++++++++----------------- svf/lib/MTA/TCT.cpp | 38 +++++++++++++++--------------- 7 files changed, 79 insertions(+), 79 deletions(-) diff --git a/svf/include/MTA/LockAnalysis.h b/svf/include/MTA/LockAnalysis.h index 6fa47bd09..dea99f719 100644 --- a/svf/include/MTA/LockAnalysis.h +++ b/svf/include/MTA/LockAnalysis.h @@ -61,7 +61,7 @@ class LockAnalysis typedef Set InstSet; typedef InstSet CISpan; typedef MapCILockToSpan; - typedef Set FunSet; + typedef Set FunSet; typedef Map InstToInstSetMap; typedef Map CxtStmtToLockFlagMap; typedef FIFOWorkList CxtStmtWorkList; @@ -192,7 +192,7 @@ class LockAnalysis //@} /// Return true if it is a candidate function - inline bool isLockCandidateFun(const SVFFunction* fun) const + inline bool isLockCandidateFun(const CallGraphNode* fun) const { return lockcandidateFuncSet.find(fun)!=lockcandidateFuncSet.end(); } @@ -430,9 +430,9 @@ class LockAnalysis //@} /// Push calling context - void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee); + void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee); /// Match context - bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee); + bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee); /// Whether it is a lock site inline bool isTDFork(const ICFGNode* call) diff --git a/svf/include/MTA/MHP.h b/svf/include/MTA/MHP.h index df4aef72e..031238a10 100644 --- a/svf/include/MTA/MHP.h +++ b/svf/include/MTA/MHP.h @@ -202,12 +202,12 @@ class MHP return tct->getTCTNode(curTid)->isMultiforked(); } /// Push calling context - inline void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) + inline void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { tct->pushCxt(cxt,call,callee); } /// Match context - inline bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) + inline bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { return tct->matchCxt(cxt,call,callee); } @@ -342,7 +342,7 @@ class ForkJoinAnalysis { NodeID parentTid = tct->getParentThread(tid); const CxtThread& parentct = tct->getTCTNode(parentTid)->getCxtThread(); - const SVFFunction* parentRoutine = tct->getStartRoutineOfCxtThread(parentct); + const CallGraphNode* parentRoutine = tct->getStartRoutineOfCxtThread(parentct); return parentRoutine->getExitBB()->back(); } @@ -450,12 +450,12 @@ class ForkJoinAnalysis //@} /// Push calling context - inline void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) + inline void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { tct->pushCxt(cxt,call,callee); } /// Match context - inline bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) + inline bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { return tct->matchCxt(cxt,call,callee); } diff --git a/svf/include/MTA/TCT.h b/svf/include/MTA/TCT.h index c8be4583a..5e43cc5c4 100644 --- a/svf/include/MTA/TCT.h +++ b/svf/include/MTA/TCT.h @@ -157,13 +157,13 @@ class TCT: public GenericThreadCreateTreeTy typedef SVFLoopAndDomInfo::LoopBBs LoopBBs; typedef TCTEdge::ThreadCreateEdgeSet ThreadCreateEdgeSet; typedef ThreadCreateEdgeSet::iterator TCTNodeIter; - typedef Set FunSet; + typedef Set FunSet; typedef std::vector InstVec; typedef Set InstSet; typedef Set PTACGNodeSet; typedef Map CxtThreadToNodeMap; typedef Map CxtThreadToForkCxt; - typedef Map CxtThreadToFun; + typedef Map CxtThreadToFun; typedef Map InstToLoopMap; typedef FIFOWorkList CxtThreadProcVec; typedef Set CxtThreadProcSet; @@ -293,12 +293,12 @@ class TCT: public GenericThreadCreateTreeTy for(PTACallGraph::FunctionSet::const_iterator cit = callees.begin(), ecit = callees.end(); cit!=ecit; cit++) { - if(candidateFuncSet.find((*cit)->getFunction())!=candidateFuncSet.end()) + if(candidateFuncSet.find(*cit)!=candidateFuncSet.end()) return true; } return false; } - inline bool isCandidateFun(const SVFFunction* fun) const + inline bool isCandidateFun(const CallGraphNode* fun) const { return candidateFuncSet.find(fun)!=candidateFuncSet.end(); } @@ -374,7 +374,7 @@ class TCT: public GenericThreadCreateTreeTy } /// get the start routine function of a thread - const SVFFunction* getStartRoutineOfCxtThread(const CxtThread& ct) const + const CallGraphNode* getStartRoutineOfCxtThread(const CxtThread& ct) const { CxtThreadToFun::const_iterator it = ctToRoutineFunMap.find(ct); assert(it!=ctToRoutineFunMap.end() && "Cxt Thread not found!!"); @@ -414,9 +414,9 @@ class TCT: public GenericThreadCreateTreeTy const LoopBBs& getLoop(const SVFBasicBlock* bb); /// Push calling context - void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee); + void pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee); /// Match context - bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee); + bool matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee); inline void pushCxt(CallStrCxt& cxt, CallSiteID csId) { @@ -477,7 +477,7 @@ class TCT: public GenericThreadCreateTreeTy /// Mark relevant procedures that are backward reachable from any fork/join site //@{ void markRelProcs(); - void markRelProcs(const SVFFunction* fun); + void markRelProcs(const CallGraphNode* cgFun); //@} /// Get entry functions that are neither called by other functions nor extern functions @@ -510,7 +510,7 @@ class TCT: public GenericThreadCreateTreeTy /// Get or create a tct node based on CxtThread //@{ - inline TCTNode* getOrCreateTCTNode(const CallStrCxt& cxt, const ICFGNode* fork,const CallStrCxt& oldCxt, const SVFFunction* routine) + inline TCTNode* getOrCreateTCTNode(const CallStrCxt& cxt, const ICFGNode* fork,const CallStrCxt& oldCxt, const CallGraphNode* routine) { CxtThread ct(cxt,fork); CxtThreadToNodeMap::const_iterator it = ctpToNodeMap.find(ct); @@ -551,7 +551,7 @@ class TCT: public GenericThreadCreateTreeTy ctToForkCxtMap[ct] = cxt; } /// Add start routine function of a cxt thread - void addStartRoutineOfCxtThread(const SVFFunction* fun, const CxtThread& ct) + void addStartRoutineOfCxtThread(const CallGraphNode* fun, const CxtThread& ct) { ctToRoutineFunMap[ct] = fun; } diff --git a/svf/include/Util/CxtStmt.h b/svf/include/Util/CxtStmt.h index edcf7811c..7b23d447a 100644 --- a/svf/include/Util/CxtStmt.h +++ b/svf/include/Util/CxtStmt.h @@ -310,7 +310,7 @@ class CxtProc { public: /// Constructor - CxtProc(const CallStrCxt& c, const SVFFunction* f) : + CxtProc(const CallStrCxt& c, const CallGraphNode* f) : cxt(c), fun(f) { } @@ -324,7 +324,7 @@ class CxtProc { } /// Return current procedure - inline const SVFFunction* getProc() const + inline const CallGraphNode* getProc() const { return fun; } @@ -383,7 +383,7 @@ class CxtProc protected: CallStrCxt cxt; - const SVFFunction* fun; + const CallGraphNode* fun; }; @@ -397,7 +397,7 @@ class CxtThreadProc : public CxtProc { public: /// Constructor - CxtThreadProc(NodeID t, const CallStrCxt& c, const SVFFunction* f) :CxtProc(c,f),tid(t) + CxtThreadProc(NodeID t, const CallStrCxt& c, const CallGraphNode* f) :CxtProc(c,f),tid(t) { } /// Copy constructor @@ -494,8 +494,8 @@ template <> struct std::hash { size_t operator()(const SVF::CxtProc& cs) const { - std::hash h; - SVF::SVFFunction* fun = const_cast (cs.getProc()); + std::hash h; + SVF::CallGraphNode* fun = const_cast (cs.getProc()); return h(fun); } }; diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 15cbfe6fa..43daa3441 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -126,7 +126,7 @@ void LockAnalysis::buildCandidateFuncSetforLock() while (!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - lockcandidateFuncSet.insert(node->getCallNode()->getFunction()); + lockcandidateFuncSet.insert(node->getCallNode()); for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -275,9 +275,9 @@ void LockAnalysis::collectCxtLock() { CxtLockProc clp = popFromCTPWorkList(); PTACallGraphNode* cgNode = - getTCG()->getPTACallGraphNode(clp.getProc()->getCallGraphNode()); + getTCG()->getPTACallGraphNode(clp.getProc()); // lzh TODO. - if (!isLockCandidateFun(cgNode->getCallNode()->getFunction())) + if (!isLockCandidateFun(cgNode->getCallNode())) continue; for (PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++) @@ -319,7 +319,7 @@ void LockAnalysis::handleCallRelation(CxtLockProc& clp, const PTACallGraphEdge* addCxtLock(cxt,curNode); return; } - const SVFFunction* svfcallee = cgEdge->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* svfcallee = cgEdge->getDstNode()->getCallNode(); pushCxt(cxt, SVFUtil::cast(curNode), svfcallee); CxtLockProc newclp(cxt, svfcallee); @@ -417,7 +417,7 @@ void LockAnalysis::handleFork(const CxtStmt& cts) for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = getTCG()->getForkEdgeBegin(call), ecgIt = getTCG()->getForkEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* svfcallee = (*cgIt)->getDstNode()->getCallNode(); CallStrCxt newCxt = curCxt; pushCxt(newCxt,call,svfcallee); const ICFGNode* svfInst = svfcallee->getEntryBlock()->front(); @@ -439,7 +439,7 @@ void LockAnalysis::handleCall(const CxtStmt& cts) for (PTACallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* svfcallee = (*cgIt)->getDstNode()->getCallNode(); if (SVFUtil::isExtCall(svfcallee)) continue; CallStrCxt newCxt = curCxt; @@ -472,7 +472,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; if (matchCxt(newCxt, SVFUtil::cast(inst), - curFunNode->getCallNode()->getFunction())) + curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { @@ -490,7 +490,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; if (matchCxt(newCxt, SVFUtil::cast(inst), - curFunNode->getCallNode()->getFunction())) + curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { @@ -523,10 +523,10 @@ void LockAnalysis::handleIntra(const CxtStmt& cts) } -void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) +void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { const CallGraphNode* svfcaller = call->getFun(); - CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); + CallSiteID csId = getTCG()->getCallSiteID(call, callee); // /// handle calling context for candidate functions only // if (isLockCandidateFun(caller) == false) @@ -534,17 +534,17 @@ void LockAnalysis::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFF if (tct->inSameCallGraphSCC( getTCG()->getPTACallGraphNode(svfcaller), - getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) + getTCG()->getPTACallGraphNode(callee)) == false) { tct->pushCxt(cxt,csId); DBOUT(DMTA, tct->dumpCxt(cxt)); } } -bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) +bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { const CallGraphNode* svfcaller = call->getFun(); - CallSiteID csId = getTCG()->getCallSiteID(call, callee->getCallGraphNode()); + CallSiteID csId = getTCG()->getCallSiteID(call, callee); // /// handle calling context for candidate functions only // if (isLockCandidateFun(caller) == false) @@ -556,7 +556,7 @@ bool LockAnalysis::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVF if (tct->inSameCallGraphSCC( getTCG()->getPTACallGraphNode(svfcaller), - getTCG()->getPTACallGraphNode(callee->getCallGraphNode())) == false) + getTCG()->getPTACallGraphNode(callee)) == false) { if (cxt.back() == csId) cxt.pop_back(); diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index d863836c9..7078afb6d 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -78,7 +78,7 @@ void MHP::analyzeInterleaving() { const CxtThread& ct = tpair.second->getCxtThread(); NodeID rootTid = tpair.first; - const SVFFunction* routine = tct->getStartRoutineOfCxtThread(ct); + const CallGraphNode* routine = tct->getStartRoutineOfCxtThread(ct); const ICFGNode* svfInst = routine->getEntryBlock()->front(); CxtThreadStmt rootcts(rootTid, ct.getContext(), svfInst); @@ -97,7 +97,7 @@ void MHP::analyzeInterleaving() DBOUT(DMTA, outs() << " >\n-----\n"); /// handle non-candidate function - if (!tct->isCandidateFun(curInst->getFun()->getFunction())) + if (!tct->isCandidateFun(curInst->getFun())) { handleNonCandidateFun(cts); } @@ -146,7 +146,7 @@ void MHP::updateNonCandidateFunInterleaving() SVFModule* module = tct->getSVFModule(); for (const SVFFunction* fun : module->getFunctionSet()) { - if (!tct->isCandidateFun(fun) && !isExtCall(fun)) + if (!tct->isCandidateFun(fun->getCallGraphNode()) && !isExtCall(fun)) { const ICFGNode* entryNode = fun->getEntryBlock()->front(); @@ -217,10 +217,10 @@ void MHP::handleFork(const CxtThreadStmt& cts, NodeID rootTid) ecgIt = tcg->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfroutine = (*cgIt)->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* cgn = (*cgIt)->getDstNode()->getCallNode(); CallStrCxt newCxt = curCxt; - pushCxt(newCxt, cbn, svfroutine); - const ICFGNode* stmt = svfroutine->getEntryBlock()->front(); + pushCxt(newCxt, cbn, cgn); + const ICFGNode* stmt = cgn->getEntryBlock()->front(); CxtThread ct(newCxt, call); CxtThreadStmt newcts(tct->getTCTNode(ct)->getId(), ct.getContext(), stmt); addInterleavingThread(newcts, cts); @@ -302,13 +302,13 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); - if (isExtCall(svfcallee)) + const CallGraphNode* cgnCallee = (*cgIt)->getDstNode()->getCallNode(); + if (isExtCall(cgnCallee)) continue; CallStrCxt newCxt = curCxt; const CallICFGNode* callicfgnode = SVFUtil::cast(call); - pushCxt(newCxt, callicfgnode, svfcallee); - const ICFGNode* svfEntryInst = svfcallee->getEntryBlock()->front(); + pushCxt(newCxt, callicfgnode, cgnCallee); + const ICFGNode* svfEntryInst = cgnCallee->getEntryBlock()->front(); CxtThreadStmt newCts(cts.getTid(), newCxt, svfEntryInst); addInterleavingThread(newCts, cts); } @@ -331,7 +331,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getCallNode()->getFunction())) + if (matchCxt(newCxt, *cit, curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -348,7 +348,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getCallNode()->getFunction())) + if (matchCxt(newCxt, *cit, curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -431,7 +431,7 @@ void MHP::updateSiblingThreads(NodeID curTid) continue; const CxtThread& ct = tct->getTCTNode(stid)->getCxtThread(); - const SVFFunction* routine = tct->getStartRoutineOfCxtThread(ct); + const CallGraphNode* routine = tct->getStartRoutineOfCxtThread(ct); const ICFGNode* stmt = routine->getEntryBlock()->front(); CxtThreadStmt cts(stid, ct.getContext(), stmt); addInterleavingThread(cts, curTid); @@ -595,7 +595,7 @@ bool MHP::mayHappenInParallelInst(const ICFGNode* i1, const ICFGNode* i2) bool MHP::mayHappenInParallelCache(const ICFGNode* i1, const ICFGNode* i2) { - if (!tct->isCandidateFun(i1->getFun()->getFunction()) && !tct->isCandidateFun(i2->getFun()->getFunction())) + if (!tct->isCandidateFun(i1->getFun()) && !tct->isCandidateFun(i2->getFun())) { FuncPair funpair = std::make_pair(i1->getFun()->getFunction(), i2->getFun()->getFunction()); FuncPairToBool::const_iterator it = nonCandidateFuncMHPRelMap.find(funpair); @@ -799,7 +799,7 @@ void ForkJoinAnalysis::handleFork(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* callee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* callee = (*cgIt)->getDstNode()->getCallNode(); CallStrCxt newCxt = curCxt; pushCxt(newCxt, cbn, callee); CxtThread ct(newCxt, call); @@ -890,12 +890,12 @@ void ForkJoinAnalysis::handleCall(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getCallEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const SVFFunction* svfcallee = (*cgIt)->getDstNode()->getCallNode()->getFunction(); - if (isExtCall(svfcallee)) + const CallGraphNode* cgnCallee = (*cgIt)->getDstNode()->getCallNode(); + if (isExtCall(cgnCallee)) continue; CallStrCxt newCxt = curCxt; - pushCxt(newCxt, cbn, svfcallee); - const ICFGNode* svfEntryInst = svfcallee->getEntryBlock()->front(); + pushCxt(newCxt, cbn, cgnCallee); + const ICFGNode* svfEntryInst = cgnCallee->getEntryBlock()->front(); CxtStmt newCts(newCxt, svfEntryInst); markCxtStmtFlag(newCts, cts); } @@ -921,7 +921,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* curNode = (*cit); if (matchCxt(newCxt, SVFUtil::cast(curNode), - curFunNode->getCallNode()->getFunction())) + curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { @@ -941,7 +941,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curNode = (*cit); if (matchCxt(newCxt, SVFUtil::cast(curNode), - curFunNode->getCallNode()->getFunction())) + curFunNode->getCallNode())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index ea7cccb6d..d34901467 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -138,12 +138,12 @@ void TCT::markRelProcs() for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it) { const SVFFunction* svfun = (*it)->getParent()->getParent(); - markRelProcs(svfun); + markRelProcs(svfun->getCallGraphNode()); for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++) { const PTACallGraphNode* forkeeNode = (*nit)->getDstNode(); - candidateFuncSet.insert(forkeeNode->getCallNode()->getFunction()); + candidateFuncSet.insert(forkeeNode->getCallNode()); } } @@ -151,7 +151,7 @@ void TCT::markRelProcs() for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it) { const SVFFunction* svfun = (*it)->getParent()->getParent(); - markRelProcs(svfun); + markRelProcs(svfun->getCallGraphNode()); } if(candidateFuncSet.empty()) @@ -161,10 +161,10 @@ void TCT::markRelProcs() /*! * */ -void TCT::markRelProcs(const SVFFunction* svffun) +void TCT::markRelProcs(const CallGraphNode* cgFun) { PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(svffun->getCallGraphNode()); + tcg->getPTACallGraphNode(cgFun); FIFOWorkList worklist; PTACGNodeSet visited; worklist.push(cgnode); @@ -172,7 +172,7 @@ void TCT::markRelProcs(const SVFFunction* svffun) while(!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - candidateFuncSet.insert(node->getCallNode()->getFunction()); + candidateFuncSet.insert(node->getCallNode()); for(PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit!=neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -193,11 +193,11 @@ void TCT::collectEntryFunInCallGraph() CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction* fun = item.second->getFunction(); + const CallGraphNode* fun = item.second; if (SVFUtil::isExtCall(fun)) continue; PTACallGraphNode* node = - tcg->getPTACallGraphNode(fun->getCallGraphNode()); + tcg->getPTACallGraphNode(fun); if (!node->hasIncomingEdge()) { entryFuncSet.insert(fun); @@ -249,7 +249,7 @@ void TCT::collectMultiForkedThreads() */ void TCT::handleCallRelation(CxtThreadProc& ctp, const PTACallGraphEdge* cgEdge, const CallICFGNode* cs) { - const SVFFunction* callee = cgEdge->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* callee = cgEdge->getDstNode()->getCallNode(); CallStrCxt cxt(ctp.getContext()); CallStrCxt oldCxt = cxt; @@ -412,8 +412,8 @@ void TCT::build() { CxtThreadProc ctp = popFromCTPWorkList(); PTACallGraphNode* cgNode = - tcg->getPTACallGraphNode(ctp.getProc()->getCallGraphNode()); - if(isCandidateFun(cgNode->getCallNode()->getFunction()) == false) + tcg->getPTACallGraphNode(ctp.getProc()); + if(isCandidateFun(cgNode->getCallNode()) == false) continue; for(PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++) @@ -448,19 +448,19 @@ void TCT::build() /*! * Push calling context */ -void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) +void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { const CallGraphNode* caller = call->getFun(); - CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); + CallSiteID csId = tcg->getCallSiteID(call, callee); /// handle calling context for candidate functions only - if(isCandidateFun(caller->getFunction()) == false) + if(isCandidateFun(caller) == false) return; if(inSameCallGraphSCC( tcg->getPTACallGraphNode(caller), - tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) + tcg->getPTACallGraphNode(callee))==false) { pushCxt(cxt,csId); DBOUT(DMTA,dumpCxt(cxt)); @@ -471,14 +471,14 @@ void TCT::pushCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* /*! * Match calling context */ -bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* callee) +bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const CallGraphNode* callee) { const CallGraphNode* caller = call->getFun(); - CallSiteID csId = tcg->getCallSiteID(call, callee->getCallGraphNode()); + CallSiteID csId = tcg->getCallSiteID(call, callee); /// handle calling context for candidate functions only - if(isCandidateFun(caller->getFunction()) == false) + if(isCandidateFun(caller) == false) return true; /// partial match @@ -487,7 +487,7 @@ bool TCT::matchCxt(CallStrCxt& cxt, const CallICFGNode* call, const SVFFunction* if(inSameCallGraphSCC( tcg->getPTACallGraphNode(caller), - tcg->getPTACallGraphNode(callee->getCallGraphNode()))==false) + tcg->getPTACallGraphNode(callee))==false) { if(cxt.back() == csId) cxt.pop_back(); From 916f5065ff6dfcfa6b9f8da484a7845840f403ba Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 23:34:05 +1100 Subject: [PATCH 26/45] rm SVFFunction in MemPartition.h & MemRegion.h --- svf/include/MSSA/MemPartition.h | 24 ++++++++--------- svf/include/MSSA/MemRegion.h | 46 ++++++++++++++++----------------- svf/lib/MSSA/MemPartition.cpp | 16 ++++++------ svf/lib/MSSA/MemRegion.cpp | 34 ++++++++++++------------ 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/svf/include/MSSA/MemPartition.h b/svf/include/MSSA/MemPartition.h index 3138f7b58..d74c72e93 100644 --- a/svf/include/MSSA/MemPartition.h +++ b/svf/include/MSSA/MemPartition.h @@ -57,13 +57,13 @@ class DistinctMRG : public MRGenerator virtual void partitionMRs(); /// Get memory region at a load - virtual void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun); + virtual void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun); /// Get memory regions to be inserted at a load statement. - virtual void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun); + virtual void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun); private: /// Create memory regions for each points-to target. - void createDistinctMR(const SVFFunction* func, const NodeBS& cpts); + void createDistinctMR(const CallGraphNode* func, const NodeBS& cpts); }; @@ -74,8 +74,8 @@ class IntraDisjointMRG : public MRGenerator { public: typedef OrderedMap PtsToSubPtsMap; - typedef Map FunToPtsMap; - typedef Map FunToInterMap; + typedef Map FunToPtsMap; + typedef Map FunToInterMap; IntraDisjointMRG(BVDataPTAImpl* p, bool ptrOnly) : MRGenerator(p, ptrOnly) {} @@ -94,7 +94,7 @@ class IntraDisjointMRG : public MRGenerator * @param mrs Memory region set contains all possible target memory regions. */ virtual inline void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, - const SVFFunction* fun) + const CallGraphNode* fun) { const PointsToList& inters = getIntersList(fun); getMRsForLoadFromInterList(aliasMRs, cpts, inters); @@ -103,26 +103,26 @@ class IntraDisjointMRG : public MRGenerator void getMRsForLoadFromInterList(MRSet& mrs, const NodeBS& cpts, const PointsToList& inters); /// Get memory regions to be inserted at a load statement. - virtual void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun); + virtual void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun); /// Create disjoint memory region - void createDisjointMR(const SVFFunction* func, const NodeBS& cpts); + void createDisjointMR(const CallGraphNode* func, const NodeBS& cpts); /// Compute intersections between cpts and computed cpts intersections before. void computeIntersections(const NodeBS& cpts, PointsToList& inters); private: - inline PtsToSubPtsMap& getPtsSubSetMap(const SVFFunction* func) + inline PtsToSubPtsMap& getPtsSubSetMap(const CallGraphNode* func) { return funcToPtsMap[func]; } - inline PointsToList& getIntersList(const SVFFunction* func) + inline PointsToList& getIntersList(const CallGraphNode* func) { return funcToInterMap[func]; } - inline const PtsToSubPtsMap& getPtsSubSetMap(const SVFFunction* func) const + inline const PtsToSubPtsMap& getPtsSubSetMap(const CallGraphNode* func) const { FunToPtsMap::const_iterator it = funcToPtsMap.find(func); assert(it != funcToPtsMap.end() && "can not find pts map for specified function"); @@ -155,7 +155,7 @@ class InterDisjointMRG : public IntraDisjointMRG * @param mrs Memory region set contains all possible target memory regions. */ virtual inline void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, - const SVFFunction*) + const CallGraphNode*) { getMRsForLoadFromInterList(aliasMRs, cpts, inters); } diff --git a/svf/include/MSSA/MemRegion.h b/svf/include/MSSA/MemRegion.h index b0f1b2b7f..bdcb0bb70 100644 --- a/svf/include/MSSA/MemRegion.h +++ b/svf/include/MSSA/MemRegion.h @@ -139,14 +139,14 @@ class MRGenerator //@} ///Define mem region set typedef OrderedSet MRSet; - typedef Map PAGEdgeToFunMap; + typedef Map PAGEdgeToFunMap; typedef OrderedSet PointsToList; - typedef Map FunToPointsToMap; - typedef Map FunToPointsTosMap; + typedef Map FunToPointsToMap; + typedef Map FunToPointsTosMap; typedef OrderedMap PtsToRepPtsSetMap; /// Map a function to its region set - typedef Map FunToMRsMap; + typedef Map FunToMRsMap; /// Map loads/stores to its mem regions, /// TODO:visitAtomicCmpXchgInst, visitAtomicRMWInst?? //@{ @@ -165,7 +165,7 @@ class MRGenerator /// Maps Mod-Ref analysis //@{ /// Map a function to its indirect refs/mods of memory objects - typedef Map FunToNodeBSMap; + typedef Map FunToNodeBSMap; /// Map a callsite to its indirect refs/mods of memory objects typedef Map CallSiteToNodeBSMap; //@} @@ -263,7 +263,7 @@ class MRGenerator } /// Whether the object node is a non-local object /// including global, heap, and stack variable in recursions - bool isNonLocalObject(NodeID id, const SVFFunction* curFun) const; + bool isNonLocalObject(NodeID id, const CallGraphNode* curFun) const; /// Get all the objects in callee's modref escaped via global objects (the chain pts of globals) void getEscapObjviaGlobals(NodeBS& globs, const NodeBS& pts); @@ -280,7 +280,7 @@ class MRGenerator PtsToRepPtsSetMap cptsToRepCPtsMap; /// Generate a memory region and put in into functions which use it - void createMR(const SVFFunction* fun, const NodeBS& cpts); + void createMR(const CallGraphNode* fun, const NodeBS& cpts); /// Collect all global variables for later escape analysis void collectGlobals(); @@ -306,7 +306,7 @@ class MRGenerator return mr->getPointsTo().intersects(cpts); } /// Get all aliased mem regions from function fun according to cpts - virtual inline void getAliasMemRegions(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun) + virtual inline void getAliasMemRegions(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun) { for(MRSet::const_iterator it = funToMRsMap[fun].begin(), eit = funToMRsMap[fun].end(); it!=eit; ++it) { @@ -316,14 +316,14 @@ class MRGenerator } /// Get memory regions for a load statement according to cpts. - virtual inline void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction*) + virtual inline void getMRsForLoad(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode*) { const MemRegion* mr = getMR(cpts); aliasMRs.insert(mr); } /// Get memory regions for call site ref according to cpts. - virtual inline void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction*) + virtual inline void getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode*) { const MemRegion* mr = getMR(cpts); aliasMRs.insert(mr); @@ -333,18 +333,18 @@ class MRGenerator virtual void modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& worklist); /// Get Mod-Ref of a callee function - virtual bool handleCallsiteModRef(NodeBS& mod, NodeBS& ref, const CallICFGNode* cs, const SVFFunction* fun); + virtual bool handleCallsiteModRef(NodeBS& mod, NodeBS& ref, const CallICFGNode* cs, const CallGraphNode* fun); /// Add cpts to store/load //@{ - inline void addCPtsToStore(NodeBS& cpts, const StoreStmt *st, const SVFFunction* fun) + inline void addCPtsToStore(NodeBS& cpts, const StoreStmt *st, const CallGraphNode* fun) { storesToPointsToMap[st] = cpts; funToPointsToMap[fun].insert(cpts); addModSideEffectOfFunction(fun,cpts); } - inline void addCPtsToLoad(NodeBS& cpts, const LoadStmt *ld, const SVFFunction* fun) + inline void addCPtsToLoad(NodeBS& cpts, const LoadStmt *ld, const CallGraphNode* fun) { loadsToPointsToMap[ld] = cpts; funToPointsToMap[fun].insert(cpts); @@ -353,18 +353,18 @@ class MRGenerator inline void addCPtsToCallSiteRefs(NodeBS& cpts, const CallICFGNode* cs) { callsiteToRefPointsToMap[cs] |= cpts; - funToPointsToMap[cs->getCaller()->getFunction()].insert(cpts); + funToPointsToMap[cs->getCaller()].insert(cpts); } inline void addCPtsToCallSiteMods(NodeBS& cpts, const CallICFGNode* cs) { callsiteToModPointsToMap[cs] |= cpts; - funToPointsToMap[cs->getCaller()->getFunction()].insert(cpts); + funToPointsToMap[cs->getCaller()].insert(cpts); } - inline bool hasCPtsList(const SVFFunction* fun) const + inline bool hasCPtsList(const CallGraphNode* fun) const { return funToPointsToMap.find(fun)!=funToPointsToMap.end(); } - inline PointsToList& getPointsToList(const SVFFunction* fun) + inline PointsToList& getPointsToList(const CallGraphNode* fun) { return funToPointsToMap[fun]; } @@ -376,21 +376,21 @@ class MRGenerator /// Add/Get methods for side-effect of functions and callsites //@{ /// Add indirect uses an memory object in the function - void addRefSideEffectOfFunction(const SVFFunction* fun, const NodeBS& refs); + void addRefSideEffectOfFunction(const CallGraphNode* fun, const NodeBS& refs); /// Add indirect def an memory object in the function - void addModSideEffectOfFunction(const SVFFunction* fun, const NodeBS& mods); + void addModSideEffectOfFunction(const CallGraphNode* fun, const NodeBS& mods); /// Add indirect uses an memory object in the function bool addRefSideEffectOfCallSite(const CallICFGNode* cs, const NodeBS& refs); /// Add indirect def an memory object in the function bool addModSideEffectOfCallSite(const CallICFGNode* cs, const NodeBS& mods); /// Get indirect refs of a function - inline const NodeBS& getRefSideEffectOfFunction(const SVFFunction* fun) + inline const NodeBS& getRefSideEffectOfFunction(const CallGraphNode* fun) { return funToRefsMap[fun]; } /// Get indirect mods of a function - inline const NodeBS& getModSideEffectOfFunction(const SVFFunction* fun) + inline const NodeBS& getModSideEffectOfFunction(const CallGraphNode* fun) { return funToModsMap[fun]; } @@ -432,7 +432,7 @@ class MRGenerator virtual void generateMRs(); /// Get the function which SVFIR Edge located - const SVFFunction* getFunction(const PAGEdge* pagEdge) const + const CallGraphNode* getFunction(const PAGEdge* pagEdge) const { PAGEdgeToFunMap::const_iterator it = pagEdgeToFunMap.find(pagEdge); assert(it!=pagEdgeToFunMap.end() && "can not find its function, it is a global SVFIR edge"); @@ -440,7 +440,7 @@ class MRGenerator } /// Get Memory Region set //@{ - inline MRSet& getFunMRSet(const SVFFunction* fun) + inline MRSet& getFunMRSet(const CallGraphNode* fun) { return funToMRsMap[fun]; } diff --git a/svf/lib/MSSA/MemPartition.cpp b/svf/lib/MSSA/MemPartition.cpp index 48a481048..c4304d398 100644 --- a/svf/lib/MSSA/MemPartition.cpp +++ b/svf/lib/MSSA/MemPartition.cpp @@ -44,7 +44,7 @@ void DistinctMRG::partitionMRs() for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end(); it!=eit; ++it) { - const SVFFunction* fun = it->first; + const CallGraphNode* fun = it->first; /// Collect all points-to target in a function scope. NodeBS mergePts; for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) @@ -61,7 +61,7 @@ void DistinctMRG::partitionMRs() * 1. collect all points-to targets in a function scope. * 2. create memory region for each point-to target. */ -void DistinctMRG::createDistinctMR(const SVFFunction* func, const NodeBS& pts) +void DistinctMRG::createDistinctMR(const CallGraphNode* func, const NodeBS& pts) { /// Create memory regions for each points-to target. @@ -88,7 +88,7 @@ void DistinctMRG::createDistinctMR(const SVFFunction* func, const NodeBS& pts) * @param fun The function being analyzed. * @param mrs Memory region set contains all possible target memory regions. */ -void DistinctMRG::getMRsForLoad(MRSet& mrs, const NodeBS& pts, const SVFFunction*) +void DistinctMRG::getMRsForLoad(MRSet& mrs, const NodeBS& pts, const CallGraphNode*) { /// Get memory regions for each points-to element in cpts. @@ -112,7 +112,7 @@ void DistinctMRG::getMRsForLoad(MRSet& mrs, const NodeBS& pts, const SVFFunction * Get memory regions to be inserted at a load statement. * Just process as getMRsForLoad(). */ -void DistinctMRG::getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun) +void DistinctMRG::getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun) { getMRsForLoad(aliasMRs, cpts, fun); } @@ -124,7 +124,7 @@ void IntraDisjointMRG::partitionMRs() for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end(); it!=eit; ++it) { - const SVFFunction* fun = it->first; + const CallGraphNode* fun = it->first; for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) @@ -229,7 +229,7 @@ void IntraDisjointMRG::computeIntersections(const NodeBS& cpts, PointsToList& in /** * Create memory regions for each points-to target. */ -void IntraDisjointMRG::createDisjointMR(const SVFFunction* func, const NodeBS& cpts) +void IntraDisjointMRG::createDisjointMR(const CallGraphNode* func, const NodeBS& cpts) { // set the rep cpts as itself. cptsToRepCPtsMap[cpts] = cpts; @@ -259,7 +259,7 @@ void IntraDisjointMRG::getMRsForLoadFromInterList(MRSet& mrs, const NodeBS& cpts * Get memory regions to be inserted at a load statement. * Just process as getMRsForLoad(). */ -void IntraDisjointMRG::getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const SVFFunction* fun) +void IntraDisjointMRG::getMRsForCallSiteRef(MRSet& aliasMRs, const NodeBS& cpts, const CallGraphNode* fun) { getMRsForLoad(aliasMRs, cpts, fun); } @@ -285,7 +285,7 @@ void InterDisjointMRG::partitionMRs() for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end(); it!=eit; ++it) { - const SVFFunction* fun = it->first; + const CallGraphNode* fun = it->first; for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 7f49a7ca2..a8b1d22b3 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -67,7 +67,7 @@ void MRGenerator::destroy() /*! * Generate a memory region and put in into functions which use it */ -void MRGenerator::createMR(const SVFFunction* fun, const NodeBS& cpts) +void MRGenerator::createMR(const CallGraphNode* fun, const NodeBS& cpts) { const NodeBS& repCPts = getRepPointsTo(cpts); MemRegion mr(repCPts); @@ -177,7 +177,7 @@ void MRGenerator::collectModRefForLoadStore() CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction& fun = *item.second->getFunction(); + const CallGraphNode& fun = *item.second; /// if this function does not have any caller, then we do not care its MSSA if (Options::IgnoreDeadFun() && fun.isUncalledFunction()) @@ -331,7 +331,7 @@ void MRGenerator::partitionMRs() for(FunToPointsTosMap::iterator it = getFunToPointsToList().begin(), eit = getFunToPointsToList().end(); it!=eit; ++it) { - const SVFFunction* fun = it->first; + const CallGraphNode* fun = it->first; for(PointsToList::iterator cit = it->second.begin(), ecit = it->second.end(); cit!=ecit; ++cit) { createMR(fun,*cit); @@ -350,7 +350,7 @@ void MRGenerator::updateAliasMRs() for(StoresToPointsToMap::const_iterator it = storesToPointsToMap.begin(), eit = storesToPointsToMap.end(); it!=eit; ++it) { MRSet aliasMRs; - const SVFFunction* fun = getFunction(it->first); + const CallGraphNode* fun = getFunction(it->first); const NodeBS& storeCPts = it->second; getAliasMemRegions(aliasMRs,storeCPts,fun); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) @@ -362,7 +362,7 @@ void MRGenerator::updateAliasMRs() for(LoadsToPointsToMap::const_iterator it = loadsToPointsToMap.begin(), eit = loadsToPointsToMap.end(); it!=eit; ++it) { MRSet aliasMRs; - const SVFFunction* fun = getFunction(it->first); + const CallGraphNode* fun = getFunction(it->first); const NodeBS& loadCPts = it->second; getMRsForLoad(aliasMRs, loadCPts, fun); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) @@ -378,7 +378,7 @@ void MRGenerator::updateAliasMRs() const CallGraphNode* fun = it->first->getCaller(); MRSet aliasMRs; const NodeBS& callsiteModCPts = it->second; - getAliasMemRegions(aliasMRs,callsiteModCPts,fun->getFunction()); + getAliasMemRegions(aliasMRs,callsiteModCPts,fun); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) { callsiteToModMRsMap[it->first].insert(*ait); @@ -390,7 +390,7 @@ void MRGenerator::updateAliasMRs() const CallGraphNode* fun = it->first->getCaller(); MRSet aliasMRs; const NodeBS& callsiteRefCPts = it->second; - getMRsForCallSiteRef(aliasMRs, callsiteRefCPts, fun->getFunction()); + getMRsForCallSiteRef(aliasMRs, callsiteRefCPts, fun); for(MRSet::iterator ait = aliasMRs.begin(), eait = aliasMRs.end(); ait!=eait; ++ait) { callsiteToRefMRsMap[it->first].insert(*ait); @@ -402,7 +402,7 @@ void MRGenerator::updateAliasMRs() /*! * Add indirect uses an memory object in the function */ -void MRGenerator::addRefSideEffectOfFunction(const SVFFunction* fun, const NodeBS& refs) +void MRGenerator::addRefSideEffectOfFunction(const CallGraphNode* fun, const NodeBS& refs) { for(NodeBS::iterator it = refs.begin(), eit = refs.end(); it!=eit; ++it) { @@ -414,7 +414,7 @@ void MRGenerator::addRefSideEffectOfFunction(const SVFFunction* fun, const NodeB /*! * Add indirect def an memory object in the function */ -void MRGenerator::addModSideEffectOfFunction(const SVFFunction* fun, const NodeBS& mods) +void MRGenerator::addModSideEffectOfFunction(const CallGraphNode* fun, const NodeBS& mods) { for(NodeBS::iterator it = mods.begin(), eit = mods.end(); it!=eit; ++it) { @@ -433,7 +433,7 @@ bool MRGenerator::addRefSideEffectOfCallSite(const CallICFGNode* cs, const NodeB NodeBS refset = refs; refset &= getCallSiteArgsPts(cs); getEscapObjviaGlobals(refset,refs); - addRefSideEffectOfFunction(cs->getCaller()->getFunction(),refset); + addRefSideEffectOfFunction(cs->getCaller(),refset); return csToRefsMap[cs] |= refset; } return false; @@ -449,7 +449,7 @@ bool MRGenerator::addModSideEffectOfCallSite(const CallICFGNode* cs, const NodeB NodeBS modset = mods; modset &= (getCallSiteArgsPts(cs) | getCallSiteRetPts(cs)); getEscapObjviaGlobals(modset,mods); - addModSideEffectOfFunction(cs->getCaller()->getFunction(),modset); + addModSideEffectOfFunction(cs->getCaller(),modset); return csToModsMap[cs] |= modset; } return false; @@ -573,7 +573,7 @@ void MRGenerator::getEscapObjviaGlobals(NodeBS& globs, const NodeBS& calleeModRe * Whether the object node is a non-local object * including global, heap, and stack variable in recursions */ -bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const +bool MRGenerator::isNonLocalObject(NodeID id, const CallGraphNode* curFun) const { //ABTest const BaseObjVar* obj = pta->getPAG()->getBaseObject(id); @@ -587,13 +587,13 @@ bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const /// or a local variable is in function recursion cycles else if(SVFUtil::isa(pVar)) { - if(const SVFFunction* svffun = pVar->getFunction()) + if(const CallGraphNode* svffun = pVar->getFunction()->getCallGraphNode()) { if(svffun!=curFun) return true; else return callGraphSCC->isInCycle( - callGraph->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); + callGraph->getPTACallGraphNode(svffun)->getId()); } } @@ -603,7 +603,7 @@ bool MRGenerator::isNonLocalObject(NodeID id, const SVFFunction* curFun) const /*! * Get Mod-Ref of a callee function */ -bool MRGenerator::handleCallsiteModRef(NodeBS& mod, NodeBS& ref, const CallICFGNode* cs, const SVFFunction* callee) +bool MRGenerator::handleCallsiteModRef(NodeBS& mod, NodeBS& ref, const CallICFGNode* cs, const CallGraphNode* callee) { /// if a callee is a heap allocator function, then its mod set of this callsite is the heap object. if(isHeapAllocExtCall(cs)) @@ -650,7 +650,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()->getFunction()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()); if(modrefchanged) worklist.push(edge->getSrcID()); } @@ -660,7 +660,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()->getFunction()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()); if(modrefchanged) worklist.push(edge->getSrcID()); } From 732594d2a870e468666c06bf6f4befb94bd7aff9 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 23:38:36 +1100 Subject: [PATCH 27/45] rm SVFFunction in MemSSA.h MSSAMuChi.h --- svf/include/MSSA/MSSAMuChi.h | 12 ++++++------ svf/include/MSSA/MemSSA.h | 20 ++++++++++---------- svf/lib/Graphs/SVFG.cpp | 4 ++-- svf/lib/MSSA/MemSSA.cpp | 12 ++++++------ svf/lib/MSSA/SVFGBuilder.cpp | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/svf/include/MSSA/MSSAMuChi.h b/svf/include/MSSA/MSSAMuChi.h index 1e5dc0e41..62daa0375 100644 --- a/svf/include/MSSA/MSSAMuChi.h +++ b/svf/include/MSSA/MSSAMuChi.h @@ -277,11 +277,11 @@ template class RetMU : public MSSAMU { private: - const SVFFunction* fun; + const CallGraphNode* fun; public: /// Constructor/Destructor for MU //@{ - RetMU(const SVFFunction* f, const MemRegion* m, Cond c = true) : + RetMU(const CallGraphNode* f, const MemRegion* m, Cond c = true) : MSSAMU(MSSAMU::RetMSSAMU,m,c), fun(f) { } @@ -289,7 +289,7 @@ class RetMU : public MSSAMU //@} /// Return function - inline const SVFFunction* getFunction() const + inline const CallGraphNode* getFunction() const { return fun; } @@ -578,11 +578,11 @@ template class EntryCHI : public MSSACHI { private: - const SVFFunction* fun; + const CallGraphNode* fun; public: /// Constructors for EntryCHI //@{ - EntryCHI(const SVFFunction* f, const MemRegion* m, Cond c = true) : + EntryCHI(const CallGraphNode* f, const MemRegion* m, Cond c = true) : MSSACHI(MSSADEF::EntryMSSACHI,m,c),fun(f) { } @@ -592,7 +592,7 @@ class EntryCHI : public MSSACHI //@} /// Return function - inline const SVFFunction* getFunction() const + inline const CallGraphNode* getFunction() const { return fun; } diff --git a/svf/include/MSSA/MemSSA.h b/svf/include/MSSA/MemSSA.h index 3424095a6..cc5b5c47b 100644 --- a/svf/include/MSSA/MemSSA.h +++ b/svf/include/MSSA/MemSSA.h @@ -85,8 +85,8 @@ class MemSSA //@} /// Map from fun to its entry chi set and return mu set - typedef Map FunToEntryChiSetMap; - typedef Map FunToReturnMuSetMap; + typedef Map FunToEntryChiSetMap; + typedef Map FunToReturnMuSetMap; /// For phi insertion //@{ @@ -123,11 +123,11 @@ class MemSSA MemSSAStat* stat; /// Create mu chi for candidate regions in a function - virtual void createMUCHI(const SVFFunction& fun); + virtual void createMUCHI(const CallGraphNode& fun); /// Insert phi for candidate regions in a function - virtual void insertPHI(const SVFFunction& fun); + virtual void insertPHI(const CallGraphNode& fun); /// SSA rename for a function - virtual void SSARename(const SVFFunction& fun); + virtual void SSARename(const CallGraphNode& fun); /// SSA rename for a basic block virtual void SSARenameBB(const SVFBasicBlock& bb); private: @@ -315,7 +315,7 @@ class MemSSA return mrGen; } /// We start from here - virtual void buildMemSSA(const SVFFunction& fun); + virtual void buildMemSSA(const CallGraphNode& fun); /// Perform statistics void performStat(); @@ -357,20 +357,20 @@ class MemSSA /// Has function entry chi or return mu //@{ - inline bool hasFuncEntryChi(const SVFFunction * fun) const + inline bool hasFuncEntryChi(const CallGraphNode * fun) const { return (funToEntryChiSetMap.find(fun) != funToEntryChiSetMap.end()); } - inline bool hasReturnMu(const SVFFunction * fun) const + inline bool hasReturnMu(const CallGraphNode * fun) const { return (funToReturnMuSetMap.find(fun) != funToReturnMuSetMap.end()); } - inline CHISet& getFuncEntryChiSet(const SVFFunction * fun) + inline CHISet& getFuncEntryChiSet(const CallGraphNode * fun) { return funToEntryChiSetMap[fun]; } - inline MUSet& getReturnMuSet(const SVFFunction * fun) + inline MUSet& getReturnMuSet(const CallGraphNode * fun) { return funToReturnMuSetMap[fun]; } diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index 6244f9294..d85ae55fd 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -286,7 +286,7 @@ void SVFG::addSVFGNodesForAddrTakenVars() for(CHISet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi) { const MemSSA::ENTRYCHI* chi = SVFUtil::cast(*pi); - addFormalINSVFGNode(pag->getICFG()->getFunEntryICFGNode(chi->getFunction()->getCallGraphNode()), chi->getResVer(), totalVFGNode++); + addFormalINSVFGNode(pag->getICFG()->getFunEntryICFGNode(chi->getFunction()), chi->getResVer(), totalVFGNode++); } } /// initialize memory SSA return mu nodes @@ -296,7 +296,7 @@ void SVFG::addSVFGNodesForAddrTakenVars() for(MUSet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi) { const MemSSA::RETMU* mu = SVFUtil::cast(*pi); - addFormalOUTSVFGNode(pag->getICFG()->getFunExitICFGNode(mu->getFunction()->getCallGraphNode()), mu->getMRVer(), totalVFGNode++); + addFormalOUTSVFGNode(pag->getICFG()->getFunExitICFGNode(mu->getFunction()), mu->getMRVer(), totalVFGNode++); } } /// initialize memory SSA callsite mu nodes diff --git a/svf/lib/MSSA/MemSSA.cpp b/svf/lib/MSSA/MemSSA.cpp index 6e189ad22..29d9d10bf 100644 --- a/svf/lib/MSSA/MemSSA.cpp +++ b/svf/lib/MSSA/MemSSA.cpp @@ -77,7 +77,7 @@ SVFIR* MemSSA::getPAG() /*! * Start building memory SSA */ -void MemSSA::buildMemSSA(const SVFFunction& fun) +void MemSSA::buildMemSSA(const CallGraphNode& fun) { assert(!isExtCall(&fun) && "we do not build memory ssa for external functions"); @@ -112,7 +112,7 @@ void MemSSA::buildMemSSA(const SVFFunction& fun) * Create mu/chi according to memory regions * collect used mrs in usedRegs and construction map from region to BB for prune SSA phi insertion */ -void MemSSA::createMUCHI(const SVFFunction& fun) +void MemSSA::createMUCHI(const CallGraphNode& fun) { @@ -198,7 +198,7 @@ void MemSSA::createMUCHI(const SVFFunction& fun) /* * Insert phi node */ -void MemSSA::insertPHI(const SVFFunction& fun) +void MemSSA::insertPHI(const CallGraphNode& fun) { DBOUT(DMSSA, @@ -246,7 +246,7 @@ void MemSSA::insertPHI(const SVFFunction& fun) /*! * SSA construction algorithm */ -void MemSSA::SSARename(const SVFFunction& fun) +void MemSSA::SSARename(const CallGraphNode& fun) { DBOUT(DMSSA, @@ -308,7 +308,7 @@ void MemSSA::SSARenameBB(const SVFBasicBlock& bb) else if(isRetInstNode(pNode)) { const SVFFunction* fun = bb.getParent(); - RenameMuSet(getReturnMuSet(fun)); + RenameMuSet(getReturnMuSet(fun->getCallGraphNode())); } } @@ -579,7 +579,7 @@ void MemSSA::dumpMSSA(OutStream& Out) CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction* fun = item.second->getFunction(); + const CallGraphNode* fun = item.second; if(Options::MSSAFun()!="" && Options::MSSAFun()!=fun->getName()) continue; diff --git a/svf/lib/MSSA/SVFGBuilder.cpp b/svf/lib/MSSA/SVFGBuilder.cpp index 0d66490f5..833d73d90 100644 --- a/svf/lib/MSSA/SVFGBuilder.cpp +++ b/svf/lib/MSSA/SVFGBuilder.cpp @@ -111,7 +111,7 @@ std::unique_ptr SVFGBuilder::buildMSSA(BVDataPTAImpl* pta, bool ptrOnlyM if (isExtCall(fun)) continue; - mssa->buildMemSSA(*(fun->getFunction())); + mssa->buildMemSSA(*(fun)); } mssa->performStat(); From 08a9d5e3b1bbcecae4233f25fb67d7f94c3ef534 Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 23:41:29 +1100 Subject: [PATCH 28/45] rm SVFFunction in MHP.h --- svf/include/MTA/MHP.h | 6 +++--- svf/lib/MTA/MHP.cpp | 10 +++++----- svf/lib/MTA/MTAStat.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/svf/include/MTA/MHP.h b/svf/include/MTA/MHP.h index 031238a10..d93c738af 100644 --- a/svf/include/MTA/MHP.h +++ b/svf/include/MTA/MHP.h @@ -46,7 +46,7 @@ class MHP { public: - typedef Set FunSet; + typedef Set FunSet; typedef FIFOWorkList CxtThreadStmtWorkList; typedef Set CxtThreadStmtSet; typedef Map ThreadStmtToThreadInterleav; @@ -55,7 +55,7 @@ class MHP typedef Set LockSpan; - typedef std::pair FuncPair; + typedef std::pair FuncPair; typedef Map FuncPairToBool; /// Constructor @@ -83,7 +83,7 @@ class MHP } /// Whether the function is connected from main function in thread call graph - bool isConnectedfromMain(const SVFFunction* fun); + bool isConnectedfromMain(const CallGraphNode* fun); // LockSpan getSpanfromCxtLock(NodeID l); /// Interface to query whether two instructions may happen-in-parallel diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index 7078afb6d..5ddf74bd6 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -189,7 +189,7 @@ void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) tcg->getPTACallGraphNode(curfun); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { - const SVFFunction* callee = (*nit)->getDstNode()->getCallNode()->getFunction(); + const CallGraphNode* callee = (*nit)->getDstNode()->getCallNode(); if (!isExtCall(callee)) { const ICFGNode* calleeInst = callee->getEntryBlock()->front(); @@ -521,10 +521,10 @@ bool MHP::isHBPair(NodeID tid1, NodeID tid2) return fja->isHBPair(tid1, tid2); } -bool MHP::isConnectedfromMain(const SVFFunction* fun) +bool MHP::isConnectedfromMain(const CallGraphNode* fun) { PTACallGraphNode* cgnode = - tcg->getPTACallGraphNode(fun->getCallGraphNode()); + tcg->getPTACallGraphNode(fun); FIFOWorkList worklist; TCT::PTACGNodeSet visited; worklist.push(cgnode); @@ -597,7 +597,7 @@ bool MHP::mayHappenInParallelCache(const ICFGNode* i1, const ICFGNode* i2) { if (!tct->isCandidateFun(i1->getFun()) && !tct->isCandidateFun(i2->getFun())) { - FuncPair funpair = std::make_pair(i1->getFun()->getFunction(), i2->getFun()->getFunction()); + FuncPair funpair = std::make_pair(i1->getFun(), i2->getFun()); FuncPairToBool::const_iterator it = nonCandidateFuncMHPRelMap.find(funpair); if (it == nonCandidateFuncMHPRelMap.end()) { @@ -671,7 +671,7 @@ void MHP::printInterleaving() void ForkJoinAnalysis::collectSCEVInfo() { // typedef Set CallInstSet; - // typedef Map FunToFJSites; + // typedef Map FunToFJSites; // FunToFJSites funToFJSites; // for (ThreadCallGraph::CallSiteSet::const_iterator it = tct->getThreadCallGraph()->forksitesBegin(), diff --git a/svf/lib/MTA/MTAStat.cpp b/svf/lib/MTA/MTAStat.cpp index a5c1b9849..0c929c079 100644 --- a/svf/lib/MTA/MTAStat.cpp +++ b/svf/lib/MTA/MTAStat.cpp @@ -122,7 +122,7 @@ void MTAStat::performMHPPairStat(MHP* mhp, LockAnalysis* lsa) { if(SVFUtil::isExtCall(fun)) continue; - if(!mhp->isConnectedfromMain(fun)) + if(!mhp->isConnectedfromMain(fun->getCallGraphNode())) continue; for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit) { From 2cc34cdc59bd9922ff4c222b9428b232dd6a781a Mon Sep 17 00:00:00 2001 From: hwg Date: Wed, 11 Dec 2024 23:43:58 +1100 Subject: [PATCH 29/45] rm SVFFunction in SaberCondAllocator.h --- svf/include/SABER/SaberCondAllocator.h | 2 +- svf/lib/SABER/SaberCondAllocator.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/svf/include/SABER/SaberCondAllocator.h b/svf/include/SABER/SaberCondAllocator.h index a90088f72..74377c118 100644 --- a/svf/include/SABER/SaberCondAllocator.h +++ b/svf/include/SABER/SaberCondAllocator.h @@ -53,7 +53,7 @@ class SaberCondAllocator typedef Map CondPosMap; ///< map a branch to its Condition typedef Map BBCondMap; /// map bb to a Condition typedef Set BasicBlockSet; - typedef Map FunToExitBBsMap; ///< map a function to all its basic blocks calling program exit + typedef Map FunToExitBBsMap; ///< map a function to all its basic blocks calling program exit typedef Map BBToCondMap; ///< map a basic block to its condition during control-flow guard computation typedef FIFOWorkList CFWorkList; ///< worklist for control-flow guard computation typedef Map> SVFGNodeToSVFGNodeSetMap; diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index 6a36a74ee..c61257b07 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -63,7 +63,7 @@ void SaberCondAllocator::allocate(const SVFModule *M) CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction *func = (item.second)->getFunction(); + const CallGraphNode *func = item.second; if (!SVFUtil::isExtCall(func)) { // Allocate conditions for a program. @@ -437,7 +437,7 @@ void SaberCondAllocator::collectBBCallingProgExit(const SVFBasicBlock &bb) if (SVFUtil::isProgExitCall(cs)) { const SVFFunction* svfun = bb.getParent(); - funToExitBBsMap[svfun].insert(&bb); + funToExitBBsMap[svfun->getCallGraphNode()].insert(&bb); } } } @@ -448,7 +448,7 @@ void SaberCondAllocator::collectBBCallingProgExit(const SVFBasicBlock &bb) bool SaberCondAllocator::isBBCallsProgExit(const SVFBasicBlock* bb) { const SVFFunction* svfun = bb->getParent(); - FunToExitBBsMap::const_iterator it = funToExitBBsMap.find(svfun); + FunToExitBBsMap::const_iterator it = funToExitBBsMap.find(svfun->getCallGraphNode()); if (it != funToExitBBsMap.end()) { for (const auto &bit: it->second) From 8cabf886935e6543136c4ad6ee768fc052137101 Mon Sep 17 00:00:00 2001 From: hwg Date: Thu, 12 Dec 2024 17:35:19 +1100 Subject: [PATCH 30/45] rm SVFFunction in SVFVariables.h & fix CallGraphNode constructor with GenericCallGraphNodeTy(i,CallNodeKd, f->getType()), fun(f) --- svf-llvm/lib/SVFIRBuilder.cpp | 8 ++--- svf/include/DDA/DDAVFSolver.h | 4 +-- svf/include/SVFIR/SVFVariables.h | 32 +++++++------------- svf/lib/Graphs/CallGraph.cpp | 2 +- svf/lib/MSSA/MemRegion.cpp | 2 +- svf/lib/MemoryModel/PointerAnalysis.cpp | 6 ++-- svf/lib/SVFIR/SVFVariables.cpp | 39 ++++++++++++++++--------- svf/lib/WPA/WPAPass.cpp | 4 +-- 8 files changed, 50 insertions(+), 47 deletions(-) diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 61a68eacd..ade6eeef8 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -1448,15 +1448,15 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge) LLVMModuleSet* llvmMS = llvmModuleSet(); if (const SVFInstruction* curInst = SVFUtil::dyn_cast(curVal)) { - const SVFFunction* srcFun = edge->getSrcNode()->getFunction(); - const SVFFunction* dstFun = edge->getDstNode()->getFunction(); + const CallGraphNode* srcFun = edge->getSrcNode()->getFunction(); + const CallGraphNode* dstFun = edge->getDstNode()->getFunction(); if(srcFun!=nullptr && !SVFUtil::isa(edge) && !SVFUtil::isa(edge->getSrcNode()) && !SVFUtil::isa(edge->getSrcNode())) { - assert(srcFun==curInst->getFunction() && "SrcNode of the PAGEdge not in the same function?"); + assert(srcFun==curInst->getFunction()->getCallGraphNode() && "SrcNode of the PAGEdge not in the same function?"); } if(dstFun!=nullptr && !SVFUtil::isa(edge) && !SVFUtil::isa(edge->getDstNode())) { - assert(dstFun==curInst->getFunction() && "DstNode of the PAGEdge not in the same function?"); + assert(dstFun==curInst->getFunction()->getCallGraphNode() && "DstNode of the PAGEdge not in the same function?"); } /// We assume every GepValVar and its GepStmt are unique across whole program diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index 08c48a1fb..e9e7a0135 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -475,10 +475,10 @@ class DDAVFSolver assert(baseObj && "base object is null??"); if(SVFUtil::isa(baseObj)) { - if(const SVFFunction* svffun = _pag->getGNode(id)->getFunction()) + if(const CallGraphNode* svffun = _pag->getGNode(id)->getFunction()) { return _callGraphSCC->isInCycle( - _callGraph->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); + _callGraph->getPTACallGraphNode(svffun)->getId()); } } return false; diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index 181094496..69e7ab7b9 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -101,7 +101,7 @@ class SVFVar : public GenericPAGNodeTy virtual const std::string getValueName() const = 0; /// Get containing function, or null for globals/constants - virtual inline const SVFFunction* getFunction() const + virtual inline const CallGraphNode* getFunction() const { return nullptr; } @@ -183,17 +183,7 @@ class SVFVar : public GenericPAGNodeTy } /// Check if this pointer is in an uncalled function - inline virtual bool ptrInUncalledFunction() const - { - if (const SVFFunction* fun = getFunction()) - { - return fun->isUncalledFunction(); - } - else - { - return false; - } - } + virtual bool ptrInUncalledFunction() const; /// Check if this variable represents constant/aggregate data virtual bool isConstDataOrAggData() const @@ -302,7 +292,7 @@ class ValVar: public SVFVar return icfgNode; } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; virtual const std::string toString() const; }; @@ -409,9 +399,9 @@ class ArgValVar: public ValVar return getName() + " (argument valvar)"; } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; - const SVFFunction* getParent() const; + const CallGraphNode* getParent() const; /// Return the index of this formal argument in its containing function. /// For example in "void foo(int a, float b)" a is 0 and b is 1. @@ -507,7 +497,7 @@ class GepValVar: public ValVar return gepValType; } - virtual const SVFFunction* getFunction() const + virtual const CallGraphNode* getFunction() const { return base->getFunction(); } @@ -726,7 +716,7 @@ class BaseObjVar : public ObjVar typeInfo = nullptr; } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; }; @@ -808,7 +798,7 @@ class GepObjVar: public ObjVar return getName() + "_" + std::to_string(apOffset); } - virtual const SVFFunction* getFunction() const + virtual const CallGraphNode* getFunction() const { return base->getFunction(); } @@ -1062,7 +1052,7 @@ class FunObjVar : public BaseObjVar return callGraphNode; } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; virtual bool isPointer() const; @@ -1821,7 +1811,7 @@ class RetValPN : public ValVar return callGraphNode; } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; virtual bool isPointer() const; @@ -1875,7 +1865,7 @@ class VarArgValPN : public ValVar { } - virtual const SVFFunction* getFunction() const; + virtual const CallGraphNode* getFunction() const; /// Return name of a LLVM value const std::string getValueName() const; diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index ffee50f50..1ca7757b2 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -57,7 +57,7 @@ const std::string CallGraphEdge::toString() const return rawstr.str(); } -CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNodeTy(i,CallNodeKd), fun(f) +CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNodeTy(i,CallNodeKd, f->getType()), fun(f) { isUncalled = f->isUncalledFunction(); isNotRet = !(f->hasReturn()); diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index a8b1d22b3..5ff30b74c 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -587,7 +587,7 @@ bool MRGenerator::isNonLocalObject(NodeID id, const CallGraphNode* curFun) const /// or a local variable is in function recursion cycles else if(SVFUtil::isa(pVar)) { - if(const CallGraphNode* svffun = pVar->getFunction()->getCallGraphNode()) + if(const CallGraphNode* svffun = pVar->getFunction()) { if(svffun!=curFun) return true; diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 37e42f514..c1034ab81 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -137,11 +137,11 @@ bool PointerAnalysis::isLocalVarInRecursiveFun(NodeID id) const assert(baseObjVar && "base object not found!!"); if(SVFUtil::isa(baseObjVar)) { - if(const SVFFunction* svffun = pag->getGNode(id)->getFunction()) + if(const CallGraphNode* svffun = pag->getGNode(id)->getFunction()) { return callGraphSCC->isInCycle( getCallGraph() - ->getPTACallGraphNode(svffun->getCallGraphNode())->getId()); + ->getPTACallGraphNode(svffun)->getId()); } } return false; @@ -396,7 +396,7 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta if(obj->isFunction()) { - const SVFFunction* calleefun = SVFUtil::cast(obj)->getFunction(); + const CallGraphNode* calleefun = SVFUtil::cast(obj)->getFunction(); const SVFFunction* callee = calleefun->getDefFunForMultipleModule(); if(SVFUtil::matchArgs(cs, callee) == false) diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index 5ff04600b..f6d537a79 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -44,6 +44,19 @@ SVFVar::SVFVar(NodeID i, const SVFType* svfType, PNODEK k) : { } +/// Check if this pointer is in an uncalled function +bool SVFVar::ptrInUncalledFunction() const +{ + if (const CallGraphNode* fun = getFunction()) + { + return fun->isUncalledFunction(); + } + else + { + return false; + } +} + bool SVFVar::isIsolatedNode() const { if (getInEdges().empty() && getOutEdges().empty()) @@ -68,10 +81,10 @@ void SVFVar::dump() const outs() << this->toString() << "\n"; } -const SVFFunction* ValVar::getFunction() const +const CallGraphNode* ValVar::getFunction() const { if(icfgNode) - return icfgNode->getFun()->getFunction(); + return icfgNode->getFun(); return nullptr; } @@ -109,14 +122,14 @@ ArgValVar::ArgValVar(NodeID i, u32_t argNo, const ICFGNode* icn, } -const SVFFunction* ArgValVar::getFunction() const +const CallGraphNode* ArgValVar::getFunction() const { return getParent(); } -const SVFFunction* ArgValVar::getParent() const +const CallGraphNode* ArgValVar::getParent() const { - return cgNode->getFunction(); + return cgNode; } bool ArgValVar::isPointer() const @@ -162,9 +175,9 @@ RetValPN::RetValPN(NodeID i, const CallGraphNode* node, const SVFType* svfType, { } -const SVFFunction* RetValPN::getFunction() const +const CallGraphNode* RetValPN::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } bool RetValPN::isPointer() const @@ -202,10 +215,10 @@ bool BaseObjVar::isBlackHoleObj() const } -const SVFFunction* BaseObjVar::getFunction() const +const CallGraphNode* BaseObjVar::getFunction() const { if(icfgNode) - return icfgNode->getFun()->getFunction(); + return icfgNode->getFun(); return nullptr; } const std::string BaseObjVar::toString() const @@ -436,9 +449,9 @@ bool FunObjVar::isIsolatedNode() const return callGraphNode->getFunction()->isIntrinsic(); } -const SVFFunction* FunObjVar::getFunction() const +const CallGraphNode* FunObjVar::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } const std::string FunObjVar::toString() const @@ -462,9 +475,9 @@ const std::string RetValPN::toString() const return rawstr.str(); } -const SVFFunction* VarArgValPN::getFunction() const +const CallGraphNode* VarArgValPN::getFunction() const { - return callGraphNode->getFunction(); + return callGraphNode; } const std::string VarArgValPN::getValueName() const diff --git a/svf/lib/WPA/WPAPass.cpp b/svf/lib/WPA/WPAPass.cpp index 4f3fac8d0..8f3f8078e 100644 --- a/svf/lib/WPA/WPAPass.cpp +++ b/svf/lib/WPA/WPAPass.cpp @@ -142,8 +142,8 @@ void WPAPass::PrintAliasPairs(PointerAnalysis* pta) node2 = rit->second; if(node1==node2) continue; - const SVFFunction* fun1 = node1->getFunction(); - const SVFFunction* fun2 = node2->getFunction(); + const CallGraphNode* fun1 = node1->getFunction(); + const CallGraphNode* fun2 = node2->getFunction(); AliasResult result = pta->alias(node1->getId(), node2->getId()); SVFUtil::outs() << (result == AliasResult::NoAlias ? "NoAlias" : "MayAlias") << " var" << node1->getId() << "[" << node1->getName() From 2370fb6d94e01e835eca2a65062f9ad0cf269efa Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 21:46:40 +1100 Subject: [PATCH 31/45] rm SVFFunction in BasicBlockG.h --- svf-llvm/lib/LLVMModule.cpp | 10 +++++++--- svf-llvm/lib/SVFIRBuilder.cpp | 6 +++--- svf/include/Graphs/BasicBlockG.h | 15 +++++++-------- svf/include/Graphs/CallGraph.h | 3 ++- svf/include/Graphs/ICFGNode.h | 4 ++-- svf/include/MTA/TCT.h | 2 +- svf/include/SABER/SaberCondAllocator.h | 8 ++++---- svf/include/SVFIR/SVFValue.h | 4 ++-- svf/include/Util/CallGraphBuilder.h | 2 ++ svf/lib/Graphs/CallGraph.cpp | 22 +++++++++++++++++++--- svf/lib/MSSA/MemSSA.cpp | 6 +++--- svf/lib/MTA/TCT.cpp | 10 +++++----- svf/lib/SABER/SaberCondAllocator.cpp | 12 ++++++------ svf/lib/Util/CDGBuilder.cpp | 2 +- svf/lib/Util/CallGraphBuilder.cpp | 10 +++++++--- 15 files changed, 71 insertions(+), 45 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index e6139f7c5..cd4442fb2 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -176,11 +176,13 @@ void LLVMModuleSet::build() if (Options::SVFMain()) addSVFMain(); + CallGraphBuilder callGraphBuilder; + callgraph = callGraphBuilder.createSVFIRCallGraph(svfModule); + createSVFDataStructure(); initSVFFunction(); + callGraphBuilder.initVFIRCallGraph(callgraph); - CallGraphBuilder callGraphBuilder; - callgraph = callGraphBuilder.createSVFIRCallGraph(svfModule); for (const auto& it : *callgraph) { SVFFunction* svffunc = const_cast(it.second->getFunction()); @@ -191,6 +193,7 @@ void LLVMModuleSet::build() ICFGBuilder icfgbuilder; icfg = icfgbuilder.build(); + callGraphBuilder.connectSVFIRCallGraphEdge(callgraph); @@ -277,7 +280,8 @@ void LLVMModuleSet::createSVFFunction(const Function* func) getSVFType(func->getFunctionType())), func->isDeclaration(), LLVMUtil::isIntrinsicFun(func), func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo); - BasicBlockGraph* bbGraph = new BasicBlockGraph(svfFunc); + CallGraphNode* callFunc = callgraph->addCallGraphNode(svfFunc); + BasicBlockGraph* bbGraph = new BasicBlockGraph(callFunc); svfFunc->setBasicBlockGraph(bbGraph); svfModule->addFunctionSet(svfFunc); addFunctionMap(func, svfFunc); diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index ade6eeef8..379665d7c 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -1452,11 +1452,11 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge) const CallGraphNode* dstFun = edge->getDstNode()->getFunction(); if(srcFun!=nullptr && !SVFUtil::isa(edge) && !SVFUtil::isa(edge->getSrcNode()) && !SVFUtil::isa(edge->getSrcNode())) { - assert(srcFun==curInst->getFunction()->getCallGraphNode() && "SrcNode of the PAGEdge not in the same function?"); + assert(srcFun==curInst->getFunction() && "SrcNode of the PAGEdge not in the same function?"); } if(dstFun!=nullptr && !SVFUtil::isa(edge) && !SVFUtil::isa(edge->getDstNode())) { - assert(dstFun==curInst->getFunction()->getCallGraphNode() && "DstNode of the PAGEdge not in the same function?"); + assert(dstFun==curInst->getFunction() && "DstNode of the PAGEdge not in the same function?"); } /// We assume every GepValVar and its GepStmt are unique across whole program @@ -1466,7 +1466,7 @@ void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(PAGEdge* edge) /// We will have one unique function exit ICFGNode for all returns if(curInst->isRetInst()) { - icfgNode = pag->getICFG()->getFunExitICFGNode(curInst->getFunction()->getCallGraphNode()); + icfgNode = pag->getICFG()->getFunExitICFGNode(curInst->getFunction()); } else { diff --git a/svf/include/Graphs/BasicBlockG.h b/svf/include/Graphs/BasicBlockG.h index df59dfce9..bb63cb779 100644 --- a/svf/include/Graphs/BasicBlockG.h +++ b/svf/include/Graphs/BasicBlockG.h @@ -39,7 +39,7 @@ namespace SVF class SVFBasicBlock; class BasicBlockEdge; class ICFGNode; -class SVFFunction; +class CallGraphNode; typedef GenericEdge GenericBasicBlockEdgeTy; class BasicBlockEdge: public GenericBasicBlockEdgeTy { @@ -75,7 +75,6 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy friend class SVFIRWriter; friend class SVFIRReader; friend class SVFIRBuilder; - friend class SVFFunction; friend class ICFGBuilder; friend class ICFG; @@ -86,7 +85,7 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy private: std::vector allICFGNodes; ///< all ICFGNodes in this BasicBlock - const SVFFunction* fun; /// Function where this BasicBlock is + const CallGraphNode* fun; /// Function where this BasicBlock is @@ -104,7 +103,7 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy public: /// Constructor without name - SVFBasicBlock(NodeID id, const SVFFunction* f): GenericBasicBlockNodeTy(id, BasicBlockKd), fun(f) + SVFBasicBlock(NodeID id, const CallGraphNode* f): GenericBasicBlockNodeTy(id, BasicBlockKd), fun(f) { } @@ -181,12 +180,12 @@ class SVFBasicBlock : public GenericBasicBlockNodeTy pred->succBBs.push_back(this); } - inline const SVFFunction* getParent() const + inline const CallGraphNode* getParent() const { return fun; } - inline const SVFFunction* getFunction() const + inline const CallGraphNode* getFunction() const { return fun; } @@ -287,10 +286,10 @@ class BasicBlockGraph: public GenericBasicBlockGraphTy { private: NodeID id{0}; - const SVFFunction* fun; + const CallGraphNode* fun; public: /// Constructor - BasicBlockGraph(const SVFFunction* f): fun(f) + BasicBlockGraph(const CallGraphNode* f): fun(f) { } diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 5cc6ed381..db0b38c5a 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -144,6 +144,7 @@ class CallGraphNode : public GenericCallGraphNodeTy /// Constructor CallGraphNode(NodeID i, const SVFFunction* f); + void init(); inline bool isDeclaration() const { @@ -403,7 +404,7 @@ class CallGraph : public GenericCallGraphTy /// Constructor CallGraph(); - void addCallGraphNode(const SVFFunction* fun); + CallGraphNode* addCallGraphNode(const SVFFunction* fun); const CallGraphNode* getCallGraphNode(const std::string& name); diff --git a/svf/include/Graphs/ICFGNode.h b/svf/include/Graphs/ICFGNode.h index 6d28463b2..a94c9a46e 100644 --- a/svf/include/Graphs/ICFGNode.h +++ b/svf/include/Graphs/ICFGNode.h @@ -205,7 +205,7 @@ class IntraICFGNode : public ICFGNode public: IntraICFGNode(NodeID id, const SVFBasicBlock* b, bool isReturn) : ICFGNode(id, IntraBlock), isRet(isReturn) { - fun = b->getFunction()->getCallGraphNode(); + fun = b->getFunction(); bb = b; } @@ -443,7 +443,7 @@ class CallICFGNode : public InterICFGNode isvararg(iv), isVirCallInst(ivc), vtabPtr(nullptr), virtualFunIdx(vfi), funNameOfVcall(fnv) { - fun = b->getFunction()->getCallGraphNode(); + fun = b->getFunction(); bb = b; type = ty; } diff --git a/svf/include/MTA/TCT.h b/svf/include/MTA/TCT.h index 5e43cc5c4..6a34616e0 100644 --- a/svf/include/MTA/TCT.h +++ b/svf/include/MTA/TCT.h @@ -399,7 +399,7 @@ class TCT: public GenericThreadCreateTreeTy bool hasLoop(const SVFBasicBlock* bb) const { - const SVFFunction* fun = bb->getFunction(); + const CallGraphNode* fun = bb->getFunction(); return fun->hasLoopInfo(bb); } bool hasLoop(const ICFGNode* inst) const diff --git a/svf/include/SABER/SaberCondAllocator.h b/svf/include/SABER/SaberCondAllocator.h index 74377c118..36a0833e0 100644 --- a/svf/include/SABER/SaberCondAllocator.h +++ b/svf/include/SABER/SaberCondAllocator.h @@ -146,8 +146,8 @@ class SaberCondAllocator inline bool postDominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const { - const SVFFunction* keyFunc = bbKey->getParent(); - const SVFFunction* valueFunc = bbValue->getParent(); + const CallGraphNode* keyFunc = bbKey->getParent(); + const CallGraphNode* valueFunc = bbValue->getParent(); bool funcEq = (keyFunc == valueFunc); (void)funcEq; // Suppress warning of unused variable under release build assert(funcEq && "two basicblocks should be in the same function!"); @@ -156,8 +156,8 @@ class SaberCondAllocator inline bool dominate(const SVFBasicBlock* bbKey, const SVFBasicBlock* bbValue) const { - const SVFFunction* keyFunc = bbKey->getParent(); - const SVFFunction* valueFunc = bbValue->getParent(); + const CallGraphNode* keyFunc = bbKey->getParent(); + const CallGraphNode* valueFunc = bbValue->getParent(); bool funcEq = (keyFunc == valueFunc); (void)funcEq; // Suppress warning of unused variable under release build assert(funcEq && "two basicblocks should be in the same function!"); diff --git a/svf/include/SVFIR/SVFValue.h b/svf/include/SVFIR/SVFValue.h index 1ad7098a3..65d93859c 100644 --- a/svf/include/SVFIR/SVFValue.h +++ b/svf/include/SVFIR/SVFValue.h @@ -563,7 +563,7 @@ class SVFInstruction : public SVFValue return bb; } - inline const SVFFunction* getFunction() const + inline const CallGraphNode* getFunction() const { return bb->getParent(); } @@ -642,7 +642,7 @@ class SVFCallInst : public SVFInstruction { return SVFUtil::dyn_cast(calledVal); } - inline const SVFFunction* getCaller() const + inline const CallGraphNode* getCaller() const { return getFunction(); } diff --git a/svf/include/Util/CallGraphBuilder.h b/svf/include/Util/CallGraphBuilder.h index 921532f4b..961486d80 100644 --- a/svf/include/Util/CallGraphBuilder.h +++ b/svf/include/Util/CallGraphBuilder.h @@ -49,6 +49,8 @@ class CallGraphBuilder /// Buidl SVFIR callgraoh CallGraph* createSVFIRCallGraph(SVFModule* svfModule); + CallGraph* initVFIRCallGraph(CallGraph* callgraph); + void connectSVFIRCallGraphEdge(CallGraph* callGraph); /// Buidl PTA callgraoh diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 1ca7757b2..65fb09d1b 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -70,8 +70,23 @@ CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNo realDefFun = f->getDefFunForMultipleModule(); bbGraph = const_cast(f->getBasicBlockGraph()); allArgs = f->getArgsList(); - if (f->hasBasicBlock()) - exitBlock = f->getExitBB(); +} + +void CallGraphNode::init() +{ + isUncalled = fun->isUncalledFunction(); + isNotRet = !(fun->hasReturn()); + isDecl = fun->isDeclaration(); + intrinsic = fun->isIntrinsic(); + addrTaken = fun->hasAddressTaken(); + varArg = fun->isVarArg(); + funcType = fun->getFunctionType(); + loopAndDom = fun->getLoopAndDomInfo(); + realDefFun = fun->getDefFunForMultipleModule(); + bbGraph = const_cast(fun->getBasicBlockGraph()); + allArgs = fun->getArgsList(); + if (fun->hasBasicBlock()) + exitBlock = fun->getExitBB(); } @@ -102,12 +117,13 @@ void CallGraph::destroy() /*! * Add call graph node */ -void CallGraph::addCallGraphNode(const SVFFunction* fun) +CallGraphNode* CallGraph::addCallGraphNode(const SVFFunction* fun) { NodeID id = callGraphNodeNum; CallGraphNode *callGraphNode = new CallGraphNode(id, fun); addGNode(id, callGraphNode); callGraphNodeNum++; + return callGraphNode; } /*! diff --git a/svf/lib/MSSA/MemSSA.cpp b/svf/lib/MSSA/MemSSA.cpp index 29d9d10bf..608abd017 100644 --- a/svf/lib/MSSA/MemSSA.cpp +++ b/svf/lib/MSSA/MemSSA.cpp @@ -307,8 +307,8 @@ void MemSSA::SSARenameBB(const SVFBasicBlock& bb) } else if(isRetInstNode(pNode)) { - const SVFFunction* fun = bb.getParent(); - RenameMuSet(getReturnMuSet(fun->getCallGraphNode())); + const CallGraphNode* fun = bb.getParent(); + RenameMuSet(getReturnMuSet(fun)); } } @@ -322,7 +322,7 @@ void MemSSA::SSARenameBB(const SVFBasicBlock& bb) } // for succ basic block in dominator tree - const SVFFunction* fun = bb.getParent(); + const CallGraphNode* fun = bb.getParent(); const Map>& dtBBsMap = fun->getDomTreeMap(); Map>::const_iterator mapIter = dtBBsMap.find(&bb); if (mapIter != dtBBsMap.end()) diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index d34901467..a1665aa19 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -137,8 +137,8 @@ void TCT::markRelProcs() { for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->forksitesBegin(), eit = tcg->forksitesEnd(); it != eit; ++it) { - const SVFFunction* svfun = (*it)->getParent()->getParent(); - markRelProcs(svfun->getCallGraphNode()); + const CallGraphNode* svfun = (*it)->getParent()->getParent(); + markRelProcs(svfun); for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++) { @@ -150,8 +150,8 @@ void TCT::markRelProcs() for (ThreadCallGraph::CallSiteSet::const_iterator it = tcg->joinsitesBegin(), eit = tcg->joinsitesEnd(); it != eit; ++it) { - const SVFFunction* svfun = (*it)->getParent()->getParent(); - markRelProcs(svfun->getCallGraphNode()); + const CallGraphNode* svfun = (*it)->getParent()->getParent(); + markRelProcs(svfun); } if(candidateFuncSet.empty()) @@ -379,7 +379,7 @@ bool TCT::isLoopExitOfJoinLoop(const SVFBasicBlock* bb) */ const TCT::LoopBBs& TCT::getLoop(const SVFBasicBlock* bb) { - const SVFFunction* fun = bb->getParent(); + const CallGraphNode* fun = bb->getParent(); return fun->getLoopInfo(bb); } diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index c61257b07..e78402fea 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -265,7 +265,7 @@ SaberCondAllocator::Condition SaberCondAllocator::evaluateProgExit(const BranchS */ SaberCondAllocator::Condition SaberCondAllocator::evaluateLoopExitBranch(const SVFBasicBlock* bb, const SVFBasicBlock* dst) { - const SVFFunction* svffun = bb->getParent(); + const CallGraphNode* svffun = bb->getParent(); assert(svffun == dst->getParent() && "two basic blocks should be in the same function"); if (svffun->isLoopHeader(bb)) @@ -436,8 +436,8 @@ void SaberCondAllocator::collectBBCallingProgExit(const SVFBasicBlock &bb) if (const CallICFGNode* cs = SVFUtil::dyn_cast(icfgNode)) if (SVFUtil::isProgExitCall(cs)) { - const SVFFunction* svfun = bb.getParent(); - funToExitBBsMap[svfun->getCallGraphNode()].insert(&bb); + const CallGraphNode* svfun = bb.getParent(); + funToExitBBsMap[svfun].insert(&bb); } } } @@ -447,8 +447,8 @@ void SaberCondAllocator::collectBBCallingProgExit(const SVFBasicBlock &bb) */ bool SaberCondAllocator::isBBCallsProgExit(const SVFBasicBlock* bb) { - const SVFFunction* svfun = bb->getParent(); - FunToExitBBsMap::const_iterator it = funToExitBBsMap.find(svfun->getCallGraphNode()); + const CallGraphNode* svfun = bb->getParent(); + FunToExitBBsMap::const_iterator it = funToExitBBsMap.find(svfun); if (it != funToExitBBsMap.end()) { for (const auto &bit: it->second) @@ -506,7 +506,7 @@ SaberCondAllocator::ComputeInterCallVFGGuard(const SVFBasicBlock* srcBB, const S SaberCondAllocator::Condition SaberCondAllocator::ComputeInterRetVFGGuard(const SVFBasicBlock* srcBB, const SVFBasicBlock* dstBB, const SVFBasicBlock* retBB) { - const SVFFunction* parent = srcBB->getParent(); + const CallGraphNode* parent = srcBB->getParent(); const SVFBasicBlock* funExitBB = parent->getExitBB(); Condition c1 = ComputeIntraVFGGuard(srcBB, funExitBB); diff --git a/svf/lib/Util/CDGBuilder.cpp b/svf/lib/Util/CDGBuilder.cpp index 08ec30024..acbe0685c 100644 --- a/svf/lib/Util/CDGBuilder.cpp +++ b/svf/lib/Util/CDGBuilder.cpp @@ -67,7 +67,7 @@ CDGBuilder::extractNodesBetweenPdomNodes(const SVFBasicBlock *succ, const SVFBas { if (succ == LCA) return; std::vector path; - SVFLoopAndDomInfo *ld = const_cast(LCA->getFunction())->getLoopAndDomInfo(); + SVFLoopAndDomInfo *ld = const_cast(LCA->getFunction())->getLoopAndDomInfo(); dfsNodesBetweenPdomNodes(LCA, succ, path, tgtNodes, ld); } diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 46f4e0aba..36ce556b9 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -40,10 +40,14 @@ using namespace SVFUtil; CallGraph* CallGraphBuilder::createSVFIRCallGraph(SVFModule* svfModule) { - CallGraph* callgraph = new CallGraph(); - for (const SVFFunction* svfFunc: svfModule->getFunctionSet()) + return new CallGraph(); +} + +CallGraph* CallGraphBuilder::initVFIRCallGraph(CallGraph* callgraph) +{ + for (const auto& item : *callgraph) { - callgraph->addCallGraphNode(svfFunc); + (item.second)->init(); } return callgraph; } From 2b9d888d83faa2832058413e0ab91a3d85ce7018 Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 22:03:04 +1100 Subject: [PATCH 32/45] refactor: replace SVFFunction with CallGraphNode in SVFUtil and ThreadAPI --- svf/include/Util/SVFUtil.h | 4 ++-- svf/lib/Graphs/SVFG.cpp | 4 ++-- svf/lib/Util/SVFUtil.cpp | 8 ++++---- svf/lib/Util/ThreadAPI.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index 542cb5947..dba4fbb79 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -321,10 +321,10 @@ inline bool isProgEntryFunction(const SVFFunction* fun) } /// Get program entry function from function name. -const SVFFunction* getProgFunction(const std::string& funName); +const CallGraphNode* getProgFunction(const std::string& funName); /// Get program entry function. -const SVFFunction* getProgEntryFunction(); +const CallGraphNode* getProgEntryFunction(); /// Return true if this is a program exit function call //@{ diff --git a/svf/lib/Graphs/SVFG.cpp b/svf/lib/Graphs/SVFG.cpp index d85ae55fd..967fdc9c2 100644 --- a/svf/lib/Graphs/SVFG.cpp +++ b/svf/lib/Graphs/SVFG.cpp @@ -427,10 +427,10 @@ void SVFG::connectIndirectSVFGEdges() */ void SVFG::connectFromGlobalToProgEntry() { - const SVFFunction* mainFunc = SVFUtil::getProgEntryFunction(); + const CallGraphNode* mainFunc = SVFUtil::getProgEntryFunction(); if (!mainFunc) return; - FormalINSVFGNodeSet& formalIns = getFormalINSVFGNodes(mainFunc->getCallGraphNode()); + FormalINSVFGNodeSet& formalIns = getFormalINSVFGNodes(mainFunc); if (formalIns.empty()) return; diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index 747621a59..07a29f00c 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -390,27 +390,27 @@ bool SVFUtil::isProgExitCall(const CallICFGNode* cs) } /// Get program entry function from module. -const SVFFunction* SVFUtil::getProgFunction(const std::string& funName) +const CallGraphNode* SVFUtil::getProgFunction(const std::string& funName) { CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const CallGraphNode*fun = item.second; if (fun->getName()==funName) - return fun->getFunction(); + return fun; } return nullptr; } /// Get program entry function from module. -const SVFFunction* SVFUtil::getProgEntryFunction() +const CallGraphNode* SVFUtil::getProgEntryFunction() { CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { const CallGraphNode*fun = item.second; if (isProgEntryFunction(fun->getFunction())) - return (fun->getFunction()); + return fun; } return nullptr; } diff --git a/svf/lib/Util/ThreadAPI.cpp b/svf/lib/Util/ThreadAPI.cpp index c4536dec5..660ca0db2 100644 --- a/svf/lib/Util/ThreadAPI.cpp +++ b/svf/lib/Util/ThreadAPI.cpp @@ -285,7 +285,7 @@ void ThreadAPI::performAPIStat(SVFModule* module) CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - for (SVFFunction::const_iterator bit = (item.second)->getFunction()->begin(), ebit = (item.second)->getFunction()->end(); bit != ebit; ++bit) + for (CallGraphNode::const_bb_iterator bit = (item.second)->begin(), ebit = (item.second)->end(); bit != ebit; ++bit) { const SVFBasicBlock* bb = bit->second; for (const auto& svfInst: bb->getICFGNodeList()) From e96388ae7d06a5946b485401ae28716221f271ca Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 22:17:18 +1100 Subject: [PATCH 33/45] refactor: replace SVFFunction with CallGraphNode in matchArgs and related functions --- svf/include/Util/SVFUtil.h | 2 +- svf/lib/Graphs/CallGraph.cpp | 3 --- svf/lib/Graphs/VFG.cpp | 2 +- svf/lib/MemoryModel/PointerAnalysis.cpp | 2 +- svf/lib/Util/SVFUtil.cpp | 2 +- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index dba4fbb79..d83a56c9d 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -187,7 +187,7 @@ inline bool isNonInstricCallSite(const ICFGNode* inst) /// Match arguments for callsite at caller and callee /// if the arg size does not match then we do not need to connect this parameter /// unless the callee is a variadic function (the first parameter of variadic function is its parameter number) -bool matchArgs(const CallICFGNode* cs, const SVFFunction* callee); +bool matchArgs(const CallICFGNode* cs, const CallGraphNode* callee); /// Split into two substrings around the first occurrence of a separator string. diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 65fb09d1b..6f8271e57 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -67,9 +67,6 @@ CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNo varArg = f->isVarArg(); funcType = f->getFunctionType(); loopAndDom = f->getLoopAndDomInfo(); - realDefFun = f->getDefFunForMultipleModule(); - bbGraph = const_cast(f->getBasicBlockGraph()); - allArgs = f->getArgsList(); } void CallGraphNode::init() diff --git a/svf/lib/Graphs/VFG.cpp b/svf/lib/Graphs/VFG.cpp index abeebf1e3..917ad7f06 100644 --- a/svf/lib/Graphs/VFG.cpp +++ b/svf/lib/Graphs/VFG.cpp @@ -962,7 +962,7 @@ void VFG::connectCallerAndCallee(const CallICFGNode* callBlockNode, const CallGr const RetICFGNode* retBlockNode = callBlockNode->getRetICFGNode(); // connect actual and formal param if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) && - matchArgs(callBlockNode, callee->getFunction())) + matchArgs(callBlockNode, callee)) { const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callBlockNode); const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee); diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index c1034ab81..75e2219cf 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -399,7 +399,7 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta const CallGraphNode* calleefun = SVFUtil::cast(obj)->getFunction(); const SVFFunction* callee = calleefun->getDefFunForMultipleModule(); - if(SVFUtil::matchArgs(cs, callee) == false) + if(SVFUtil::matchArgs(cs, callee->getCallGraphNode()) == false) continue; if(0 == getIndCallMap()[cs].count(callee->getCallGraphNode())) diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index 07a29f00c..91a2b2a0a 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -304,7 +304,7 @@ void SVFUtil::stopAnalysisLimitTimer(bool limitTimerSet) /// unless the callee is a variadic function (the first parameter of variadic function is its parameter number) /// e.g., void variadicFoo(int num, ...); variadicFoo(5, 1,2,3,4,5) /// for variadic function, callsite arg size must be greater than or equal to callee arg size -bool SVFUtil::matchArgs(const CallICFGNode* call, const SVFFunction* callee) +bool SVFUtil::matchArgs(const CallICFGNode* call, const CallGraphNode* callee) { if (callee->isVarArg() || ThreadAPI::getThreadAPI()->isTDFork(call)) return call->arg_size() >= callee->arg_size(); From 626553fc21a6259e4ffdd57e488495143427d987 Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 22:21:13 +1100 Subject: [PATCH 34/45] refactor: replace SVFFunction with CallGraphNode in SVFStat branchStat function --- svf/lib/Util/SVFStat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/svf/lib/Util/SVFStat.cpp b/svf/lib/Util/SVFStat.cpp index cc9aa3d12..dd6e2e071 100644 --- a/svf/lib/Util/SVFStat.cpp +++ b/svf/lib/Util/SVFStat.cpp @@ -226,8 +226,8 @@ void SVFStat::branchStat() CallGraph* svfirCallGraph = PAG::getPAG()->getCallGraph(); for (const auto& item: *svfirCallGraph) { - const SVFFunction* func = item.second->getFunction(); - for (SVFFunction::const_iterator bbIt = func->begin(), bbEit = func->end(); + const CallGraphNode* func = item.second; + for (CallGraphNode::const_bb_iterator bbIt = func->begin(), bbEit = func->end(); bbIt != bbEit; ++bbIt) { const SVFBasicBlock* bb = bbIt->second; From 0d6b3078d813f8d07273ce88013758183f8f61ad Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 22:27:13 +1100 Subject: [PATCH 35/45] refactor: replace SVFFunction with CallGraphNode in MemRegion, MemSSA, and SaberCondAllocator --- svf/lib/MSSA/MemRegion.cpp | 2 +- svf/lib/MSSA/MemSSA.cpp | 2 +- svf/lib/SABER/SaberCondAllocator.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 5ff30b74c..56826cdc9 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -183,7 +183,7 @@ void MRGenerator::collectModRefForLoadStore() if (Options::IgnoreDeadFun() && fun.isUncalledFunction()) continue; - for (SVFFunction::const_iterator iter = fun.begin(), eiter = fun.end(); + for (CallGraphNode::const_bb_iterator iter = fun.begin(), eiter = fun.end(); iter != eiter; ++iter) { const SVFBasicBlock* bb = iter->second; diff --git a/svf/lib/MSSA/MemSSA.cpp b/svf/lib/MSSA/MemSSA.cpp index 608abd017..148993a5a 100644 --- a/svf/lib/MSSA/MemSSA.cpp +++ b/svf/lib/MSSA/MemSSA.cpp @@ -594,7 +594,7 @@ void MemSSA::dumpMSSA(OutStream& Out) } } - for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); + for (CallGraphNode::const_bb_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit) { const SVFBasicBlock* bb = bit->second; diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index e78402fea..0806dc52c 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -67,7 +67,7 @@ void SaberCondAllocator::allocate(const SVFModule *M) if (!SVFUtil::isExtCall(func)) { // Allocate conditions for a program. - for (SVFFunction::const_iterator bit = func->begin(), ebit = func->end(); + for (CallGraphNode::const_bb_iterator bit = func->begin(), ebit = func->end(); bit != ebit; ++bit) { const SVFBasicBlock* bb = bit->second; From c5e3b81df0c00b496307cfe74807bd25c3042a57 Mon Sep 17 00:00:00 2001 From: hwg Date: Fri, 31 Jan 2025 22:51:30 +1100 Subject: [PATCH 36/45] refactor: replace SVFFunction with CallGraphNode in SVFModule, related MTA etc --- svf-llvm/lib/LLVMModule.cpp | 2 +- svf/include/Graphs/CallGraph.h | 4 ++++ svf/include/SVFIR/SVFModule.h | 6 +++--- svf/lib/MTA/LockAnalysis.cpp | 2 +- svf/lib/MTA/MHP.cpp | 4 ++-- svf/lib/MTA/MTA.cpp | 2 +- svf/lib/MTA/MTAStat.cpp | 4 ++-- svf/lib/SVFIR/SVFModule.cpp | 6 ++---- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index cd4442fb2..6b31408b1 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -283,7 +283,7 @@ void LLVMModuleSet::createSVFFunction(const Function* func) CallGraphNode* callFunc = callgraph->addCallGraphNode(svfFunc); BasicBlockGraph* bbGraph = new BasicBlockGraph(callFunc); svfFunc->setBasicBlockGraph(bbGraph); - svfModule->addFunctionSet(svfFunc); + svfModule->addFunctionSet(callFunc); addFunctionMap(func, svfFunc); for (const Argument& arg : func->args()) diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index db0b38c5a..64a006902 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -144,6 +144,10 @@ class CallGraphNode : public GenericCallGraphNodeTy /// Constructor CallGraphNode(NodeID i, const SVFFunction* f); + ~CallGraphNode(){ + delete fun; + } + void init(); inline bool isDeclaration() const diff --git a/svf/include/SVFIR/SVFModule.h b/svf/include/SVFIR/SVFModule.h index c4735cb19..de7b3c073 100644 --- a/svf/include/SVFIR/SVFModule.h +++ b/svf/include/SVFIR/SVFModule.h @@ -43,7 +43,7 @@ class SVFModule friend class SVFIRReader; public: - typedef std::vector FunctionSetType; + typedef std::vector FunctionSetType; typedef std::vector GlobalSetType; typedef std::vector AliasSetType; typedef std::vector ConstantType; @@ -100,10 +100,10 @@ class SVFModule return !pagReadFromTxt.empty(); } - const SVFFunction* getSVFFunction(const std::string& name); + const CallGraphNode* getSVFFunction(const std::string& name); ///@{ - inline void addFunctionSet(SVFFunction* svfFunc) + inline void addFunctionSet(CallGraphNode* svfFunc) { FunctionSet.push_back(svfFunc); } diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 43daa3441..2c695a680 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -70,7 +70,7 @@ void LockAnalysis::collectLockUnlocksites() { ThreadCallGraph* tcg=tct->getThreadCallGraph(); - for (const SVFFunction* F : tct->getSVFModule()->getFunctionSet()) + for (const CallGraphNode* F : tct->getSVFModule()->getFunctionSet()) { for (auto it : *F) { diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index 5ddf74bd6..7e20a00e1 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -144,9 +144,9 @@ void MHP::analyzeInterleaving() void MHP::updateNonCandidateFunInterleaving() { SVFModule* module = tct->getSVFModule(); - for (const SVFFunction* fun : module->getFunctionSet()) + for (const CallGraphNode* fun : module->getFunctionSet()) { - if (!tct->isCandidateFun(fun->getCallGraphNode()) && !isExtCall(fun)) + if (!tct->isCandidateFun(fun) && !isExtCall(fun)) { const ICFGNode* entryNode = fun->getEntryBlock()->front(); diff --git a/svf/lib/MTA/MTA.cpp b/svf/lib/MTA/MTA.cpp index 5b6e671c3..dd193c824 100644 --- a/svf/lib/MTA/MTA.cpp +++ b/svf/lib/MTA/MTA.cpp @@ -136,7 +136,7 @@ void MTA::detect(SVFModule* module) PointerAnalysis* pta = AndersenWaveDiff::createAndersenWaveDiff(pag); // Add symbols for all of the functions and the instructions in them. - for (const SVFFunction* F : module->getFunctionSet()) + for (const CallGraphNode* F : module->getFunctionSet()) { // collect and create symbols inside the function body for (auto it : *F) diff --git a/svf/lib/MTA/MTAStat.cpp b/svf/lib/MTA/MTAStat.cpp index 0c929c079..3256b387f 100644 --- a/svf/lib/MTA/MTAStat.cpp +++ b/svf/lib/MTA/MTAStat.cpp @@ -118,11 +118,11 @@ void MTAStat::performMHPPairStat(MHP* mhp, LockAnalysis* lsa) Set instSet1; Set instSet2; SVFModule* mod = mhp->getTCT()->getSVFModule(); - for (const SVFFunction* fun : mod->getFunctionSet()) + for (const CallGraphNode* fun : mod->getFunctionSet()) { if(SVFUtil::isExtCall(fun)) continue; - if(!mhp->isConnectedfromMain(fun->getCallGraphNode())) + if(!mhp->isConnectedfromMain(fun)) continue; for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit) { diff --git a/svf/lib/SVFIR/SVFModule.cpp b/svf/lib/SVFIR/SVFModule.cpp index 3fcd0a573..b8168fdac 100644 --- a/svf/lib/SVFIR/SVFModule.cpp +++ b/svf/lib/SVFIR/SVFModule.cpp @@ -34,8 +34,6 @@ SVFModule* SVFModule::svfModule = nullptr; SVFModule::~SVFModule() { - for (const SVFFunction* f : FunctionSet) - delete f; for (const SVFConstant* c : ConstantSet) delete c; for (const SVFValue* o : OtherValueSet) @@ -45,9 +43,9 @@ SVFModule::~SVFModule() ExtAPI::destory(); } -const SVFFunction* SVFModule::getSVFFunction(const std::string& name) +const CallGraphNode* SVFModule::getSVFFunction(const std::string& name) { - for (const SVFFunction* fun : getFunctionSet()) + for (const CallGraphNode* fun : getFunctionSet()) { if (fun->getName() == name) { From 4ad1f61ba02308a0fce5ef2b43ae4429fe1913fe Mon Sep 17 00:00:00 2001 From: hwg Date: Sat, 1 Feb 2025 16:21:17 +1100 Subject: [PATCH 37/45] refactor: update SVFFunction references to CallGraphNode in CallGraph --- svf-llvm/lib/LLVMModule.cpp | 4 +++- svf/include/Graphs/CallGraph.h | 8 ++++---- svf/lib/Graphs/CallGraph.cpp | 2 +- svf/lib/MemoryModel/PointerAnalysis.cpp | 14 +++++++------- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 6b31408b1..15143ee00 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -181,7 +181,6 @@ void LLVMModuleSet::build() createSVFDataStructure(); initSVFFunction(); - callGraphBuilder.initVFIRCallGraph(callgraph); for (const auto& it : *callgraph) { @@ -190,6 +189,9 @@ void LLVMModuleSet::build() addFunctionMap(SVFUtil::cast(getLLVMValue(svffunc)), it.second); } + callGraphBuilder.initVFIRCallGraph(callgraph); + + ICFGBuilder icfgbuilder; icfg = icfgbuilder.build(); diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 64a006902..d5f678b96 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -135,10 +135,10 @@ class CallGraphNode : public GenericCallGraphNodeTy bool varArg; /// return true if this function supports variable arguments const SVFFunctionType* funcType; /// FunctionType, which is different from the type (PointerType) of this SVFFunction SVFLoopAndDomInfo* loopAndDom; /// the loop and dominate information - const SVFFunction* realDefFun; /// the definition of a function across multiple modules + const CallGraphNode * realDefFun{nullptr}; /// the definition of a function across multiple modules BasicBlockGraph* bbGraph; /// the basic block graph of this function std::vector allArgs; /// all formal arguments of this function - const SVFBasicBlock *exitBlock; /// a 'single' basic block having no successors and containing return instruction in a function + const SVFBasicBlock *exitBlock{nullptr}; /// a 'single' basic block having no successors and containing return instruction in a function public: /// Constructor @@ -252,10 +252,10 @@ class CallGraphNode : public GenericCallGraphNodeTy return loopAndDom->postDominate(bbKey,bbValue); } - inline const SVFFunction* getDefFunForMultipleModule() const + inline const CallGraphNode* getDefFunForMultipleModule() const { if(realDefFun==nullptr) - return this->fun; + return this; return realDefFun; } diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 6f8271e57..509f08458 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -79,7 +79,7 @@ void CallGraphNode::init() varArg = fun->isVarArg(); funcType = fun->getFunctionType(); loopAndDom = fun->getLoopAndDomInfo(); - realDefFun = fun->getDefFunForMultipleModule(); + realDefFun = fun->getDefFunForMultipleModule()->getCallGraphNode(); bbGraph = const_cast(fun->getBasicBlockGraph()); allArgs = fun->getArgsList(); if (fun->hasBasicBlock()) diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 75e2219cf..6ae1e6794 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -397,17 +397,17 @@ void PointerAnalysis::resolveIndCalls(const CallICFGNode* cs, const PointsTo& ta if(obj->isFunction()) { const CallGraphNode* calleefun = SVFUtil::cast(obj)->getFunction(); - const SVFFunction* callee = calleefun->getDefFunForMultipleModule(); + const CallGraphNode* callee = calleefun->getDefFunForMultipleModule(); - if(SVFUtil::matchArgs(cs, callee->getCallGraphNode()) == false) + if(SVFUtil::matchArgs(cs, callee) == false) continue; - if(0 == getIndCallMap()[cs].count(callee->getCallGraphNode())) + if(0 == getIndCallMap()[cs].count(callee)) { - newEdges[cs].insert(callee->getCallGraphNode()); - getIndCallMap()[cs].insert(callee->getCallGraphNode()); + newEdges[cs].insert(callee); + getIndCallMap()[cs].insert(callee); - callgraph->addIndirectCallGraphEdge(cs, cs->getCaller(), callee->getCallGraphNode()); + callgraph->addIndirectCallGraphEdge(cs, cs->getCaller(), callee); // FIXME: do we need to update llvm call graph here? // The indirect call is maintained by ourself, We may update llvm's when we need to //PTACallGraphNode* callgraphNode = callgraph->getOrInsertFunction(cs.getCaller()); @@ -472,7 +472,7 @@ void PointerAnalysis::connectVCallToVFns(const CallICFGNode* cs, const VFunSet & feit = vfns.end(); fit != feit; ++fit) { const CallGraphNode* callee = *fit; - callee = callee->getDefFunForMultipleModule()->getCallGraphNode(); + callee = callee->getDefFunForMultipleModule(); if (getIndCallMap()[cs].count(callee) > 0) continue; if(cs->arg_size() == callee->arg_size() || From 4b6c780d437159def0486625fe88b5a675a3c1e5 Mon Sep 17 00:00:00 2001 From: hwg Date: Sat, 1 Feb 2025 17:15:08 +1100 Subject: [PATCH 38/45] rm SVFFunction in ExtAPI --- svf-llvm/include/SVF-LLVM/LLVMModule.h | 18 ++++++++- svf-llvm/include/SVF-LLVM/SVFIRBuilder.h | 2 +- svf-llvm/lib/ICFGBuilder.cpp | 4 +- svf-llvm/lib/LLVMLoopAnalysis.cpp | 2 +- svf-llvm/lib/LLVMModule.cpp | 28 ++++++------- svf-llvm/lib/LLVMUtil.cpp | 14 +++---- svf-llvm/lib/SVFIRBuilder.cpp | 8 ++-- svf-llvm/lib/SVFIRExtAPI.cpp | 2 +- svf-llvm/lib/SymbolTableBuilder.cpp | 4 +- svf/include/Util/ExtAPI.h | 30 +++++++------- svf/include/Util/SVFUtil.h | 21 ++++------ svf/lib/AE/Svfexe/AEDetector.cpp | 2 +- svf/lib/AE/Svfexe/AbsExtAPI.cpp | 7 ++-- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 2 +- svf/lib/CFL/CFLAlias.cpp | 2 +- svf/lib/DDA/FlowDDA.cpp | 42 -------------------- svf/lib/Graphs/CallGraph.cpp | 3 +- svf/lib/Graphs/PTACallGraph.cpp | 4 +- svf/lib/Graphs/ThreadCallGraph.cpp | 6 +-- svf/lib/MTA/MTAStat.cpp | 2 +- svf/lib/Util/ExtAPI.cpp | 34 ++++++++-------- svf/lib/Util/SVFUtil.cpp | 18 ++++++--- svf/lib/WPA/Andersen.cpp | 2 +- 23 files changed, 112 insertions(+), 145 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index 718a442e5..5aad56f0d 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -218,7 +218,7 @@ class LLVMModuleSet setValueAttr(func,svfFunc); } - void addFunctionMap(const Function* func, CallGraphNode* svfFunc); + void addFunctionMap(const Function* func, CallGraphNode* node); // create a SVFBasicBlock according to LLVM BasicBlock, then add it to SVFFunction's BasicBlockGraph inline void addBasicBlock(SVFFunction* fun, const BasicBlock* bb) @@ -366,6 +366,22 @@ class LLVMModuleSet return nullptr; } + inline const CallGraphNode* getFunctionNode(const std::string& name) + { + Function* fun = nullptr; + + for (u32_t i = 0; i < llvmModuleSet->getModuleNum(); ++i) + { + Module* mod = llvmModuleSet->getModule(i); + fun = mod->getFunction(name); + if (fun) + { + return llvmModuleSet->getCallGraphNode(fun); + } + } + return nullptr; + } + ICFGNode* getICFGNode(const Instruction* inst); bool hasICFGNode(const Instruction* inst); diff --git a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h index 50b5c6cf8..f5c38b45a 100644 --- a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +++ b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h @@ -234,7 +234,7 @@ class SVFIRBuilder: public llvm::InstVisitor //@{ virtual const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector &fields, const Value* szValue); virtual void addComplexConsForExt(Value *D, Value *S, const Value* sz); - virtual void handleExtCall(const CallBase* cs, const SVFFunction* svfCallee); + virtual void handleExtCall(const CallBase* cs, const CallGraphNode* svfCallee); //@} /// Set current basic block in order to keep track of control flow information diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index 3e9473369..a55ec0ade 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -283,8 +283,8 @@ void ICFGBuilder::addICFGInterEdges(const Instruction* cs, const Function* calle /// direct call if(callee) { - SVFFunction* svfFun = - llvmModuleSet()->getSVFFunction(callee); + CallGraphNode* svfFun = + llvmModuleSet()->getCallGraphNode(callee); /// if this is an external function (no function body) if (SVFUtil::isExtCall(svfFun)) { diff --git a/svf-llvm/lib/LLVMLoopAnalysis.cpp b/svf-llvm/lib/LLVMLoopAnalysis.cpp index c2a9d842e..4136bb481 100644 --- a/svf-llvm/lib/LLVMLoopAnalysis.cpp +++ b/svf-llvm/lib/LLVMLoopAnalysis.cpp @@ -54,7 +54,7 @@ void LLVMLoopAnalysis::buildLLVMLoops(SVFModule *mod, ICFG* icfg) for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F) { const Function* func = &*F; - const SVFFunction* svffun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(func); + const CallGraphNode* svffun = LLVMModuleSet::getLLVMModuleSet()->getCallGraphNode(func); if (func->isDeclaration()) continue; // do not analyze external call if (SVFUtil::isExtCall(svffun)) continue; diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 15143ee00..c945ea779 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -182,13 +182,6 @@ void LLVMModuleSet::build() createSVFDataStructure(); initSVFFunction(); - for (const auto& it : *callgraph) - { - SVFFunction* svffunc = const_cast(it.second->getFunction()); - svffunc->setCallGraphNode(it.second); - addFunctionMap(SVFUtil::cast(getLLVMValue(svffunc)), it.second); - } - callGraphBuilder.initVFIRCallGraph(callgraph); @@ -238,8 +231,8 @@ void LLVMModuleSet::createSVFDataStructure() // Store annotations of functions in extapi.bc for (const auto& pair : ExtFun2Annotations) { - const SVFFunction* svffun = getSVFFunction(pair.first); - ExtAPI::getExtAPI()->setExtFuncAnnotations(svffun, pair.second); + const CallGraphNode* funNode = getFunctionNode(pair.first); + ExtAPI::getExtAPI()->setExtFuncAnnotations(funNode, pair.second); } /// then traverse candidate sets @@ -282,12 +275,15 @@ void LLVMModuleSet::createSVFFunction(const Function* func) getSVFType(func->getFunctionType())), func->isDeclaration(), LLVMUtil::isIntrinsicFun(func), func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo); - CallGraphNode* callFunc = callgraph->addCallGraphNode(svfFunc); - BasicBlockGraph* bbGraph = new BasicBlockGraph(callFunc); + CallGraphNode* funcNode = callgraph->addCallGraphNode(svfFunc); + svfFunc->setCallGraphNode(funcNode); + BasicBlockGraph* bbGraph = new BasicBlockGraph(funcNode); svfFunc->setBasicBlockGraph(bbGraph); - svfModule->addFunctionSet(callFunc); + svfModule->addFunctionSet(funcNode); + addFunctionMap(func, funcNode); addFunctionMap(func, svfFunc); + for (const Argument& arg : func->args()) { SVFArgument* svfarg = new SVFArgument( @@ -337,7 +333,7 @@ void LLVMModuleSet::initSVFFunction() SVFFunction* svffun = getSVFFunction(&f); initSVFBasicBlock(&f); - if (!SVFUtil::isExtCall(svffun)) + if (!SVFUtil::isExtCall(svffun->getCallGraphNode())) { initDomTree(svffun, &f); } @@ -1292,10 +1288,10 @@ void LLVMModuleSet::dumpSymTable() SVFUtil::outs() << "}\n"; } -void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* svfFunc) +void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* node) { - LLVMFunc2CallGraphNode[func] = svfFunc; - addToSVFVar2LLVMValueMap(func, svfFunc); + LLVMFunc2CallGraphNode[func] = node; + addToSVFVar2LLVMValueMap(func, node); } void LLVMModuleSet::setValueAttr(const Value* val, SVFValue* svfvalue) diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index b6d695314..f07ed2be6 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -73,7 +73,7 @@ bool LLVMUtil::isObject(const Value* ref) */ void LLVMUtil::getFunReachableBBs (const Function* fun, std::vector &reachableBBs) { - assert(!SVFUtil::isExtCall(LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(fun)) && "The calling function cannot be an external function."); + assert(!SVFUtil::isExtCall(LLVMModuleSet::getLLVMModuleSet()->getCallGraphNode(fun)) && "The calling function cannot be an external function."); //initial DominatorTree DominatorTree& dt = LLVMModuleSet::getLLVMModuleSet()->getDomTree(fun); @@ -121,8 +121,8 @@ bool LLVMUtil::basicBlockHasRetInst(const BasicBlock* bb) */ bool LLVMUtil::functionDoesNotRet(const Function* fun) { - const SVFFunction* svffun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(fun); - if (SVFUtil::isExtCall(svffun)) + const CallGraphNode* cgn = LLVMModuleSet::getLLVMModuleSet()->getCallGraphNode(fun); + if (SVFUtil::isExtCall(cgn)) { return fun->getReturnType()->isVoidTy(); } @@ -623,8 +623,8 @@ bool LLVMUtil::isHeapAllocExtCallViaRet(const Instruction* inst) { const Function* fun = call->getCalledFunction(); return fun && isPtrTy && - (extApi->is_alloc(pSet->getSVFFunction(fun)) || - extApi->is_realloc(pSet->getSVFFunction(fun))); + (extApi->is_alloc(pSet->getCallGraphNode(fun)) || + extApi->is_realloc(pSet->getCallGraphNode(fun))); } else return false; @@ -637,7 +637,7 @@ bool LLVMUtil::isHeapAllocExtCallViaArg(const Instruction* inst) const Function* fun = call->getCalledFunction(); return fun && ExtAPI::getExtAPI()->is_arg_alloc( - LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(fun)); + LLVMModuleSet::getLLVMModuleSet()->getCallGraphNode(fun)); } else { @@ -654,7 +654,7 @@ bool LLVMUtil::isStackAllocExtCallViaRet(const Instruction *inst) { const Function* fun = call->getCalledFunction(); return fun && isPtrTy && - extApi->is_alloc_stack_ret(pSet->getSVFFunction(fun)); + extApi->is_alloc_stack_ret(pSet->getCallGraphNode(fun)); } else return false; diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 379665d7c..b167c7771 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -1010,10 +1010,10 @@ void SVFIRBuilder::visitCallSite(CallBase* cs) } if (const Function *callee = LLVMUtil::getCallee(cs)) { - const SVFFunction* svfcallee = llvmModuleSet()->getSVFFunction(callee); - if (isExtCall(svfcallee)) + const CallGraphNode* calleeNode = llvmModuleSet()->getCallGraphNode(callee); + if (isExtCall(calleeNode)) { - handleExtCall(cs, svfcallee); + handleExtCall(cs, calleeNode); } else { @@ -1337,7 +1337,7 @@ void SVFIRBuilder::updateCallGraph(PTACallGraph* callgraph) if (isExtCall(*func_iter)) { setCurrentLocation(callee, callee->empty() ? nullptr : &callee->getEntryBlock()); - const SVFFunction* svfcallee = llvmModuleSet()->getSVFFunction(callee); + const CallGraphNode* svfcallee = llvmModuleSet()->getCallGraphNode(callee); handleExtCall(callbase, svfcallee); } else diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index 26176c53a..79a0eca73 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -126,7 +126,7 @@ void SVFIRBuilder::addComplexConsForExt(Value *D, Value *S, const Value* szValue } } -void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCallee) +void SVFIRBuilder::handleExtCall(const CallBase* cs, const CallGraphNode* svfCallee) { const SVFInstruction* svfInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs); const SVFCallInst* svfCall = SVFUtil::cast(svfInst); diff --git a/svf-llvm/lib/SymbolTableBuilder.cpp b/svf-llvm/lib/SymbolTableBuilder.cpp index aa21aa1f9..c089e335c 100644 --- a/svf-llvm/lib/SymbolTableBuilder.cpp +++ b/svf-llvm/lib/SymbolTableBuilder.cpp @@ -607,7 +607,7 @@ const Type* SymbolTableBuilder::inferTypeOfHeapObjOrStaticObj(const Instruction else if(LLVMUtil::isHeapAllocExtCallViaArg(inst)) { const CallBase* cs = LLVMUtil::getLLVMCallSite(inst); - u32_t arg_pos = SVFUtil::getHeapAllocHoldingArgPosition(SVFUtil::cast(svfinst)->getCalledFunction()); + u32_t arg_pos = SVFUtil::getHeapAllocHoldingArgPosition(SVFUtil::cast(svfinst)->getCalledFunction()->getCallGraphNode()); const Value* arg = cs->getArgOperand(arg_pos); originalPType = SVFUtil::dyn_cast(arg->getType()); inferedType = inferObjType(startValue = arg); @@ -747,7 +747,7 @@ u32_t SymbolTableBuilder::analyzeHeapAllocByteSize(const Value* val) calledFunction); std::vector args; // Heap alloc functions have annoation like "AllocSize:Arg1" - for (std::string annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(svfFunction)) + for (std::string annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(svfFunction->getCallGraphNode())) { if (annotation.find("AllocSize:") != std::string::npos) { diff --git a/svf/include/Util/ExtAPI.h b/svf/include/Util/ExtAPI.h index d94862877..aa2b2731e 100644 --- a/svf/include/Util/ExtAPI.h +++ b/svf/include/Util/ExtAPI.h @@ -48,8 +48,8 @@ class ExtAPI static ExtAPI *extOp; - // Map SVFFunction to its annotations - Map> func2Annotations; + // Map CallGraphNode to its annotations + Map> func2Annotations; // extapi.bc file path static std::string extBcPath; @@ -69,44 +69,44 @@ class ExtAPI std::string getExtBcPath(); // Get the annotation of (F) - std::string getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation); + std::string getExtFuncAnnotation(const CallGraphNode* fun, const std::string& funcAnnotation); - const std::vector& getExtFuncAnnotations(const SVFFunction* fun); + const std::vector& getExtFuncAnnotations(const CallGraphNode* fun); // Does (F) have some annotation? - bool hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation); + bool hasExtFuncAnnotation(const CallGraphNode* fun, const std::string& funcAnnotation); // Does (F) have a static var X (unavailable to us) that its return points to? - bool has_static(const SVFFunction *F); + bool has_static(const CallGraphNode *F); // Does (F) have a memcpy_like operation? - bool is_memcpy(const SVFFunction *F); + bool is_memcpy(const CallGraphNode *F); // Does (F) have a memset_like operation? - bool is_memset(const SVFFunction *F); + bool is_memset(const CallGraphNode *F); // Does (F) allocate a new object and return it? - bool is_alloc(const SVFFunction *F); + bool is_alloc(const CallGraphNode *F); // Does (F) allocate a new object and assign it to one of its arguments? - bool is_arg_alloc(const SVFFunction *F); + bool is_arg_alloc(const CallGraphNode *F); // Does (F) allocate a new stack object and return it? - bool is_alloc_stack_ret(const SVFFunction *F); + bool is_alloc_stack_ret(const CallGraphNode *F); // Get the position of argument which holds the new object - s32_t get_alloc_arg_pos(const SVFFunction *F); + s32_t get_alloc_arg_pos(const CallGraphNode *F); // Does (F) reallocate a new object? - bool is_realloc(const SVFFunction *F); + bool is_realloc(const CallGraphNode *F); // Should (F) be considered "external" (either not defined in the program // or a user-defined version of a known alloc or no-op)? - bool is_ext(const SVFFunction *F); + bool is_ext(const CallGraphNode *F); private: // Set the annotation of (F) - void setExtFuncAnnotations(const SVFFunction* fun, const std::vector& funcAnnotations); + void setExtFuncAnnotations(const CallGraphNode* fun, const std::vector& funcAnnotations); }; } // End namespace SVF diff --git a/svf/include/Util/SVFUtil.h b/svf/include/Util/SVFUtil.h index d83a56c9d..70cd7b574 100644 --- a/svf/include/Util/SVFUtil.h +++ b/svf/include/Util/SVFUtil.h @@ -266,19 +266,15 @@ void stopAnalysisLimitTimer(bool limitTimerSet); /// Return true if the call is an external call (external library in function summary table) /// If the library function is redefined in the application code (e.g., memcpy), it will return false and will not be treated as an external call. //@{ -inline bool isExtCall(const SVFFunction* fun) -{ - return fun && ExtAPI::getExtAPI()->is_ext(fun); -} bool isExtCall(const CallGraphNode* fun); -inline bool isMemcpyExtFun(const SVFFunction* fun) +inline bool isMemcpyExtFun(const CallGraphNode* fun) { return fun && ExtAPI::getExtAPI()->is_memcpy(fun); } -inline bool isMemsetExtFun(const SVFFunction* fun) +inline bool isMemsetExtFun(const CallGraphNode* fun) { return fun && ExtAPI::getExtAPI()->is_memset(fun); } @@ -286,20 +282,20 @@ inline bool isMemsetExtFun(const SVFFunction* fun) /// Return true if the call is a heap allocator/reallocator //@{ /// note that these two functions are not suppose to be used externally -inline bool isHeapAllocExtFunViaRet(const SVFFunction* fun) +inline bool isHeapAllocExtFunViaRet(const CallGraphNode* fun) { return fun && (ExtAPI::getExtAPI()->is_alloc(fun) || ExtAPI::getExtAPI()->is_realloc(fun)); } -inline bool isHeapAllocExtFunViaArg(const SVFFunction* fun) +inline bool isHeapAllocExtFunViaArg(const CallGraphNode* fun) { return fun && ExtAPI::getExtAPI()->is_arg_alloc(fun); } /// Get the position of argument that holds an allocated heap object. //@{ -inline u32_t getHeapAllocHoldingArgPosition(const SVFFunction* fun) +inline u32_t getHeapAllocHoldingArgPosition(const CallGraphNode* fun) { return ExtAPI::getExtAPI()->get_alloc_arg_pos(fun); } @@ -307,7 +303,7 @@ inline u32_t getHeapAllocHoldingArgPosition(const SVFFunction* fun) /// Return true if the call is a heap reallocator //@{ /// note that this function is not suppose to be used externally -inline bool isReallocExtFun(const SVFFunction* fun) +inline bool isReallocExtFun(const CallGraphNode* fun) { return fun && (ExtAPI::getExtAPI()->is_realloc(fun)); } @@ -315,10 +311,7 @@ inline bool isReallocExtFun(const SVFFunction* fun) /// Program entry function e.g. main //@{ /// Return true if this is a program entry function (e.g. main) -inline bool isProgEntryFunction(const SVFFunction* fun) -{ - return fun && fun->getName() == "main"; -} +bool isProgEntryFunction(const CallGraphNode* fun); /// Get program entry function from function name. const CallGraphNode* getProgFunction(const std::string& funName); diff --git a/svf/lib/AE/Svfexe/AEDetector.cpp b/svf/lib/AE/Svfexe/AEDetector.cpp index e4393ec4e..cdef7b957 100644 --- a/svf/lib/AE/Svfexe/AEDetector.cpp +++ b/svf/lib/AE/Svfexe/AEDetector.cpp @@ -225,7 +225,7 @@ void BufOverflowDetector::detectExtAPI(AbstractState& as, AbsExtAPI::ExtAPIType extType = AbsExtAPI::UNCLASSIFIED; // Determine the type of external memory API - for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction()->getFunction())) + for (const std::string &annotation : ExtAPI::getExtAPI()->getExtFuncAnnotations(call->getCalledFunction())) { if (annotation.find("MEMCPY") != std::string::npos) extType = AbsExtAPI::MEMCPY; diff --git a/svf/lib/AE/Svfexe/AbsExtAPI.cpp b/svf/lib/AE/Svfexe/AbsExtAPI.cpp index ae02d3b9f..1c3ab9789 100644 --- a/svf/lib/AE/Svfexe/AbsExtAPI.cpp +++ b/svf/lib/AE/Svfexe/AbsExtAPI.cpp @@ -389,10 +389,9 @@ void AbsExtAPI::handleExtAPI(const CallICFGNode *call) AbstractState& as = getAbsStateFromTrace(call); const CallGraphNode *cgNode = call->getCalledFunction(); assert(cgNode && "CallGraphNode* is nullptr"); - const SVFFunction *fun = cgNode->getFunction(); ExtAPIType extType = UNCLASSIFIED; // get type of mem api - for (const std::string &annotation: ExtAPI::getExtAPI()->getExtFuncAnnotations(fun)) + for (const std::string &annotation: ExtAPI::getExtAPI()->getExtFuncAnnotations(cgNode)) { if (annotation.find("MEMCPY") != std::string::npos) extType = MEMCPY; @@ -405,9 +404,9 @@ void AbsExtAPI::handleExtAPI(const CallICFGNode *call) } if (extType == UNCLASSIFIED) { - if (func_map.find(fun->getName()) != func_map.end()) + if (func_map.find(cgNode->getName()) != func_map.end()) { - func_map[fun->getName()](call); + func_map[cgNode->getName()](call); } else { diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index 6f13d1f5e..647d39472 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -566,7 +566,7 @@ void AbstractInterpretation::handleCallSite(const ICFGNode* node) bool AbstractInterpretation::isExtCall(const SVF::CallICFGNode *callNode) { if (callNode->getCalledFunction()) - return SVFUtil::isExtCall(callNode->getCalledFunction()->getFunction()); + return SVFUtil::isExtCall(callNode->getCalledFunction()); else return false; } diff --git a/svf/lib/CFL/CFLAlias.cpp b/svf/lib/CFL/CFLAlias.cpp index 0645664fc..33159b42b 100644 --- a/svf/lib/CFL/CFLAlias.cpp +++ b/svf/lib/CFL/CFLAlias.cpp @@ -69,7 +69,7 @@ void CFLAlias::connectCaller2CalleeParams(const CallICFGNode* cs, const CallGrap const CallICFGNode* callBlockNode = cs; const RetICFGNode* retBlockNode = cs->getRetICFGNode(); - if(SVFUtil::isHeapAllocExtFunViaRet(F->getFunction()) && svfir->callsiteHasRet(retBlockNode)) + if(SVFUtil::isHeapAllocExtFunViaRet(F) && svfir->callsiteHasRet(retBlockNode)) { heapAllocatorViaIndCall(cs); } diff --git a/svf/lib/DDA/FlowDDA.cpp b/svf/lib/DDA/FlowDDA.cpp index feba0d6e2..7d2e868a4 100644 --- a/svf/lib/DDA/FlowDDA.cpp +++ b/svf/lib/DDA/FlowDDA.cpp @@ -102,36 +102,6 @@ bool FlowDDA::testIndCallReachability(LocDPItem&, const CallGraphNode* callee, C bool FlowDDA::handleBKCondition(LocDPItem& dpm, const SVFGEdge* edge) { _client->handleStatement(edge->getSrcNode(), dpm.getCurNodeID()); -// CallSiteID csId = 0; -// -// if (edge->isCallVFGEdge()) { -// /// we don't handle context in recursions, they treated as assignments -// if (const CallDirSVFGEdge* callEdge = SVFUtil::dyn_cast(edge)) -// csId = callEdge->getCallSiteId(); -// else -// csId = SVFUtil::cast(edge)->getCallSiteId(); -// -// const SVFFunction* callee = edge->getDstNode()->getBB()->getParent(); -// if(testIndCallReachability(dpm,callee,csId)==false){ -// return false; -// } -// -// } -// -// else if (edge->isRetVFGEdge()) { -// /// we don't handle context in recursions, they treated as assignments -// if (const RetDirSVFGEdge* retEdge = SVFUtil::dyn_cast(edge)) -// csId = retEdge->getCallSiteId(); -// else -// csId = SVFUtil::cast(edge)->getCallSiteId(); -// -// const SVFFunction* callee = edge->getSrcNode()->getBB()->getParent(); -// if(testIndCallReachability(dpm,callee,csId)==false){ -// return false; -// } -// -// } - return true; } @@ -179,18 +149,6 @@ bool FlowDDA::isHeapCondMemObj(const NodeID& var, const StoreSVFGNode*) const BaseObjVar* pVar = _pag->getBaseObject(getPtrNodeID(var)); if(pVar && SVFUtil::isa(pVar)) { -// if(const Instruction* mallocSite = SVFUtil::dyn_cast(mem->getValue())) { -// const SVFFunction* fun = mallocSite->getParent()->getParent(); -// const SVFFunction* curFun = store->getBB() ? store->getBB()->getParent() : nullptr; -// if(fun!=curFun) -// return true; -// if(_callGraphSCC->isInCycle(_callGraph->getCallGraphNode(fun)->getId())) -// return true; -// if(_pag->getICFG()->isInLoop(mallocSite)) -// return true; -// -// return false; -// } return true; } return false; diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index 509f08458..a07116493 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -209,8 +209,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits static std::string getNodeAttributes(CallGraphNode*node, CallGraph*) { - const SVFFunction* fun = node->getFunction(); - if (!SVFUtil::isExtCall(fun)) + if (!SVFUtil::isExtCall(node)) { return "shape=box"; } diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index 4df3885d6..b626841bf 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -91,7 +91,7 @@ bool PTACallGraphNode::isReachableFromProgEntry() const PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (SVFUtil::isProgEntryFunction(node->getCallNode()->getFunction())) + if (SVFUtil::isProgEntryFunction(node->getCallNode())) return true; for (const_iterator it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) @@ -369,7 +369,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits static std::string getNodeAttributes(PTACallGraphNode*node, PTACallGraph*) { - const SVFFunction* fun = node->getCallNode()->getFunction(); + const CallGraphNode* fun = node->getCallNode(); if (!SVFUtil::isExtCall(fun)) { return "shape=box"; diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 3e84b4796..2c9ed9ec2 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -128,11 +128,11 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) PTACallGraphNode* caller = getPTACallGraphNode(cs->getCaller()); - const SVFFunction* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) - ->getCallGraphNode()->getFunction(); + const CallGraphNode* forkee = SVFUtil::dyn_cast(tdAPI->getForkedFun(cs)) + ->getCallGraphNode(); assert(forkee && "callee does not exist"); PTACallGraphNode* callee = getPTACallGraphNode( - forkee->getDefFunForMultipleModule()->getCallGraphNode()); + forkee->getDefFunForMultipleModule()); CallSiteID csId = addCallSite(cs, callee->getCallNode()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) diff --git a/svf/lib/MTA/MTAStat.cpp b/svf/lib/MTA/MTAStat.cpp index 3256b387f..811e705be 100644 --- a/svf/lib/MTA/MTAStat.cpp +++ b/svf/lib/MTA/MTAStat.cpp @@ -124,7 +124,7 @@ void MTAStat::performMHPPairStat(MHP* mhp, LockAnalysis* lsa) continue; if(!mhp->isConnectedfromMain(fun)) continue; - for (SVFFunction::const_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit) + for (CallGraphNode::const_bb_iterator bit = fun->begin(), ebit = fun->end(); bit != ebit; ++bit) { const SVFBasicBlock* bb = bit->second; for (const auto& icfgNode : bb->getICFGNodeList()) diff --git a/svf/lib/Util/ExtAPI.cpp b/svf/lib/Util/ExtAPI.cpp index 8bd009372..8679377ae 100644 --- a/svf/lib/Util/ExtAPI.cpp +++ b/svf/lib/Util/ExtAPI.cpp @@ -161,15 +161,15 @@ std::string ExtAPI::getExtBcPath() abort(); } -void ExtAPI::setExtFuncAnnotations(const SVFFunction* fun, const std::vector& funcAnnotations) +void ExtAPI::setExtFuncAnnotations(const CallGraphNode* fun, const std::vector& funcAnnotations) { - assert(fun && "Null SVFFunction* pointer"); + assert(fun && "Null CallGraphNode* pointer"); func2Annotations[fun] = funcAnnotations; } -bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation) +bool ExtAPI::hasExtFuncAnnotation(const CallGraphNode* fun, const std::string& funcAnnotation) { - assert(fun && "Null SVFFunction* pointer"); + assert(fun && "Null CallGraphNode* pointer"); auto it = func2Annotations.find(fun); if (it != func2Annotations.end()) { @@ -180,9 +180,9 @@ bool ExtAPI::hasExtFuncAnnotation(const SVFFunction* fun, const std::string& fun return false; } -std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::string& funcAnnotation) +std::string ExtAPI::getExtFuncAnnotation(const CallGraphNode* fun, const std::string& funcAnnotation) { - assert(fun && "Null SVFFunction* pointer"); + assert(fun && "Null CallGraphNode* pointer"); auto it = func2Annotations.find(fun); if (it != func2Annotations.end()) { @@ -193,45 +193,45 @@ std::string ExtAPI::getExtFuncAnnotation(const SVFFunction* fun, const std::stri return ""; } -const std::vector& ExtAPI::getExtFuncAnnotations(const SVFFunction* fun) +const std::vector& ExtAPI::getExtFuncAnnotations(const CallGraphNode* fun) { - assert(fun && "Null SVFFunction* pointer"); + assert(fun && "Null CallGraphNode* pointer"); auto it = func2Annotations.find(fun); if (it != func2Annotations.end()) return it->second; return func2Annotations[fun]; } -bool ExtAPI::is_memcpy(const SVFFunction *F) +bool ExtAPI::is_memcpy(const CallGraphNode *F) { return F && (hasExtFuncAnnotation(F, "MEMCPY") || hasExtFuncAnnotation(F, "STRCPY") || hasExtFuncAnnotation(F, "STRCAT")); } -bool ExtAPI::is_memset(const SVFFunction *F) +bool ExtAPI::is_memset(const CallGraphNode *F) { return F && hasExtFuncAnnotation(F, "MEMSET"); } -bool ExtAPI::is_alloc(const SVFFunction* F) +bool ExtAPI::is_alloc(const CallGraphNode* F) { return F && hasExtFuncAnnotation(F, "ALLOC_HEAP_RET"); } // Does (F) allocate a new object and assign it to one of its arguments? -bool ExtAPI::is_arg_alloc(const SVFFunction* F) +bool ExtAPI::is_arg_alloc(const CallGraphNode* F) { return F && hasExtFuncAnnotation(F, "ALLOC_HEAP_ARG"); } -bool ExtAPI::is_alloc_stack_ret(const SVFFunction* F) +bool ExtAPI::is_alloc_stack_ret(const CallGraphNode* F) { return F && hasExtFuncAnnotation(F, "ALLOC_STACK_RET"); } // Get the position of argument which holds the new object -s32_t ExtAPI::get_alloc_arg_pos(const SVFFunction* F) +s32_t ExtAPI::get_alloc_arg_pos(const CallGraphNode* F) { std::string allocArg = getExtFuncAnnotation(F, "ALLOC_HEAP_ARG"); assert(!allocArg.empty() && "Not an alloc call via argument or incorrect extern function annotation!"); @@ -247,7 +247,7 @@ s32_t ExtAPI::get_alloc_arg_pos(const SVFFunction* F) } // Does (F) reallocate a new object? -bool ExtAPI::is_realloc(const SVFFunction* F) +bool ExtAPI::is_realloc(const CallGraphNode* F) { return F && hasExtFuncAnnotation(F, "REALLOC_HEAP_RET"); } @@ -255,9 +255,9 @@ bool ExtAPI::is_realloc(const SVFFunction* F) // Should (F) be considered "external" (either not defined in the program // or a user-defined version of a known alloc or no-op)? -bool ExtAPI::is_ext(const SVFFunction* F) +bool ExtAPI::is_ext(const CallGraphNode* F) { - assert(F && "Null SVFFunction* pointer"); + assert(F && "Null CallGraphNode* pointer"); if (F->isDeclaration() || F->isIntrinsic()) return true; else if (hasExtFuncAnnotation(F, "OVERWRITE") && getExtFuncAnnotations(F).size() == 1) diff --git a/svf/lib/Util/SVFUtil.cpp b/svf/lib/Util/SVFUtil.cpp index 91a2b2a0a..007efc46b 100644 --- a/svf/lib/Util/SVFUtil.cpp +++ b/svf/lib/Util/SVFUtil.cpp @@ -338,7 +338,7 @@ bool SVFUtil::isExtCall(const CallICFGNode* cs) bool SVFUtil::isHeapAllocExtCallViaArg(const CallICFGNode* cs) { if (cs->getCalledFunction()) - return isHeapAllocExtFunViaArg(cs->getCalledFunction()->getFunction()); + return isHeapAllocExtFunViaArg(cs->getCalledFunction()); else return false; } @@ -346,7 +346,7 @@ bool SVFUtil::isHeapAllocExtCallViaArg(const CallICFGNode* cs) u32_t SVFUtil::getHeapAllocHoldingArgPosition(const CallICFGNode* cs) { - return getHeapAllocHoldingArgPosition(cs->getCalledFunction()->getFunction()); + return getHeapAllocHoldingArgPosition(cs->getCalledFunction()); } @@ -366,13 +366,13 @@ bool SVFUtil::isHeapAllocExtCallViaRet(const CallICFGNode* cs) { bool isPtrTy = cs->getType()->isPointerTy(); const CallGraphNode* fun = cs->getCalledFunction(); - return fun && isPtrTy && isHeapAllocExtFunViaRet(fun->getFunction()); + return fun && isPtrTy && isHeapAllocExtFunViaRet(fun); } bool SVFUtil::isReallocExtCall(const CallICFGNode* cs) { bool isPtrTy = cs->getType()->isPointerTy(); - return isPtrTy && isReallocExtFun(cs->getCalledFunction()->getFunction()); + return isPtrTy && isReallocExtFun(cs->getCalledFunction()); } @@ -389,6 +389,12 @@ bool SVFUtil::isProgExitCall(const CallICFGNode* cs) return isProgExitFunction(cs->getCalledFunction()); } +/// Return true if this is a program entry function (e.g. main) +bool SVFUtil::isProgEntryFunction(const CallGraphNode* fun) +{ + return fun && fun->getName() == "main"; +} + /// Get program entry function from module. const CallGraphNode* SVFUtil::getProgFunction(const std::string& funName) { @@ -409,7 +415,7 @@ const CallGraphNode* SVFUtil::getProgEntryFunction() for (const auto& item: *svfirCallGraph) { const CallGraphNode*fun = item.second; - if (isProgEntryFunction(fun->getFunction())) + if (isProgEntryFunction(fun)) return fun; } return nullptr; @@ -432,7 +438,7 @@ const ObjVar* SVFUtil::getObjVarOfValVar(const SVF::ValVar* valVar) bool SVFUtil::isExtCall(const CallGraphNode* fun) { - return fun && ExtAPI::getExtAPI()->is_ext(fun->getFunction()); + return fun && ExtAPI::getExtAPI()->is_ext(fun); } bool SVFUtil::isProgExitFunction (const CallGraphNode * fun) diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index 090a0db05..ce4224440 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -282,7 +282,7 @@ void AndersenBase::connectCaller2CalleeParams(const CallICFGNode* cs, const CallICFGNode* callBlockNode = cs; const RetICFGNode* retBlockNode = cs->getRetICFGNode(); - if(SVFUtil::isHeapAllocExtFunViaRet(F->getFunction()) && pag->callsiteHasRet(retBlockNode)) + if(SVFUtil::isHeapAllocExtFunViaRet(F) && pag->callsiteHasRet(retBlockNode)) { heapAllocatorViaIndCall(cs,cpySrcNodes); } From c22415beeb51a4105ff36074dfcb9896bbdb6533 Mon Sep 17 00:00:00 2001 From: hwg Date: Sat, 1 Feb 2025 22:08:13 +1100 Subject: [PATCH 39/45] rm SVFFunction* getFunction() in CallGraphNode --- svf-llvm/lib/SVFIRBuilder.cpp | 2 +- svf-llvm/lib/SVFIRExtAPI.cpp | 4 ++-- svf/include/Graphs/CallGraph.h | 8 +------- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 2 +- svf/lib/Graphs/CallGraph.cpp | 2 +- svf/lib/SVFIR/SVFVariables.cpp | 4 ++-- svf/lib/Util/CallGraphBuilder.cpp | 6 +++--- 7 files changed, 11 insertions(+), 17 deletions(-) diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index b167c7771..566462c1b 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -290,7 +290,7 @@ void SVFIRBuilder::initialiseNodes() // Check if the value is a function and add a function object node if (const Function* func = SVFUtil::dyn_cast(llvmValue)) { - NodeID id = llvmModuleSet()->getObjectNode(llvmModuleSet()->getCallGraphNode(func)->getFunction()); + NodeID id = llvmModuleSet()->getObjectNode(llvmModuleSet()->getSVFValue(func)); pag->addFunObjNode(iter->second, pag->getObjTypeInfo(id), llvmModuleSet()->getCallGraphNode(func), iter->first->getType(), icfgNode); } // Check if the value is a heap object and add a heap object node diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index 79a0eca73..9f4a42312 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -264,7 +264,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const CallGraphNode* svfCal const ValVar* valVar = getForkedFun(callICFGNode); if (const FunValVar* funcValVar = SVFUtil::dyn_cast(valVar)) { - const SVFFunction* forkedFun = funcValVar->getCallGraphNode()->getFunction() + const CallGraphNode* forkedFun = funcValVar->getCallGraphNode() ->getDefFunForMultipleModule(); const SVFVar* actualParm = getActualParmAtForkSite(callICFGNode); /// pthread_create has 1 arg. @@ -276,7 +276,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const CallGraphNode* svfCal /// Connect actual parameter to formal parameter of the start routine if (actualParm->isPointer() && formalParm->getType()->isPointerTy()) { - FunEntryICFGNode *entry = pag->getICFG()->getFunEntryICFGNode(forkedFun->getCallGraphNode()); + FunEntryICFGNode *entry = pag->getICFG()->getFunEntryICFGNode(forkedFun); addThreadForkEdge(actualParm->getId(), llvmModuleSet()->getValueNode(formalParm), callICFGNode, entry); } } diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index d5f678b96..24468e0b2 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -337,13 +337,7 @@ class CallGraphNode : public GenericCallGraphNodeTy inline const std::string &getName() const { - return fun->getName(); - } - - /// Get function of this call node - inline const SVFFunction* getFunction() const - { - return fun; + return name; } diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index 647d39472..474546e10 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -92,7 +92,7 @@ void AbstractInterpretation::initWTO() // Check if the current function is part of a cycle if (callGraphScc->isInCycle(it->second->getId())) recursiveFuns.insert(it->second); // Mark the function as recursive - if (it->second->getFunction()->isDeclaration()) + if (it->second->isDeclaration()) continue; auto* wto = new ICFGWTO(icfg, icfg->getFunEntryICFGNode(it->second)); wto->init(); diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index a07116493..df978b7d8 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -92,7 +92,7 @@ const std::string CallGraphNode::toString() const { std::string str; std::stringstream rawstr(str); - rawstr << "CallGraphNode ID: " << getId() << " {fun: " << fun->getName() << "}"; + rawstr << "CallGraphNode ID: " << getId() << " {fun: " << getName() << "}"; return rawstr.str(); } diff --git a/svf/lib/SVFIR/SVFVariables.cpp b/svf/lib/SVFIR/SVFVariables.cpp index f6d537a79..cad318745 100644 --- a/svf/lib/SVFIR/SVFVariables.cpp +++ b/svf/lib/SVFIR/SVFVariables.cpp @@ -134,7 +134,7 @@ const CallGraphNode* ArgValVar::getParent() const bool ArgValVar::isPointer() const { - return cgNode->getFunction()->getArg(argNo)->getType()->isPointerTy(); + return cgNode->getArg(argNo)->getType()->isPointerTy(); } const std::string ArgValVar::toString() const @@ -446,7 +446,7 @@ bool FunObjVar::isPointer() const bool FunObjVar::isIsolatedNode() const { - return callGraphNode->getFunction()->isIntrinsic(); + return callGraphNode->isIntrinsic(); } const CallGraphNode* FunObjVar::getFunction() const diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 36ce556b9..e3d8c4bc3 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -56,7 +56,7 @@ void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) { for (const auto& item : *callgraph) { - for (auto it : *(item.second)->getFunction()) + for (auto it : *(item.second)) { const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* inst : svfbb->getICFGNodeList()) @@ -90,7 +90,7 @@ ThreadCallGraph* CallGraphBuilder::buildThreadCallGraph() ThreadAPI* tdAPI = ThreadAPI::getThreadAPI(); for (const auto& item: *svfirCallGraph) { - for (auto it : *(item.second)->getFunction()) + for (auto it : *(item.second)) { const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* inst : svfbb->getICFGNodeList()) @@ -116,7 +116,7 @@ ThreadCallGraph* CallGraphBuilder::buildThreadCallGraph() // record join sites for (const auto& item: *svfirCallGraph) { - for (auto it : *(item.second)->getFunction()) + for (auto it : *(item.second)) { const SVFBasicBlock* svfbb = it.second; for (const ICFGNode* node : svfbb->getICFGNodeList()) From 1675748926a82300ed872a67686c9e7dcd76b028 Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 01:39:38 +1100 Subject: [PATCH 40/45] rm const SVFFunction* fun; in CallGraphNode --- svf-llvm/include/SVF-LLVM/LLVMModule.h | 4 +- svf-llvm/lib/LLVMModule.cpp | 29 ++++++++++++-- svf/include/Graphs/CallGraph.h | 18 +++++---- svf/include/Util/CallGraphBuilder.h | 2 - svf/lib/Graphs/CallGraph.cpp | 53 +++++++++++++------------- svf/lib/Util/CallGraphBuilder.cpp | 9 ----- 6 files changed, 65 insertions(+), 50 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/LLVMModule.h b/svf-llvm/include/SVF-LLVM/LLVMModule.h index 5aad56f0d..98f046729 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMModule.h +++ b/svf-llvm/include/SVF-LLVM/LLVMModule.h @@ -50,10 +50,9 @@ class LLVMModuleSet public: typedef std::vector FunctionSetType; - typedef Map FunDeclToDefMapTy; - typedef Map FunDefToDeclsMapTy; typedef Map GlobalDefToRepMapTy; + typedef Map CGN2SVFFunMap; typedef Map LLVMFun2SVFFunMap; typedef Map LLVMFun2CallGraphNodeMap; typedef Map LLVMBB2SVFBBMap; @@ -113,6 +112,7 @@ class LLVMModuleSet FunToFunEntryNodeMapTy FunToFunEntryNodeMap; ///< map a function to its FunExitICFGNode FunToFunExitNodeMapTy FunToFunExitNodeMap; ///< map a function to its FunEntryICFGNode CallGraph* callgraph; + CGN2SVFFunMap CallGraphNode2SVFFunMap; Map FunToDominatorTree; diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index c945ea779..f9ef52e6f 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -182,13 +182,31 @@ void LLVMModuleSet::build() createSVFDataStructure(); initSVFFunction(); - callGraphBuilder.initVFIRCallGraph(callgraph); - + // iterate over CallGraphNode2SVFFunMap + for (auto& item : CallGraphNode2SVFFunMap) + { + CallGraphNode* callNode = const_cast(item.first); + SVFFunction* fun = item.second; + callNode->init(fun->getFunctionType(), + fun->isUncalledFunction(), + !(fun->hasReturn()), + fun->isDeclaration(), + fun->isIntrinsic(), + fun->hasAddressTaken(), + fun->isVarArg(), + fun->getLoopAndDomInfo(), + const_cast(fun->getDefFunForMultipleModule()->getCallGraphNode()), + const_cast(fun->getBasicBlockGraph()), + fun->getArgsList(), + fun->hasBasicBlock()? const_cast(fun->getExitBB()) : nullptr + ); + } ICFGBuilder icfgbuilder; icfg = icfgbuilder.build(); + callGraphBuilder.connectSVFIRCallGraphEdge(callgraph); @@ -275,13 +293,18 @@ void LLVMModuleSet::createSVFFunction(const Function* func) getSVFType(func->getFunctionType())), func->isDeclaration(), LLVMUtil::isIntrinsicFun(func), func->hasAddressTaken(), func->isVarArg(), new SVFLoopAndDomInfo); - CallGraphNode* funcNode = callgraph->addCallGraphNode(svfFunc); + CallGraphNode* funcNode = callgraph->addCallGraphNode(getSVFType(func->getType()), + SVFUtil::cast( + getSVFType(func->getFunctionType())), + func->isDeclaration(), LLVMUtil::isIntrinsicFun(func), + func->hasAddressTaken(), func->isVarArg(), nullptr); svfFunc->setCallGraphNode(funcNode); BasicBlockGraph* bbGraph = new BasicBlockGraph(funcNode); svfFunc->setBasicBlockGraph(bbGraph); svfModule->addFunctionSet(funcNode); addFunctionMap(func, funcNode); addFunctionMap(func, svfFunc); + CallGraphNode2SVFFunMap[funcNode] = svfFunc; for (const Argument& arg : func->args()) diff --git a/svf/include/Graphs/CallGraph.h b/svf/include/Graphs/CallGraph.h index 24468e0b2..63be7dad7 100644 --- a/svf/include/Graphs/CallGraph.h +++ b/svf/include/Graphs/CallGraph.h @@ -126,29 +126,31 @@ class CallGraphNode : public GenericCallGraphNodeTy private: - const SVFFunction* fun; bool isDecl; /// return true if this function does not have a body bool intrinsic; /// return true if this function is an intrinsic function (e.g., llvm.dbg), which does not reside in the application code bool addrTaken; /// return true if this function is address-taken (for indirect call purposes) bool isUncalled; /// return true if this function is never called bool isNotRet; /// return true if this function never returns bool varArg; /// return true if this function supports variable arguments - const SVFFunctionType* funcType; /// FunctionType, which is different from the type (PointerType) of this SVFFunction + const SVFFunctionType* funcType; /// FunctionType, which is different from the type (PointerType) of this SVF Function SVFLoopAndDomInfo* loopAndDom; /// the loop and dominate information const CallGraphNode * realDefFun{nullptr}; /// the definition of a function across multiple modules BasicBlockGraph* bbGraph; /// the basic block graph of this function std::vector allArgs; /// all formal arguments of this function - const SVFBasicBlock *exitBlock{nullptr}; /// a 'single' basic block having no successors and containing return instruction in a function + SVFBasicBlock *exitBlock{nullptr}; /// a 'single' basic block having no successors and containing return instruction in a function public: /// Constructor - CallGraphNode(NodeID i, const SVFFunction* f); + CallGraphNode(NodeID i, const SVFType* ty, + const SVFFunctionType* ft, bool declare, bool intrinsic, + bool addrTaken, bool varg, SVFLoopAndDomInfo* ld); ~CallGraphNode(){ - delete fun; } - void init(); + void init(const SVFFunctionType* ft, bool uncalled, bool notRet, bool declare, bool intr, bool adt, + bool varg, SVFLoopAndDomInfo* ld, CallGraphNode* cgn, BasicBlockGraph* bbG, + std::vector allArg, SVFBasicBlock* eBb); inline bool isDeclaration() const { @@ -402,7 +404,9 @@ class CallGraph : public GenericCallGraphTy /// Constructor CallGraph(); - CallGraphNode* addCallGraphNode(const SVFFunction* fun); + CallGraphNode* addCallGraphNode( const SVFType* ty, + const SVFFunctionType* ft, bool declare, bool intrinsic, + bool addrTaken, bool varg, SVFLoopAndDomInfo* ld); const CallGraphNode* getCallGraphNode(const std::string& name); diff --git a/svf/include/Util/CallGraphBuilder.h b/svf/include/Util/CallGraphBuilder.h index 961486d80..921532f4b 100644 --- a/svf/include/Util/CallGraphBuilder.h +++ b/svf/include/Util/CallGraphBuilder.h @@ -49,8 +49,6 @@ class CallGraphBuilder /// Buidl SVFIR callgraoh CallGraph* createSVFIRCallGraph(SVFModule* svfModule); - CallGraph* initVFIRCallGraph(CallGraph* callgraph); - void connectSVFIRCallGraphEdge(CallGraph* callGraph); /// Buidl PTA callgraoh diff --git a/svf/lib/Graphs/CallGraph.cpp b/svf/lib/Graphs/CallGraph.cpp index df978b7d8..aa712c8fa 100644 --- a/svf/lib/Graphs/CallGraph.cpp +++ b/svf/lib/Graphs/CallGraph.cpp @@ -57,37 +57,34 @@ const std::string CallGraphEdge::toString() const return rawstr.str(); } -CallGraphNode::CallGraphNode(NodeID i, const SVFFunction* f): GenericCallGraphNodeTy(i,CallNodeKd, f->getType()), fun(f) + +void CallGraphNode::init(const SVFFunctionType* ft, bool uncalled, bool notRet, bool declare, bool intr, bool adt, + bool varg, SVFLoopAndDomInfo* ld, CallGraphNode* cgn, BasicBlockGraph* bbG, std::vector allArg, SVFBasicBlock* eBb) { - isUncalled = f->isUncalledFunction(); - isNotRet = !(f->hasReturn()); - isDecl = f->isDeclaration(); - intrinsic = f->isIntrinsic(); - addrTaken = f->hasAddressTaken(); - varArg = f->isVarArg(); - funcType = f->getFunctionType(); - loopAndDom = f->getLoopAndDomInfo(); + this->isUncalled = uncalled; + this->isNotRet = notRet; + this->isDecl = declare; + this->intrinsic = intr; + this->addrTaken =adt; + this->varArg = varg; + this->funcType = ft; + this->loopAndDom = ld; + this->realDefFun = cgn; + this->bbGraph = bbG; + this->allArgs = allArg; + this->exitBlock = eBb; } -void CallGraphNode::init() +CallGraphNode::CallGraphNode(NodeID i, + const SVFType* ty, const SVFFunctionType* ft, + bool declare, bool intrinsic, bool adt, + bool varg, SVFLoopAndDomInfo* ld) + : GenericNode(i,CallNodeKd,ty),isDecl(declare), intrinsic(intrinsic), + addrTaken(adt), isUncalled(false), isNotRet(false), varArg(varg), + funcType(ft), loopAndDom(ld), realDefFun(nullptr), exitBlock(nullptr) { - isUncalled = fun->isUncalledFunction(); - isNotRet = !(fun->hasReturn()); - isDecl = fun->isDeclaration(); - intrinsic = fun->isIntrinsic(); - addrTaken = fun->hasAddressTaken(); - varArg = fun->isVarArg(); - funcType = fun->getFunctionType(); - loopAndDom = fun->getLoopAndDomInfo(); - realDefFun = fun->getDefFunForMultipleModule()->getCallGraphNode(); - bbGraph = const_cast(fun->getBasicBlockGraph()); - allArgs = fun->getArgsList(); - if (fun->hasBasicBlock()) - exitBlock = fun->getExitBB(); } - - const std::string CallGraphNode::toString() const { std::string str; @@ -114,10 +111,12 @@ void CallGraph::destroy() /*! * Add call graph node */ -CallGraphNode* CallGraph::addCallGraphNode(const SVFFunction* fun) +CallGraphNode* CallGraph::addCallGraphNode(const SVFType* ty, const SVFFunctionType* ft, + bool declare, bool intrinsic, bool adt, + bool varg, SVFLoopAndDomInfo* ld) { NodeID id = callGraphNodeNum; - CallGraphNode *callGraphNode = new CallGraphNode(id, fun); + CallGraphNode *callGraphNode = new CallGraphNode(id, ty, ft, declare, intrinsic, adt, varg, ld); addGNode(id, callGraphNode); callGraphNodeNum++; return callGraphNode; diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index e3d8c4bc3..5c5ae7080 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -43,15 +43,6 @@ CallGraph* CallGraphBuilder::createSVFIRCallGraph(SVFModule* svfModule) return new CallGraph(); } -CallGraph* CallGraphBuilder::initVFIRCallGraph(CallGraph* callgraph) -{ - for (const auto& item : *callgraph) - { - (item.second)->init(); - } - return callgraph; -} - void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) { for (const auto& item : *callgraph) From b741107b8fe094bc745d149ff9c82216c9606120 Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 02:09:52 +1100 Subject: [PATCH 41/45] fix --- svf-llvm/lib/LLVMModule.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index f9ef52e6f..1a4a78d57 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -90,6 +90,11 @@ LLVMModuleSet::~LLVMModuleSet() delete item.second; item.second = nullptr; } + + for (auto& item : CallGraphNode2SVFFunMap){ + delete item.second; + } + delete typeInference; typeInference = nullptr; } From 64a56dbb84a079c9cde127fb780ff57b0c029605 Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 19:39:26 +1100 Subject: [PATCH 42/45] remove comments --- svf-llvm/lib/ICFGBuilder.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/svf-llvm/lib/ICFGBuilder.cpp b/svf-llvm/lib/ICFGBuilder.cpp index a55ec0ade..0b2a27cee 100644 --- a/svf-llvm/lib/ICFGBuilder.cpp +++ b/svf-llvm/lib/ICFGBuilder.cpp @@ -247,12 +247,6 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst) { calledFunc = llvmModuleSet()->getCallGraphNode(called_llvmfunc); } -// else -// { -// const SVFFunction* func = SVFUtil::dyn_cast( -// llvmModuleSet()->getSVFValue(called_llvmval)); -// calledFunc = func?func->getCallGraphNode(): nullptr ; -// } SVFBasicBlock* bb = llvmModuleSet()->getSVFBasicBlock(inst->getParent()); From 5205addd8b043ca0ec109af5de2f56907d935d4c Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 21:23:22 +1100 Subject: [PATCH 43/45] callgraph->getPTACallGraphNode(fun)->getId()) --> fun->getId() --- svf/include/DDA/DDAVFSolver.h | 2 +- svf/include/MemoryModel/PointerAnalysis.h | 2 +- svf/lib/AE/Svfexe/AbstractInterpretation.cpp | 2 +- svf/lib/DDA/DDAPass.cpp | 8 ++------ svf/lib/MSSA/MemRegion.cpp | 3 +-- svf/lib/MemoryModel/PointerAnalysis.cpp | 4 +--- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/svf/include/DDA/DDAVFSolver.h b/svf/include/DDA/DDAVFSolver.h index e9e7a0135..c2b565155 100644 --- a/svf/include/DDA/DDAVFSolver.h +++ b/svf/include/DDA/DDAVFSolver.h @@ -478,7 +478,7 @@ class DDAVFSolver if(const CallGraphNode* svffun = _pag->getGNode(id)->getFunction()) { return _callGraphSCC->isInCycle( - _callGraph->getPTACallGraphNode(svffun)->getId()); + svffun->getId()); } } return false; diff --git a/svf/include/MemoryModel/PointerAnalysis.h b/svf/include/MemoryModel/PointerAnalysis.h index 24a857dad..2a783d751 100644 --- a/svf/include/MemoryModel/PointerAnalysis.h +++ b/svf/include/MemoryModel/PointerAnalysis.h @@ -407,7 +407,7 @@ class PointerAnalysis inline bool isInRecursion(const CallGraphNode* fun) const { return callGraphSCC->isInCycle( - callgraph->getPTACallGraphNode(fun)->getId()); + fun->getId()); } /// Whether a local variable is in function recursions bool isLocalVarInRecursiveFun(NodeID id) const; diff --git a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp index 474546e10..6f3042da7 100644 --- a/svf/lib/AE/Svfexe/AbstractInterpretation.cpp +++ b/svf/lib/AE/Svfexe/AbstractInterpretation.cpp @@ -797,7 +797,7 @@ void AbstractInterpretation::SkipRecursiveCall(const CallICFGNode *callNode) } FIFOWorkList blkWorkList; FIFOWorkList instWorklist; - for (const SVFBasicBlock * bb: callNode->getCalledFunction()->getReachableBBs()) // HWG need to rethink this + for (const SVFBasicBlock * bb: callNode->getCalledFunction()->getReachableBBs()) { for (const ICFGNode* node: bb->getICFGNodeList()) { diff --git a/svf/lib/DDA/DDAPass.cpp b/svf/lib/DDA/DDAPass.cpp index 2a78b93e4..c831322fd 100644 --- a/svf/lib/DDA/DDAPass.cpp +++ b/svf/lib/DDA/DDAPass.cpp @@ -270,12 +270,8 @@ void DDAPass::collectCxtInsenEdgeForVFCycle(PointerAnalysis* pta, const SVFG* sv if(srcFun && dstFun) { - NodeID src = - pta->getCallGraph() - ->getPTACallGraphNode(srcFun)->getId(); - NodeID dst = - pta->getCallGraph() - ->getPTACallGraphNode(dstFun)->getId(); + NodeID src = srcFun->getId(); + NodeID dst = dstFun->getId(); if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end()) insensitveEdges.insert(edge); else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end()) diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 8a38b8d11..507674bbd 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -577,8 +577,7 @@ bool MRGenerator::isNonLocalObject(NodeID id, const CallGraphNode* curFun) const if(svffun!=curFun) return true; else - return callGraphSCC->isInCycle( - callGraph->getPTACallGraphNode(svffun)->getId()); + return callGraphSCC->isInCycle(svffun->getId()); } } diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 6ae1e6794..13efe6493 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -139,9 +139,7 @@ bool PointerAnalysis::isLocalVarInRecursiveFun(NodeID id) const { if(const CallGraphNode* svffun = pag->getGNode(id)->getFunction()) { - return callGraphSCC->isInCycle( - getCallGraph() - ->getPTACallGraphNode(svffun)->getId()); + return callGraphSCC->isInCycle(svffun->getId()); } } return false; From b43fd17ae1229a8fdf77ab951f92e03ec5c91368 Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 21:29:10 +1100 Subject: [PATCH 44/45] rename getCallNode() -> getCallGraphNode(); connectSVFIRCallGraphEdge -> addSVFIRCallGraphEdges --- svf-llvm/lib/LLVMUtil.cpp | 2 +- svf/include/Graphs/PTACallGraph.h | 4 ++-- svf/include/Util/CallGraphBuilder.h | 4 ++-- svf/lib/Graphs/PTACallGraph.cpp | 10 +++++----- svf/lib/Graphs/ThreadCallGraph.cpp | 10 +++++----- svf/lib/MSSA/MemRegion.cpp | 4 ++-- svf/lib/MTA/LockAnalysis.cpp | 16 +++++++++------- svf/lib/MTA/MHP.cpp | 24 ++++++++++++++---------- svf/lib/MTA/TCT.cpp | 6 +++--- svf/lib/Util/CallGraphBuilder.cpp | 2 +- 10 files changed, 44 insertions(+), 38 deletions(-) diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index f07ed2be6..717f65452 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -757,7 +757,7 @@ const std::string SVFBaseNode::valueOnlyToString() const llvm::raw_string_ostream rawstr(str); if (const SVF::PTACallGraphNode* fun = SVFUtil::dyn_cast(this)) { - rawstr << "Function: " << fun->getCallNode()->getName() << " "; + rawstr << "Function: " << fun->getCallGraphNode()->getName() << " "; } else { diff --git a/svf/include/Graphs/PTACallGraph.h b/svf/include/Graphs/PTACallGraph.h index 62f68de96..98bedc9ef 100644 --- a/svf/include/Graphs/PTACallGraph.h +++ b/svf/include/Graphs/PTACallGraph.h @@ -191,7 +191,7 @@ class PTACallGraphNode : public GenericPTACallGraphNodeTy } /// Get function of this call node - inline const CallGraphNode* getCallNode() const + inline const CallGraphNode* getCallGraphNode() const { return fun; } @@ -418,7 +418,7 @@ class PTACallGraph : public GenericPTACallGraphTy for (CallGraphEdgeSet::const_iterator it = getCallEdgeBegin(cs), eit = getCallEdgeEnd(cs); it != eit; ++it) { - callees.insert((*it)->getDstNode()->getCallNode()); + callees.insert((*it)->getDstNode()->getCallGraphNode()); } } } diff --git a/svf/include/Util/CallGraphBuilder.h b/svf/include/Util/CallGraphBuilder.h index 921532f4b..15a09627e 100644 --- a/svf/include/Util/CallGraphBuilder.h +++ b/svf/include/Util/CallGraphBuilder.h @@ -47,9 +47,9 @@ class CallGraphBuilder CallGraphBuilder()=default; /// Buidl SVFIR callgraoh - CallGraph* createSVFIRCallGraph(SVFModule* svfModule); + CallGraph* createSVFIRCallGraph(); - void connectSVFIRCallGraphEdge(CallGraph* callGraph); + void addSVFIRCallGraphEdges(CallGraph* callGraph); /// Buidl PTA callgraoh PTACallGraph* buildPTACallGraph(); diff --git a/svf/lib/Graphs/PTACallGraph.cpp b/svf/lib/Graphs/PTACallGraph.cpp index b626841bf..af36b1485 100644 --- a/svf/lib/Graphs/PTACallGraph.cpp +++ b/svf/lib/Graphs/PTACallGraph.cpp @@ -91,7 +91,7 @@ bool PTACallGraphNode::isReachableFromProgEntry() const PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (SVFUtil::isProgEntryFunction(node->getCallNode())) + if (SVFUtil::isProgEntryFunction(node->getCallGraphNode())) return true; for (const_iterator it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) @@ -137,7 +137,7 @@ PTACallGraph::PTACallGraph(const CallGraph& other) { PTACallGraphNode* src = getCallGraphNode(edge->getSrcID()); PTACallGraphNode* dst = getCallGraphNode(edge->getDstID()); - CallSiteID csId = addCallSite(cs, dst->getCallNode()); + CallSiteID csId = addCallSite(cs, dst->getCallGraphNode()); PTACallGraphEdge* newEdge = new PTACallGraphEdge(src,dst, PTACallGraphEdge::CallRetEdge,csId); newEdge->addDirectCallSite(cs); @@ -205,7 +205,7 @@ void PTACallGraph::addIndirectCallGraphEdge(const CallICFGNode* cs,const CallGra numOfResolvedIndCallEdge++; - CallSiteID csId = addCallSite(cs, callee->getCallNode()); + CallSiteID csId = addCallSite(cs, callee->getCallGraphNode()); if(!hasGraphEdge(caller,callee, PTACallGraphEdge::CallRetEdge,csId)) { @@ -312,7 +312,7 @@ bool PTACallGraph::isReachableBetweenFunctions(const CallGraphNode* srcFn, const PTACallGraphNode* node = const_cast(nodeStack.top()); nodeStack.pop(); - if (node->getCallNode() == srcFn) + if (node->getCallGraphNode() == srcFn) return true; for (CallGraphEdgeConstIter it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it) @@ -369,7 +369,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits static std::string getNodeAttributes(PTACallGraphNode*node, PTACallGraph*) { - const CallGraphNode* fun = node->getCallNode(); + const CallGraphNode* fun = node->getCallGraphNode(); if (!SVFUtil::isExtCall(fun)) { return "shape=box"; diff --git a/svf/lib/Graphs/ThreadCallGraph.cpp b/svf/lib/Graphs/ThreadCallGraph.cpp index 2c9ed9ec2..630bde143 100644 --- a/svf/lib/Graphs/ThreadCallGraph.cpp +++ b/svf/lib/Graphs/ThreadCallGraph.cpp @@ -133,11 +133,11 @@ bool ThreadCallGraph::addDirectForkEdge(const CallICFGNode* cs) assert(forkee && "callee does not exist"); PTACallGraphNode* callee = getPTACallGraphNode( forkee->getDefFunForMultipleModule()); - CallSiteID csId = addCallSite(cs, callee->getCallNode()); + CallSiteID csId = addCallSite(cs, callee->getCallGraphNode()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getCallNode() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallGraphNode() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addDirectCallSite(cs); @@ -160,11 +160,11 @@ bool ThreadCallGraph::addIndirectForkEdge(const CallICFGNode* cs, const CallGrap PTACallGraphNode* callee = getPTACallGraphNode(calleefun); - CallSiteID csId = addCallSite(cs, callee->getCallNode()); + CallSiteID csId = addCallSite(cs, callee->getCallGraphNode()); if (!hasGraphEdge(caller, callee, PTACallGraphEdge::TDForkEdge, csId)) { - assert(cs->getCaller() == caller->getCallNode() && "callee instruction not inside caller??"); + assert(cs->getCaller() == caller->getCallGraphNode() && "callee instruction not inside caller??"); ThreadForkEdge* edge = new ThreadForkEdge(caller, callee, csId); edge->addInDirectCallSite(cs); @@ -202,7 +202,7 @@ void ThreadCallGraph::addDirectJoinEdge(const CallICFGNode* cs,const CallSiteSet if (!hasThreadJoinEdge(cs,joinFunNode,threadRoutineFunNode, csId)) { - assert(cs->getCaller() == joinFunNode->getCallNode() && "callee instruction not inside caller??"); + assert(cs->getCaller() == joinFunNode->getCallGraphNode() && "callee instruction not inside caller??"); ThreadJoinEdge* edge = new ThreadJoinEdge(joinFunNode,threadRoutineFunNode,csId); edge->addDirectCallSite(cs); diff --git a/svf/lib/MSSA/MemRegion.cpp b/svf/lib/MSSA/MemRegion.cpp index 507674bbd..1b2c24d6b 100644 --- a/svf/lib/MSSA/MemRegion.cpp +++ b/svf/lib/MSSA/MemRegion.cpp @@ -634,7 +634,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallGraphNode()); if(modrefchanged) worklist.push(edge->getSrcID()); } @@ -644,7 +644,7 @@ void MRGenerator::modRefAnalysis(PTACallGraphNode* callGraphNode, WorkList& work { NodeBS mod, ref; const CallICFGNode* cs = (*cit); - bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallNode()); + bool modrefchanged = handleCallsiteModRef(mod, ref, cs, callGraphNode->getCallGraphNode()); if(modrefchanged) worklist.push(edge->getSrcID()); } diff --git a/svf/lib/MTA/LockAnalysis.cpp b/svf/lib/MTA/LockAnalysis.cpp index 2c695a680..c916e76d3 100644 --- a/svf/lib/MTA/LockAnalysis.cpp +++ b/svf/lib/MTA/LockAnalysis.cpp @@ -126,7 +126,7 @@ void LockAnalysis::buildCandidateFuncSetforLock() while (!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - lockcandidateFuncSet.insert(node->getCallNode()); + lockcandidateFuncSet.insert(node->getCallGraphNode()); for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -277,7 +277,7 @@ void LockAnalysis::collectCxtLock() PTACallGraphNode* cgNode = getTCG()->getPTACallGraphNode(clp.getProc()); // lzh TODO. - if (!isLockCandidateFun(cgNode->getCallNode())) + if (!isLockCandidateFun(cgNode->getCallGraphNode())) continue; for (PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit != neit; nit++) @@ -319,7 +319,7 @@ void LockAnalysis::handleCallRelation(CxtLockProc& clp, const PTACallGraphEdge* addCxtLock(cxt,curNode); return; } - const CallGraphNode* svfcallee = cgEdge->getDstNode()->getCallNode(); + const CallGraphNode* svfcallee = cgEdge->getDstNode()->getCallGraphNode(); pushCxt(cxt, SVFUtil::cast(curNode), svfcallee); CxtLockProc newclp(cxt, svfcallee); @@ -417,7 +417,8 @@ void LockAnalysis::handleFork(const CxtStmt& cts) for (ThreadCallGraph::ForkEdgeSet::const_iterator cgIt = getTCG()->getForkEdgeBegin(call), ecgIt = getTCG()->getForkEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const CallGraphNode* svfcallee = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* svfcallee = + (*cgIt)->getDstNode()->getCallGraphNode(); CallStrCxt newCxt = curCxt; pushCxt(newCxt,call,svfcallee); const ICFGNode* svfInst = svfcallee->getEntryBlock()->front(); @@ -439,7 +440,8 @@ void LockAnalysis::handleCall(const CxtStmt& cts) for (PTACallGraph::CallGraphEdgeSet::const_iterator cgIt = getTCG()->getCallEdgeBegin(call), ecgIt = getTCG()->getCallEdgeEnd(call); cgIt != ecgIt; ++cgIt) { - const CallGraphNode* svfcallee = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* svfcallee = + (*cgIt)->getDstNode()->getCallGraphNode(); if (SVFUtil::isExtCall(svfcallee)) continue; CallStrCxt newCxt = curCxt; @@ -472,7 +474,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; if (matchCxt(newCxt, SVFUtil::cast(inst), - curFunNode->getCallNode())) + curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { @@ -490,7 +492,7 @@ void LockAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* inst = *cit; if (matchCxt(newCxt, SVFUtil::cast(inst), - curFunNode->getCallNode())) + curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : curInst->getOutEdges()) { diff --git a/svf/lib/MTA/MHP.cpp b/svf/lib/MTA/MHP.cpp index 7e20a00e1..3890854ed 100644 --- a/svf/lib/MTA/MHP.cpp +++ b/svf/lib/MTA/MHP.cpp @@ -189,7 +189,7 @@ void MHP::handleNonCandidateFun(const CxtThreadStmt& cts) tcg->getPTACallGraphNode(curfun); for (PTACallGraphNode::const_iterator nit = node->OutEdgeBegin(), neit = node->OutEdgeEnd(); nit != neit; nit++) { - const CallGraphNode* callee = (*nit)->getDstNode()->getCallNode(); + const CallGraphNode* callee = (*nit)->getDstNode()->getCallGraphNode(); if (!isExtCall(callee)) { const ICFGNode* calleeInst = callee->getEntryBlock()->front(); @@ -217,7 +217,8 @@ void MHP::handleFork(const CxtThreadStmt& cts, NodeID rootTid) ecgIt = tcg->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const CallGraphNode* cgn = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* cgn = + (*cgIt)->getDstNode()->getCallGraphNode(); CallStrCxt newCxt = curCxt; pushCxt(newCxt, cbn, cgn); const ICFGNode* stmt = cgn->getEntryBlock()->front(); @@ -302,7 +303,8 @@ void MHP::handleCall(const CxtThreadStmt& cts, NodeID rootTid) cgIt != ecgIt; ++cgIt) { - const CallGraphNode* cgnCallee = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* cgnCallee = + (*cgIt)->getDstNode()->getCallGraphNode(); if (isExtCall(cgnCallee)) continue; CallStrCxt newCxt = curCxt; @@ -331,7 +333,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getCallNode())) + if (matchCxt(newCxt, *cit, curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -348,7 +350,7 @@ void MHP::handleRet(const CxtThreadStmt& cts) cit != ecit; ++cit) { CallStrCxt newCxt = cts.getContext(); - if (matchCxt(newCxt, *cit, curFunNode->getCallNode())) + if (matchCxt(newCxt, *cit, curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : cts.getStmt()->getOutEdges()) { @@ -532,7 +534,7 @@ bool MHP::isConnectedfromMain(const CallGraphNode* fun) while (!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - if ("main" == node->getCallNode()->getName()) + if ("main" == node->getCallGraphNode()->getName()) return true; for (PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit != neit; nit++) { @@ -799,7 +801,8 @@ void ForkJoinAnalysis::handleFork(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getForkEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const CallGraphNode* callee = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* callee = + (*cgIt)->getDstNode()->getCallGraphNode(); CallStrCxt newCxt = curCxt; pushCxt(newCxt, cbn, callee); CxtThread ct(newCxt, call); @@ -890,7 +893,8 @@ void ForkJoinAnalysis::handleCall(const CxtStmt& cts, NodeID rootTid) ecgIt = getTCG()->getCallEdgeEnd(cbn); cgIt != ecgIt; ++cgIt) { - const CallGraphNode* cgnCallee = (*cgIt)->getDstNode()->getCallNode(); + const CallGraphNode* cgnCallee = + (*cgIt)->getDstNode()->getCallGraphNode(); if (isExtCall(cgnCallee)) continue; CallStrCxt newCxt = curCxt; @@ -921,7 +925,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) CallStrCxt newCxt = curCxt; const ICFGNode* curNode = (*cit); if (matchCxt(newCxt, SVFUtil::cast(curNode), - curFunNode->getCallNode())) + curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { @@ -941,7 +945,7 @@ void ForkJoinAnalysis::handleRet(const CxtStmt& cts) const ICFGNode* curNode = (*cit); if (matchCxt(newCxt, SVFUtil::cast(curNode), - curFunNode->getCallNode())) + curFunNode->getCallGraphNode())) { for(const ICFGEdge* outEdge : curNode->getOutEdges()) { diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index a1665aa19..337ce1d53 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -143,7 +143,7 @@ void TCT::markRelProcs() for(ThreadCallGraph::ForkEdgeSet::const_iterator nit = tcg->getForkEdgeBegin(*it), neit = tcg->getForkEdgeEnd(*it); nit!=neit; nit++) { const PTACallGraphNode* forkeeNode = (*nit)->getDstNode(); - candidateFuncSet.insert(forkeeNode->getCallNode()); + candidateFuncSet.insert(forkeeNode->getCallGraphNode()); } } @@ -172,7 +172,7 @@ void TCT::markRelProcs(const CallGraphNode* cgFun) while(!worklist.empty()) { const PTACallGraphNode* node = worklist.pop(); - candidateFuncSet.insert(node->getCallNode()); + candidateFuncSet.insert(node->getCallGraphNode()); for(PTACallGraphNode::const_iterator nit = node->InEdgeBegin(), neit = node->InEdgeEnd(); nit!=neit; nit++) { const PTACallGraphNode* srcNode = (*nit)->getSrcNode(); @@ -413,7 +413,7 @@ void TCT::build() CxtThreadProc ctp = popFromCTPWorkList(); PTACallGraphNode* cgNode = tcg->getPTACallGraphNode(ctp.getProc()); - if(isCandidateFun(cgNode->getCallNode()) == false) + if(isCandidateFun(cgNode->getCallGraphNode()) == false) continue; for(PTACallGraphNode::const_iterator nit = cgNode->OutEdgeBegin(), neit = cgNode->OutEdgeEnd(); nit!=neit; nit++) diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index 5c5ae7080..a67a28663 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -38,7 +38,7 @@ using namespace SVF; using namespace SVFUtil; -CallGraph* CallGraphBuilder::createSVFIRCallGraph(SVFModule* svfModule) +CallGraph* CallGraphBuilder::createSVFIRCallGraph() { return new CallGraph(); } From 0410a4264619e25505257262e226978104f0b574 Mon Sep 17 00:00:00 2001 From: hwg Date: Sun, 2 Feb 2025 21:48:46 +1100 Subject: [PATCH 45/45] rename getCallNode() -> getCallGraphNode(); connectSVFIRCallGraphEdge -> addSVFIRCallGraphEdges --- svf-llvm/lib/LLVMModule.cpp | 5 ++--- svf/include/Graphs/ThreadCallGraph.h | 8 ++++---- svf/lib/MTA/TCT.cpp | 2 +- svf/lib/Util/CallGraphBuilder.cpp | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/svf-llvm/lib/LLVMModule.cpp b/svf-llvm/lib/LLVMModule.cpp index 5644506ff..d61f69574 100644 --- a/svf-llvm/lib/LLVMModule.cpp +++ b/svf-llvm/lib/LLVMModule.cpp @@ -188,12 +188,11 @@ void LLVMModuleSet::build() addSVFMain(); CallGraphBuilder callGraphBuilder; - callgraph = callGraphBuilder.createSVFIRCallGraph(svfModule); + callgraph = callGraphBuilder.createSVFIRCallGraph(); createSVFDataStructure(); initSVFFunction(); - // iterate over CallGraphNode2SVFFunMap for (auto& item : CallGraphNode2SVFFunMap) { CallGraphNode* callNode = const_cast(item.first); @@ -218,7 +217,7 @@ void LLVMModuleSet::build() - callGraphBuilder.connectSVFIRCallGraphEdge(callgraph); + callGraphBuilder.addSVFIRCallGraphEdges(callgraph); } diff --git a/svf/include/Graphs/ThreadCallGraph.h b/svf/include/Graphs/ThreadCallGraph.h index c06b0e908..05d396309 100644 --- a/svf/include/Graphs/ThreadCallGraph.h +++ b/svf/include/Graphs/ThreadCallGraph.h @@ -73,8 +73,8 @@ class ThreadForkEdge: public PTACallGraphEdge std::stringstream rawstr(str); rawstr << "ThreadForkEdge "; rawstr << "CallSiteID: " << getCallSiteID(); - rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallNode()->getName() << ")"; - rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallNode()->getName() << ")"; + rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallGraphNode()->getName() << ")"; + rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallGraphNode()->getName() << ")"; return rawstr.str(); } @@ -113,8 +113,8 @@ class ThreadJoinEdge: public PTACallGraphEdge std::stringstream rawstr(str); rawstr << "ThreadJoinEdge "; rawstr << "CallSiteID: " << getCallSiteID(); - rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallNode()->getName() << ")"; - rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallNode()->getName() << ")"; + rawstr << " srcNodeID " << getSrcID() << " (fun: " << getSrcNode()->getCallGraphNode()->getName() << ")"; + rawstr << " dstNodeID " << getDstID() << " (fun: " << getDstNode()->getCallGraphNode()->getName() << ")"; return rawstr.str(); } diff --git a/svf/lib/MTA/TCT.cpp b/svf/lib/MTA/TCT.cpp index 337ce1d53..24876ae13 100644 --- a/svf/lib/MTA/TCT.cpp +++ b/svf/lib/MTA/TCT.cpp @@ -249,7 +249,7 @@ void TCT::collectMultiForkedThreads() */ void TCT::handleCallRelation(CxtThreadProc& ctp, const PTACallGraphEdge* cgEdge, const CallICFGNode* cs) { - const CallGraphNode* callee = cgEdge->getDstNode()->getCallNode(); + const CallGraphNode* callee = cgEdge->getDstNode()->getCallGraphNode(); CallStrCxt cxt(ctp.getContext()); CallStrCxt oldCxt = cxt; diff --git a/svf/lib/Util/CallGraphBuilder.cpp b/svf/lib/Util/CallGraphBuilder.cpp index a67a28663..9573c6a5e 100644 --- a/svf/lib/Util/CallGraphBuilder.cpp +++ b/svf/lib/Util/CallGraphBuilder.cpp @@ -43,8 +43,7 @@ CallGraph* CallGraphBuilder::createSVFIRCallGraph() return new CallGraph(); } -void CallGraphBuilder::connectSVFIRCallGraphEdge(CallGraph* callgraph) -{ +void CallGraphBuilder::addSVFIRCallGraphEdges(SVF::CallGraph* callgraph){ for (const auto& item : *callgraph) { for (auto it : *(item.second))