harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3a7ceaaefb8b92a78c7cb7eef9ec6618fa47a7d5
parent dcbf011ec9014746cbe1e940c1201e5bcee83f70
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 12 Feb 2021 10:21:10 -0500

check: return void even if value is absent

Diffstat:
Msrc/check.c | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1512,19 +1512,23 @@ check_expr_return(struct context *ctx, expr->result = &builtin_type_void; expr->terminates = true; + struct expression *rval = xcalloc(1, sizeof(struct expression)); if (aexpr->_return.value) { - struct expression *rval = xcalloc(1, sizeof(struct expression)); check_expression(ctx, aexpr->_return.value, rval, ctx->fntype->func.result); - expect(&aexpr->_return.value->loc, - type_is_assignable(ctx->fntype->func.result, rval->result), - "Return value is not assignable to function result type"); - if (ctx->fntype->func.result != rval->result) { - rval = lower_implicit_cast( - ctx->fntype->func.result, rval); - } - expr->_return.value = rval; + } else { + rval->type = EXPR_CONSTANT; + rval->result = &builtin_type_void; + } + + expect(&aexpr->_return.value->loc, + type_is_assignable(ctx->fntype->func.result, rval->result), + "Return value is not assignable to function result type"); + if (ctx->fntype->func.result != rval->result) { + rval = lower_implicit_cast( + ctx->fntype->func.result, rval); } + expr->_return.value = rval; trleave(TR_CHECK, NULL); }