diff --git a/tools/cc.py b/tools/cc.py index 8c18f8c..50047cc 100644 --- a/tools/cc.py +++ b/tools/cc.py @@ -1107,11 +1107,17 @@ class CcInterp(lark.visitors.Interpreter): self._synth(op) self.cur_fun.regs.drop_temps() begin_vars = self.cur_fun.regs.snap() + valid_vars_set = set(begin_vars[0].items()) self.visit(tree.children[1]) + valid_vars_set &= set(self.cur_fun.regs.snap()[0].items()) if has_else: self.cur_fun.regs.restore(begin_vars) self.cur_fun.ops.append(op.synth_else) self.visit(tree.children[2]) + valid_vars_set &= set(self.cur_fun.regs.snap()[0].items()) + valid_vars = dict(valid_vars_set) + valid_snap = (valid_vars, {r: begin_vars[1][r] for r in valid_vars.values()}) + self.cur_fun.regs.restore(valid_snap) self.cur_fun.ops.append(op.synth_endif) def _restore_vars(self, begin_vars):