Skip to content

Commit

Permalink
Support functions without return instruction and unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
Corteggiani committed Dec 11, 2017
1 parent 26d3d15 commit adb8c56
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions tools/inception-cl/IRMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void IRMerger::WriteABIEpilogue(llvm::Function* fct) {

Type* FType = fct->getReturnType();

Instruction* last = &(fct->back().back());
if (last && !dyn_cast<ReturnInst>(last)) {
llvm::ReturnInst::Create(getGlobalContext(), NULL, &(fct->back()));
}

// void return has been write by Lifter
if (FType->isVoidTy()) {
return;
Expand Down Expand Up @@ -109,27 +114,6 @@ void IRMerger::WriteABIEpilogue(llvm::Function* fct) {
inst = next;
}
}

/*
* If no return instruction is present, we create one if the function return
* void. Otherwise, we return an error.
* Functions can delegate the return to a callee. In this case, an infinite
* loop is often present at the end of the function (unreachable code).
*/
if (!has_return_inst) {
// To keep llvm-as happy we create an unreachable return instruction
if (fct->getReturnType()->isVoidTy()) {
IRBuilder<>* IRB = new IRBuilder<>(inst);

IRB->CreateRetVoid();
} else {
inception_error(
"Function %s has been decompiled without return instruction."
"It does not return void... This is often due to a disassembler "
"issue",
fct->getName().str().c_str());
}
}
}

void IRMerger::WriteABIPrologue(llvm::Function* fct) {
Expand Down

0 comments on commit adb8c56

Please sign in to comment.