Skip to content
Open
Changes from all commits
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
11 changes: 11 additions & 0 deletions llvm_passes/core/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ Instruction *getTermInstofFunction(Function *func) {
BasicBlock &termbb = func->back();
Instruction *ret = termbb.getTerminator();

// if the instruction in the last BB is not return/unreachable instruction,
// iterate through the main function to find the return/unreachable instruction
if( isa<ReturnInst>(ret) || isa<UnreachableInst>(ret) ){}
else{
for( inst_iterator f_it = inst_begin(func); f_it != inst_end(func); ++f_it ){
if( isa<ReturnInst>(&(*f_it))){
ret = &(*f_it);
}
}
}

assert(isa<ReturnInst>(ret) || isa<UnreachableInst>(ret) &&
"Last instruction is not return or exit() instruction");
return ret;
Expand Down