From 3ac9b17e1aca31a2c01c0887272b50741d43ad76 Mon Sep 17 00:00:00 2001 From: lemon Date: Wed, 18 Feb 2026 18:18:12 +0100 Subject: ir/rpo: sanity checks --- ir/cfg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ir') diff --git a/ir/cfg.c b/ir/cfg.c index 58e1625..24a0614 100644 --- a/ir/cfg.c +++ b/ir/cfg.c @@ -1,12 +1,14 @@ #include "ir.h" static void -porec(struct block ***rpo, struct block *b) +porec(int *nblk, struct block ***rpo, struct block *b) { if (wasvisited(b)) return; + assert(*nblk > 0 && "nblk bad"); + --*nblk; markvisited(b); - if (b->s2) porec(rpo, b->s2); - if (b->s1) porec(rpo, b->s1); + if (b->s2) porec(nblk, rpo, b->s2); + if (b->s1) porec(nblk, rpo, b->s1); *--*rpo = b; } @@ -23,7 +25,8 @@ sortrpo(struct function *fn) startbbvisit(); fn->entry->id = 0; - porec(&rpo, fn->entry); + int nblk = fn->nblk; + porec(&nblk, &rpo, fn->entry); ndead = rpo - rpobuf; if (ndead > 0) for (blk = fn->entry->lprev; blk != fn->entry; blk = next) { next = blk->lprev; -- cgit v1.2.3