Skip to content

Commit d890e64

Browse files
committed
Auto merge of #77549 - tmiasko:simplify-branch-same-fix, r=oli-obk
Fix miscompile in SimplifyBranchSame Cherry-picked from #77486, but with a different test case that used to be compiled incorrectly on both master & beta branches.
2 parents 62bfcfd + f271957 commit d890e64

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

compiler/rustc_mir/src/transform/simplify_try.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
630630
// All successor basic blocks must be equal or contain statements that are pairwise considered equal.
631631
for ((target_and_value_l,bb_l), (target_and_value_r,bb_r)) in iter_bbs_reachable.tuple_windows() {
632632
let trivial_checks = bb_l.is_cleanup == bb_r.is_cleanup
633-
&& bb_l.terminator().kind == bb_r.terminator().kind;
633+
&& bb_l.terminator().kind == bb_r.terminator().kind
634+
&& bb_l.statements.len() == bb_r.statements.len();
634635
let statement_check = || {
635636
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
636637
let stmt_equality = self.statement_equality(*adt_matched_on, &l, target_and_value_l, &r, target_and_value_r);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for SimplifyBranchSame miscompilation.
2+
// run-pass
3+
4+
macro_rules! m {
5+
($a:expr, $b:expr, $c:block) => {
6+
match $a {
7+
Lto::Fat | Lto::Thin => { $b; (); $c }
8+
Lto::No => { $b; () }
9+
}
10+
}
11+
}
12+
13+
pub enum Lto { No, Thin, Fat }
14+
15+
fn f(mut cookie: u32, lto: Lto) -> u32 {
16+
let mut _a = false;
17+
m!(lto, _a = true, {cookie = 0});
18+
cookie
19+
}
20+
21+
fn main() { assert_eq!(f(42, Lto::Thin), 0) }

0 commit comments

Comments
 (0)