mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-12 02:43:14 +01:00
Allow 'return exp;' for void main().
It's unfortunate that for main the llvm type and D type don't match up...
This commit is contained in:
@@ -90,10 +90,15 @@ void ReturnStatement::toIR(IRState* p)
|
||||
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';
|
||||
}
|
||||
|
||||
7
tests/mini/mainvoidreturn.d
Normal file
7
tests/mini/mainvoidreturn.d
Normal file
@@ -0,0 +1,7 @@
|
||||
void foo()
|
||||
{}
|
||||
|
||||
void main()
|
||||
{
|
||||
return foo();
|
||||
}
|
||||
Reference in New Issue
Block a user