diff --git a/llvm_passes/core/Utils.cpp b/llvm_passes/core/Utils.cpp index f518a246..4e28240d 100644 --- a/llvm_passes/core/Utils.cpp +++ b/llvm_passes/core/Utils.cpp @@ -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(ret) || isa(ret) ){} + else{ + for( inst_iterator f_it = inst_begin(func); f_it != inst_end(func); ++f_it ){ + if( isa(&(*f_it))){ + ret = &(*f_it); + } + } + } + assert(isa(ret) || isa(ret) && "Last instruction is not return or exit() instruction"); return ret;