From 4fa48e716d6381e51ae8dc7a9992c4c7d50219a1 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 27 Jun 2022 13:11:50 -0700 Subject: qbe: Insert dead block when compiling unreachable code after a jump QBE will optimize out these blocks, and the dead block prevents the possibility of NULL value usage when further control flow follows. Fixes #80. --- qbe.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qbe.c b/qbe.c index b95af9e..d24d963 100644 --- a/qbe.c +++ b/qbe.c @@ -246,9 +246,12 @@ static struct value * funcinst(struct func *f, int op, int class, struct value *arg0, struct value *arg1) { struct inst *inst; + struct block *b; - if (f->end->jump.kind) - return NULL; + if (f->end->jump.kind) { + b = mkblock("dead"); + funclabel(f, b); + } inst = mkinst(f, op, class, arg0, arg1); arrayaddptr(&f->end->insts, inst); return &inst->res; -- cgit v1.2.3