changeset 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 a8fc855f156e
children 18bbb1436153
files gen/statements.cpp
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gen/statements.cpp	Tue Mar 09 23:21:48 2010 +0200
+++ b/gen/statements.cpp	Wed Mar 10 19:35:14 2010 -0700
@@ -57,7 +57,7 @@
         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 @@
         // 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";