From f2c5fa2c2f2e0c3c266218f7d849b399e015b052 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 29 Jul 2008 15:58:45 +0200 Subject: [PATCH] Enable insertion of missing terminator instruction for main. --- gen/functions.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index aa194f99..0ed5d178 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -695,16 +695,17 @@ void DtoDefineFunc(FuncDeclaration* fd) // llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement // in automatically, so we do it here. - if (!fd->isMain()) { - if (!gIR->scopereturned()) { - // pass the previous block into this block - if (global.params.symdebug) DtoDwarfFuncEnd(fd); - if (func->getReturnType() == LLType::VoidTy) { - llvm::ReturnInst::Create(gIR->scopebb()); - } - else { + if (!gIR->scopereturned()) { + // pass the previous block into this block + if (global.params.symdebug) DtoDwarfFuncEnd(fd); + if (func->getReturnType() == LLType::VoidTy) { + llvm::ReturnInst::Create(gIR->scopebb()); + } + else { + if (!fd->isMain()) llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb()); - } + else + llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb()); } }