Skip to content

Commit

Permalink
fix(ssa refactor): Fix ssa-gen of nested ifs (#1406)
Browse files Browse the repository at this point in the history
Fix ssa-gen of nested ifs
  • Loading branch information
jfecher committed May 25, 2023
1 parent 82c9181 commit 5fd976e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/noirc_evaluator/src/ssa_refactor/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,22 @@ impl<'a> FunctionContext<'a> {
let mut result = self.unit_value();

if let Some(alternative) = &if_expr.alternative {
let end_block = self.builder.insert_block();
let then_values = then_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, then_values);

self.builder.switch_to_block(else_block);
let else_value = self.codegen_expression(alternative);

let end_block = self.builder.insert_block();
let else_values = else_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, else_values);

// Create block arguments for the end block as needed to branch to
// with our then and else value.
result = Self::map_type(&if_expr.typ, |typ| {
self.builder.add_block_parameter(end_block, typ).into()
});

let else_values = else_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, else_values);

// Must also set the then block to jmp to the end now
self.builder.switch_to_block(then_block);
let then_values = then_value.into_value_list(self);
self.builder.terminate_with_jmp(end_block, then_values);
self.builder.switch_to_block(end_block);
} else {
// In the case we have no 'else', the 'else' block is actually the end block.
Expand Down

0 comments on commit 5fd976e

Please sign in to comment.