diff options
author | Michael Forney <mforney@mforney.org> | 2022-06-27 13:11:50 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2022-06-27 13:11:50 -0700 |
commit | 4fa48e716d6381e51ae8dc7a9992c4c7d50219a1 (patch) | |
tree | 794bb30b8ff13d1ef43c5d66d630d6cb77bf40fe | |
parent | c4dc3ee92a962dbb939789d5d5f7fd43a8dcdb6c (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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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; |