aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-24 17:01:57 +0200
committerlemon <lsof@mailbox.org>2025-10-24 17:01:57 +0200
commite732643b8640bfdc822e2e4bd994977279b2f58b (patch)
tree13e9224c24cff9e84ccf547c79934f5022721fa8
parent2a2b7d3eb49c919deab6988ca8ca22fb05c1eaa6 (diff)
c: also propagate terminates in genswitch
-rw-r--r--c/c.c13
-rw-r--r--ir/ir.c1
2 files changed, 10 insertions, 4 deletions
diff --git a/c/c.c b/c/c.c
index 6ae7ee7..fd5da52 100644
--- a/c/c.c
+++ b/c/c.c
@@ -3426,7 +3426,7 @@ struct switchstmt {
vec_of(struct swcase) cases;
};
-static void
+static bool
genswitch(struct comp *cm, struct function *fn, const struct expr *ex)
{
union ref sel;
@@ -3475,8 +3475,15 @@ genswitch(struct comp *cm, struct function *fn, const struct expr *ex)
vfree(&st.cases);
if (fn->curblk != end) {
if (fn->curblk) EMITS putbranch(fn, end);
- useblk(fn, end);
+ if (end->npred > 0) {
+ useblk(fn, end);
+ } else {
+ fn->curblk = NULL;
+ freeblk(fn, end);
+ }
}
+
+ return fn->curblk == NULL;
}
static bool /* return 1 if stmt is terminating (ends with a jump) */
@@ -3728,7 +3735,7 @@ stmt(struct comp *cm, struct function *fn)
expect(cm, ')', NULL);
if (!isint(ex.ty))
error(&ex.span, "'switch' value is not an integer: '%ty'", ex.ty);
- genswitch(cm, fn, &ex);
+ terminates = genswitch(cm, fn, &ex);
break;
case TKWbreak:
lex(cm, &tk);
diff --git a/ir/ir.c b/ir/ir.c
index 5cd1624..49d8d5e 100644
--- a/ir/ir.c
+++ b/ir/ir.c
@@ -297,7 +297,6 @@ insertblk(struct function *fn, struct block *pred, struct block *subst)
assert(0);
}
-
static int
newinstr(void)
{