]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
ast_return should accept NULL as value to create a simple 'return' without a value
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 15:58:38 +0000 (17:58 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 15:58:38 +0000 (17:58 +0200)
ast.c
ir.c

diff --git a/ast.c b/ast.c
index 851171ef50798a697f0a8f42bebd1f455391f41f..fb1bc87e40ed1689661faf4490df3e8773ff8d9e 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1135,13 +1135,18 @@ bool ast_return_codegen(ast_return *self, ast_function *func, bool lvalue, ir_va
     }
     self->expression.outr = (ir_value*)1;
 
-    cgen = self->operand->expression.codegen;
-    /* lvalue! */
-    if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
-        return false;
+    if (self->operand) {
+        cgen = self->operand->expression.codegen;
+        /* lvalue! */
+        if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
+            return false;
 
-    if (!ir_block_create_return(func->curblock, operand))
-        return false;
+        if (!ir_block_create_return(func->curblock, operand))
+            return false;
+    } else {
+        if (!ir_block_create_return(func->curblock, NULL))
+            return false;
+    }
 
     return true;
 }
diff --git a/ir.c b/ir.c
index 5e7a92324752d79f2e0baa3a167aec2a0beeb43a..dcf03e0f2905397a839542194e2b1c58b820fc20 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -1077,11 +1077,11 @@ bool ir_block_create_return(ir_block *self, ir_value *v)
     if (!in)
         return false;
 
-    if (!ir_instr_op(in, 0, v, false) ||
-        !ir_block_instr_add(self, in) )
-    {
+    if (v && !ir_instr_op(in, 0, v, false))
+        return false;
+
+    if (!ir_block_instr_add(self, in))
         return false;
-    }
     return true;
 }