diff --git a/svf/lib/Util/CFBasicBlockGBuilder.cpp b/svf/lib/Util/CFBasicBlockGBuilder.cpp index cdef899de..d0d2498d6 100644 --- a/svf/lib/Util/CFBasicBlockGBuilder.cpp +++ b/svf/lib/Util/CFBasicBlockGBuilder.cpp @@ -28,6 +28,8 @@ */ #include "Util/CFBasicBlockGBuilder.h" +#include + namespace SVF { @@ -40,50 +42,76 @@ namespace SVF void CFBasicBlockGBuilder::initCFBasicBlockGNodes(ICFG *icfg, Map> &bbToNodes) { - for (const auto &node : *icfg) + for (const auto &func : *PAG::getPAG()->getModule()) { - CFBasicBlockNode *pNode; - if (const SVFBasicBlock *bb = node.second->getBB()) + for(const auto& bb: *func) { - if (const CallICFGNode *callNode = SVFUtil::dyn_cast(node.second)) - { - // Create a new CFBasicBlockNode for the CallICFGNode - pNode = new CFBasicBlockNode({callNode}); - bbToNodes[bb].push_back(pNode); - _CFBasicBlockG->addCFBBNode(pNode); - - // Create a new CFBasicBlockNode for the corresponding RetICFGNode - auto *retNode = new CFBasicBlockNode({callNode->getRetICFGNode()}); - bbToNodes[bb].push_back(retNode); - _CFBasicBlockG->addCFBBNode(retNode); - } - else if (!SVFUtil::isa(node.second)) + for(const auto& inst: *bb) { - if (bbToNodes.find(bb) == bbToNodes.end()) + if(SVFUtil::isIntrinsicInst(inst)) continue; + const ICFGNode* icfgNode = icfg->getICFGNode(inst); + if (const CallICFGNode *callNode = SVFUtil::dyn_cast(icfgNode)) { - // Create a new CFBasicBlockNode for the non-CallICFGNode - pNode = new CFBasicBlockNode({node.second}); - bbToNodes[node.second->getBB()] = {pNode}; + // Create a new CFBasicBlockNode for the CallICFGNode + CFBasicBlockNode* pNode = new CFBasicBlockNode({callNode}); + bbToNodes[bb].push_back(pNode); _CFBasicBlockG->addCFBBNode(pNode); + + // Create a new CFBasicBlockNode for the corresponding RetICFGNode + auto *retNode = new CFBasicBlockNode({callNode->getRetICFGNode()}); + bbToNodes[bb].push_back(retNode); + _CFBasicBlockG->addCFBBNode(retNode); } else { - pNode = bbToNodes[node.second->getBB()].back(); - if (!SVFUtil::isa(pNode->getICFGNodes()[0])) + if (bbToNodes.find(bb) == bbToNodes.end()) { - // Add the non-CallICFGNode to the existing CFBasicBlockNode - pNode->addNode(node.second); + // Create a new CFBasicBlockNode for the non-CallICFGNode + CFBasicBlockNode* pNode = new CFBasicBlockNode({icfgNode}); + bbToNodes[bb] = {pNode}; + _CFBasicBlockG->addCFBBNode(pNode); } else { - // Create a new CFBasicBlockNode for the non-CallICFGNode - pNode = new CFBasicBlockNode({node.second}); - bbToNodes[node.second->getBB()].push_back(pNode); - _CFBasicBlockG->addCFBBNode(pNode); + CFBasicBlockNode* pNode = bbToNodes[bb].back(); + if (!SVFUtil::isa(pNode->getICFGNodes()[0])) + { + // Add the non-CallICFGNode to the existing CFBasicBlockNode + pNode->addNode(icfgNode); + } + else + { + // Create a new CFBasicBlockNode for the non-CallICFGNode + pNode = new CFBasicBlockNode({icfgNode}); + bbToNodes[bb].push_back(pNode); + _CFBasicBlockG->addCFBBNode(pNode); + } } } } } + + if(const FunEntryICFGNode* funEntryNode = icfg->getFunEntryICFGNode(func)) + { + if(const SVFBasicBlock* bb = funEntryNode->getBB()) + { + std::vector& nodes = bbToNodes[bb]; + CFBasicBlockNode* pNode = new CFBasicBlockNode({funEntryNode}); + nodes.insert(nodes.begin(), pNode); + _CFBasicBlockG->addCFBBNode(pNode); + } + } + + if(const FunExitICFGNode* funExitNode = icfg->getFunExitICFGNode(func)) + { + if(const SVFBasicBlock* bb = funExitNode->getBB()) + { + std::vector& nodes = bbToNodes[bb]; + CFBasicBlockNode* pNode = new CFBasicBlockNode({funExitNode}); + nodes.push_back(pNode); + _CFBasicBlockG->addCFBBNode(pNode); + } + } } }