Skip to content

Commit

Permalink
chore: Add panic for compiler error described in #6620 (#6621)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Nov 26, 2024
1 parent 624ae6c commit 7d7b9c9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ impl<'f> Context<'f> {
};
self.condition_stack.push(cond_context);
self.insert_current_side_effects_enabled();

// We disallow this case as it results in the `else_destination` block
// being inlined before the `then_destination` block due to block deduplication in the work queue.
//
// The `else_destination` block then gets treated as if it were the `then_destination` block
// and has the incorrect condition applied to it.
assert_ne!(
self.branch_ends[if_entry], *then_destination,
"ICE: branches merge inside of `then` branch"
);
vec![self.branch_ends[if_entry], *else_destination, *then_destination]
}

Expand Down Expand Up @@ -1476,4 +1486,23 @@ mod test {
_ => unreachable!("Should have terminator instruction"),
}
}

#[test]
#[should_panic = "ICE: branches merge inside of `then` branch"]
fn panics_if_branches_merge_within_then_branch() {
//! This is a regression test for https://github.com/noir-lang/noir/issues/6620
let src = "
acir(inline) fn main f0 {
b0(v0: u1):
jmpif v0 then: b2, else: b1
b2():
return
b1():
jmp b2()
}
";
let merged_ssa = Ssa::from_str(src).unwrap();
let _ = merged_ssa.flatten_cfg();
}
}

0 comments on commit 7d7b9c9

Please sign in to comment.