cc: fix loaded variables after if block

This commit is contained in:
Paul Mathieu 2021-04-24 08:56:51 -07:00
parent 84cbd185bb
commit 71212cde2d

View File

@ -1107,11 +1107,17 @@ class CcInterp(lark.visitors.Interpreter):
self._synth(op) self._synth(op)
self.cur_fun.regs.drop_temps() self.cur_fun.regs.drop_temps()
begin_vars = self.cur_fun.regs.snap() begin_vars = self.cur_fun.regs.snap()
valid_vars_set = set(begin_vars[0].items())
self.visit(tree.children[1]) self.visit(tree.children[1])
valid_vars_set &= set(self.cur_fun.regs.snap()[0].items())
if has_else: if has_else:
self.cur_fun.regs.restore(begin_vars) self.cur_fun.regs.restore(begin_vars)
self.cur_fun.ops.append(op.synth_else) self.cur_fun.ops.append(op.synth_else)
self.visit(tree.children[2]) 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) self.cur_fun.ops.append(op.synth_endif)
def _restore_vars(self, begin_vars): def _restore_vars(self, begin_vars):