aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-06-27 13:11:50 -0700
committerMichael Forney <mforney@mforney.org>2022-06-27 13:11:50 -0700
commit4fa48e716d6381e51ae8dc7a9992c4c7d50219a1 (patch)
tree794bb30b8ff13d1ef43c5d66d630d6cb77bf40fe
parentc4dc3ee92a962dbb939789d5d5f7fd43a8dcdb6c (diff)
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.
-rw-r--r--qbe.c7
1 files 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;