Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CFBBGbuilder bug #1273

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
set last bb as exit bb for no return func
  • Loading branch information
jumormt committed Dec 6, 2023
commit d2c158bb48712a0c47309c0b46dff4ef847da179
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
4 changes: 2 additions & 2 deletions svf/lib/Util/CFBasicBlockGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ void CFBasicBlockGBuilder::addInterProceduralEdge(ICFG *icfg,
{
if (const RetCFGEdge *retEdge = SVFUtil::dyn_cast<RetCFGEdge>(icfgEdge))
{
// no return function does not have an exit BB
if(!retEdge->getSrcNode()->getBB()) continue;
// no return function
if(!retEdge->getSrcNode()->getFun()->hasReturn()) continue;
CFBasicBlockEdge *pEdge = new CFBasicBlockEdge(bbToNodes[retEdge->getSrcNode()->getBB()].back(),
bbNodes.second[i],
retEdge);
Expand Down
Loading