From dd6a54d442ff6ae0d66c1d370dd1b1a72a82fdd0 Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Wed, 10 Mar 2010 19:35:14 -0700 Subject: [PATCH] Strange workaround for returning from within 'void main()'. The new dmdfe sets the ReturnStatement->exp to null. Fixed bug #391. --- gen/statements.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gen/statements.cpp b/gen/statements.cpp index 7e5c5725..4e0dbac2 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -57,7 +57,7 @@ void ReturnStatement::toIR(IRState* p) DtoDwarfStopPoint(loc.linnum); // is there a return value expression? - if (exp) + if (exp || (!exp && (p->topfunc() == p->mainFunc)) ) { // if the functions return type is void this means that // we are returning through a pointer argument @@ -88,8 +88,12 @@ void ReturnStatement::toIR(IRState* p) // the return type is not void, so this is a normal "register" return else { - // do abi specific transformations on the return value - LLValue* v = p->func()->type->fty.putRet(exp->type, exp->toElem(p)); + LLValue* v; + if (!exp && (p->topfunc() == p->mainFunc)) + v = LLConstant::getNullValue(p->mainFunc->getReturnType()); + else + // do abi specific transformations on the return value + v = p->func()->type->fty.putRet(exp->type, exp->toElem(p)); if (Logger::enabled()) Logger::cout() << "return value is '" <<*v << "'\n";