ast_return should accept NULL as value to create a simple 'return' without a value

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-18 17:58:38 +02:00
parent 2cf4895cc7
commit 6d84010dc4
2 changed files with 15 additions and 10 deletions

17
ast.c
View file

@ -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;
}

8
ir.c
View file

@ -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;
}