From 0b77ae0eda8d3abca659f816040021a82a456e81 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 23 Nov 2025 19:38:38 +0100 Subject: c: check actual reachability for non-void func may not return value --- ir/ir.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ir/ir.c') diff --git a/ir/ir.c b/ir/ir.c index 412d0f9..4a092b3 100644 --- a/ir/ir.c +++ b/ir/ir.c @@ -451,6 +451,27 @@ numberinstrs(struct function *fn) } while ((blk = blk->lnext) != fn->entry); } +static bool +reachablerec(struct function *fn, struct block *blk) +{ + if (blk == fn->entry) return 1; + markvisited(blk); + if (blk->npred == 1 && !wasvisited(blkpred(blk, 0))) + return reachablerec(fn, blkpred(blk, 0)); + else for (int i = 0; i < blk->npred; ++i) { + struct block *p = blkpred(blk, i); + if (!wasvisited(p) && reachablerec(fn, p)) return 1; + } + return 0; +} + +bool +blkreachable(struct function *fn, struct block *blk) +{ + startbbvisit(); + return reachablerec(fn, blk); +} + /* require use */ void replcuses(union ref from, union ref to) -- cgit v1.2.3