Tweak liveness analysis for if-else chains
diff --git a/internal/cgen/liveness.go b/internal/cgen/liveness.go
index 3382868..3d7db14 100644
--- a/internal/cgen/liveness.go
+++ b/internal/cgen/liveness.go
@@ -349,7 +349,7 @@
func (h *livenessHelper) doIf(r livenesses, n *a.If, depth uint32) error {
scratch := make(livenesses, len(r))
result := make(livenesses, len(r))
- for ; n != nil; n = n.ElseIf() {
+ for {
if err := h.doExpr(r, n.Condition()); err != nil {
return err
}
@@ -360,11 +360,17 @@
}
result.reconcile(scratch)
+ if ei := n.ElseIf(); ei != nil {
+ n = ei
+ continue
+ }
+
copy(scratch, r)
if err := h.doBlock(scratch, n.BodyIfFalse(), depth); err != nil {
return err
}
result.reconcile(scratch)
+ break
}
copy(r, result)
return nil
diff --git a/lang/check/type.go b/lang/check/type.go
index 0ce0d34..5b3f213 100644
--- a/lang/check/type.go
+++ b/lang/check/type.go
@@ -122,6 +122,11 @@
case a.KIf:
for n := n.AsIf(); n != nil; n = n.ElseIf() {
+ if (n.ElseIf() != nil) && (len(n.BodyIfFalse()) > 0) {
+ return fmt.Errorf("check: if has an else-if and an else-not-if")
+ }
+ }
+ for n := n.AsIf(); n != nil; n = n.ElseIf() {
cond := n.Condition()
if cond.Effect() != 0 {
return fmt.Errorf("check: internal error: if-condition is not effect-free")
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index 391ebb0..b62bea9 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -6634,7 +6634,6 @@
uint64_t scratch;
} s_decode_image_config[1];
struct {
- wuffs_base__status v_status;
uint64_t scratch;
} s_decode_frame[1];
struct {
@@ -8514,9 +8513,6 @@
uint32_t v_expect;
uint32_t v_expect_after_value;
} s_decode_tokens[1];
- struct {
- uint32_t v_neg;
- } s_decode_inf_nan[1];
} private_data;
#ifdef __cplusplus
@@ -23384,9 +23380,6 @@
}
uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
- if (coro_susp_point) {
- v_status = self->private_data.s_decode_frame[0].v_status;
- }
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -23513,7 +23506,6 @@
suspend:
self->private_impl.p_decode_frame[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
self->private_impl.active_coroutine = wuffs_base__status__is_suspension(&status) ? 3 : 0;
- self->private_data.s_decode_frame[0].v_status = v_status;
goto exit;
exit:
@@ -34278,9 +34270,6 @@
}
uint32_t coro_susp_point = self->private_impl.p_decode_inf_nan[0];
- if (coro_susp_point) {
- v_neg = self->private_data.s_decode_inf_nan[0].v_neg;
- }
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -34388,7 +34377,6 @@
goto suspend;
suspend:
self->private_impl.p_decode_inf_nan[0] = wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;
- self->private_data.s_decode_inf_nan[0].v_neg = v_neg;
goto exit;
exit: