Mercurial > projects > ldc
comparison gen/statements.cpp @ 1647:638a823ace45
Strange workaround for returning from within 'void main()'. The new dmdfe sets the ReturnStatement->exp to null. Fixed bug #391.
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Wed, 10 Mar 2010 19:35:14 -0700 |
parents | 332925de1881 |
children | 40bd4a0d4870 |
comparison
equal
deleted
inserted
replaced
1646:a8fc855f156e | 1647:638a823ace45 |
---|---|
55 | 55 |
56 if (global.params.symdebug) | 56 if (global.params.symdebug) |
57 DtoDwarfStopPoint(loc.linnum); | 57 DtoDwarfStopPoint(loc.linnum); |
58 | 58 |
59 // is there a return value expression? | 59 // is there a return value expression? |
60 if (exp) | 60 if (exp || (!exp && (p->topfunc() == p->mainFunc)) ) |
61 { | 61 { |
62 // if the functions return type is void this means that | 62 // if the functions return type is void this means that |
63 // we are returning through a pointer argument | 63 // we are returning through a pointer argument |
64 if (p->topfunc()->getReturnType() == LLType::getVoidTy(gIR->context())) | 64 if (p->topfunc()->getReturnType() == LLType::getVoidTy(gIR->context())) |
65 { | 65 { |
86 | 86 |
87 } | 87 } |
88 // the return type is not void, so this is a normal "register" return | 88 // the return type is not void, so this is a normal "register" return |
89 else | 89 else |
90 { | 90 { |
91 // do abi specific transformations on the return value | 91 LLValue* v; |
92 LLValue* v = p->func()->type->fty.putRet(exp->type, exp->toElem(p)); | 92 if (!exp && (p->topfunc() == p->mainFunc)) |
93 v = LLConstant::getNullValue(p->mainFunc->getReturnType()); | |
94 else | |
95 // do abi specific transformations on the return value | |
96 v = p->func()->type->fty.putRet(exp->type, exp->toElem(p)); | |
93 | 97 |
94 if (Logger::enabled()) | 98 if (Logger::enabled()) |
95 Logger::cout() << "return value is '" <<*v << "'\n"; | 99 Logger::cout() << "return value is '" <<*v << "'\n"; |
96 | 100 |
97 IrFunction* f = p->func(); | 101 IrFunction* f = p->func(); |