~mcf/cproc

4fa48e716d6381e51ae8dc7a9992c4c7d50219a1 — Michael Forney a month ago c4dc3ee
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.
1 files changed, 5 insertions(+), 2 deletions(-)

M qbe.c
M qbe.c => qbe.c +5 -2
@@ 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;