harec

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

commit 4f167dd8b1209571c1fb7cc06cb9c4eee52d5d9e
parent c1684d24b9f1c44f2262315b22301fff3e173b4c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  4 Aug 2021 12:39:19 +0200

gen: more sophisticated (hack) for trailing ret

Would be nice if qbe didn't require this, but here we are.

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gen.c b/src/gen.c @@ -805,7 +805,12 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl) struct gen_value ret = gen_expr(ctx, decl->func.body); if (decl->func.body->terminates) { - pushi(ctx->current, NULL, Q_RET, NULL); + // XXX: This is a bit hacky, to appease qbe + size_t ln = ctx->current->body.ln; + struct qbe_statement *last = &ctx->current->body.stmts[ln - 1]; + if (last->type != Q_INSTR || last->instr != Q_RET) { + pushi(ctx->current, NULL, Q_RET, NULL); + } } else if (type_dealias(fntype->func.result)->storage != STORAGE_VOID) { struct qbe_value qret = mkqval(ctx, &ret); pushi(ctx->current, NULL, Q_RET, &qret, NULL);