Skip to content

Commit

Permalink
Merge pull request #1273 from jumormt/master
Browse files Browse the repository at this point in the history
fix CFBBGbuilder bug
  • Loading branch information
yuleisui authored Dec 6, 2023
2 parents e98ad8a + d2c158b commit 9831850
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions svf-llvm/lib/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ void LLVMModuleSet::initSVFBasicBlock(const Function* func)
LLVMUtil::getPrevInsts(inst, getSVFInstruction(inst)->getPredInstructions());
}
}
// For no return functions, we set the last block as exit BB
// This ensures that each function that has definition must have an exit BB
if(svfFun->exitBlock == nullptr && svfFun->hasBasicBlock()) svfFun->setExitBlock(
const_cast<SVFBasicBlock *>(svfFun->back()));
}


Expand Down
7 changes: 1 addition & 6 deletions svf/include/SVFIR/SVFValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ class SVFFunction : public SVFValue

/// Carefully! when you call getExitBB, you need ensure the function has return instruction
/// more refer to: https://github.com/SVF-tools/SVF/pull/1262
inline const SVFBasicBlock* getExitBB() const
{
assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
assert((hasReturn() && exitBlock) && "ensure the function has a single basic block containing a return instruction!");
return exitBlock;
}
const SVFBasicBlock* getExitBB() const;

void setExitBlock(SVFBasicBlock *bb);

Expand Down
6 changes: 1 addition & 5 deletions svf/lib/Graphs/ICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ FunExitICFGNode::FunExitICFGNode(NodeID id, const SVFFunction* f)
// if function is implemented
if (f->begin() != f->end())
{
// ensure the enclosing function has exit basic block
if (f->hasReturn())
{
bb = f->getExitBB();
}
bb = f->getExitBB();
}
}

Expand Down
8 changes: 8 additions & 0 deletions svf/lib/SVFIR/SVFValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ bool SVFFunction::isVarArg() const
return varArg;
}

const SVFBasicBlock *SVFFunction::getExitBB() const
{
assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
assert((!hasReturn() || exitBlock->back()->isRetInst()) && "last inst must be return inst");
assert(exitBlock && "must have an exitBlock");
return exitBlock;
}

void SVFFunction::setExitBlock(SVFBasicBlock *bb)
{
assert(!exitBlock && "have already set exit Basicblock!");
Expand Down
2 changes: 2 additions & 0 deletions svf/lib/Util/CFBasicBlockGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ void CFBasicBlockGBuilder::addInterProceduralEdge(ICFG *icfg,
{
if (const RetCFGEdge *retEdge = SVFUtil::dyn_cast<RetCFGEdge>(icfgEdge))
{
// no return function
if(!retEdge->getSrcNode()->getFun()->hasReturn()) continue;
CFBasicBlockEdge *pEdge = new CFBasicBlockEdge(bbToNodes[retEdge->getSrcNode()->getBB()].back(),
bbNodes.second[i],
retEdge);
Expand Down

0 comments on commit 9831850

Please sign in to comment.