Mercurial > projects > ldc
changeset 974:815e1b8c6b00
Allow 'return exp;' for void main().
It's unfortunate that for main the llvm type and D type don't match up...
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Tue, 17 Feb 2009 18:53:15 +0100 |
parents | d96471e8b5e5 |
children | 067bb8f19c36 |
files | gen/statements.cpp tests/mini/mainvoidreturn.d |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/statements.cpp Tue Feb 17 18:25:34 2009 +0100 +++ b/gen/statements.cpp Tue Feb 17 18:53:15 2009 +0100 @@ -90,10 +90,15 @@ if (Logger::enabled()) Logger::cout() << "return value is '" <<*v << "'\n"; - // can happen for classes + // can happen for classes and void main if (v->getType() != p->topfunc()->getReturnType()) { - v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); + // for main and a void expression: return 0 instead, else bitcast + if (p->topfunc() == p->mainFunc && v->getType() == LLType::VoidTy) + v = llvm::Constant::getNullValue(p->mainFunc->getReturnType()); + else + v = gIR->ir->CreateBitCast(v, p->topfunc()->getReturnType(), "tmp"); + if (Logger::enabled()) Logger::cout() << "return value after cast: " << *v << '\n'; }