From 9df73782edda1e7715129a8c60ed44031a9f5828 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 1 Aug 2023 13:07:49 +0300 Subject: [PATCH] Fixed support for fake contol edges between END and ENTRY --- ir_dump.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ir_dump.c b/ir_dump.c index bafac5f..9c62e2e 100644 --- a/ir_dump.c +++ b/ir_dump.c @@ -670,8 +670,19 @@ void ir_dump_codegen(const ir_ctx *ctx, FILE *f) if (insn->op == IR_END || insn->op == IR_LOOP_END) { uint32_t succ; - IR_ASSERT(bb->successors_count == 1); - succ = ctx->cfg_edges[bb->successors]; + if (bb->successors_count == 1) { + succ = ctx->cfg_edges[bb->successors]; + } else { + /* END may have a fake control edge to ENTRY */ + IR_ASSERT(bb->successors_count == 2); + succ = ctx->cfg_edges[bb->successors]; + if (ctx->ir_base[ctx->cfg_blocks[succ].start].op == IR_ENTRY) { + succ = ctx->cfg_edges[bb->successors + 1]; + } else { + uint32_t fake_succ = ctx->cfg_edges[bb->successors + 1]; + IR_ASSERT(ctx->ir_base[ctx->cfg_blocks[fake_succ].start].op == IR_ENTRY); + } + } if (succ != b + 1) { fprintf(f, "\t# GOTO BB%d\n", succ); }