comparison gen/functions.cpp @ 428:8b7cee241e91

Enable insertion of missing terminator instruction for main.
author Christian Kamm <kamm incasoftware de>
date Tue, 29 Jul 2008 15:58:45 +0200
parents 0e6b4d65d3f8
children 74101be2a553
comparison
equal deleted inserted replaced
427:f1d37dc5d354 428:8b7cee241e91
693 // output function body 693 // output function body
694 fd->fbody->toIR(gIR); 694 fd->fbody->toIR(gIR);
695 695
696 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement 696 // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
697 // in automatically, so we do it here. 697 // in automatically, so we do it here.
698 if (!fd->isMain()) { 698 if (!gIR->scopereturned()) {
699 if (!gIR->scopereturned()) { 699 // pass the previous block into this block
700 // pass the previous block into this block 700 if (global.params.symdebug) DtoDwarfFuncEnd(fd);
701 if (global.params.symdebug) DtoDwarfFuncEnd(fd); 701 if (func->getReturnType() == LLType::VoidTy) {
702 if (func->getReturnType() == LLType::VoidTy) { 702 llvm::ReturnInst::Create(gIR->scopebb());
703 llvm::ReturnInst::Create(gIR->scopebb()); 703 }
704 } 704 else {
705 else { 705 if (!fd->isMain())
706 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); 706 llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
707 } 707 else
708 llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb());
708 } 709 }
709 } 710 }
710 711
711 // erase alloca point 712 // erase alloca point
712 allocaPoint->eraseFromParent(); 713 allocaPoint->eraseFromParent();