diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index a5c86e31a2921..1e0a47ead8c5c 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -159,52 +159,44 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } ExprKind::LogicalOp { op, lhs, rhs } => { - // And: - // - // [block: If(lhs)] -true-> [else_block: dest = (rhs)] - // | (false) - // [shortcircuit_block: dest = false] - // - // Or: - // - // [block: If(lhs)] -false-> [else_block: dest = (rhs)] - // | (true) - // [shortcircuit_block: dest = true] - - let (shortcircuit_block, mut else_block, join_block) = ( - this.cfg.start_new_block(), - this.cfg.start_new_block(), - this.cfg.start_new_block(), - ); - - let lhs = unpack!(block = this.as_local_operand(block, &this.thir[lhs])); - let blocks = match op { - LogicalOp::And => (else_block, shortcircuit_block), - LogicalOp::Or => (shortcircuit_block, else_block), + let condition_scope = this.local_scope(); + let source_info = this.source_info(expr.span); + // We first evaluate the left-hand side of the predicate ... + let (then_block, else_block) = + this.in_if_then_scope(condition_scope, expr.span, |this| { + this.then_else_break( + block, + &this.thir[lhs], + Some(condition_scope), + condition_scope, + source_info, + ) + }); + let (short_circuit, continuation, constant) = match op { + LogicalOp::And => (else_block, then_block, false), + LogicalOp::Or => (then_block, else_block, true), }; - let term = TerminatorKind::if_(lhs, blocks.0, blocks.1); - this.cfg.terminate(block, source_info, term); - + // At this point, the control flow splits into a short-circuiting path + // and a continuation path. + // - If the operator is `&&`, passing `lhs` leads to continuation of evaluation on `rhs`; + // failing it leads to the short-circuting path which assigns `false` to the place. + // - If the operator is `||`, failing `lhs` leads to continuation of evaluation on `rhs`; + // passing it leads to the short-circuting path which assigns `true` to the place. this.cfg.push_assign_constant( - shortcircuit_block, + short_circuit, source_info, destination, Constant { - span: expr_span, + span: expr.span, user_ty: None, - literal: match op { - LogicalOp::And => ConstantKind::from_bool(this.tcx, false), - LogicalOp::Or => ConstantKind::from_bool(this.tcx, true), - }, + literal: ConstantKind::from_bool(this.tcx, constant), }, ); - this.cfg.goto(shortcircuit_block, source_info, join_block); - - let rhs = unpack!(else_block = this.as_local_operand(else_block, &this.thir[rhs])); - this.cfg.push_assign(else_block, source_info, destination, Rvalue::Use(rhs)); - this.cfg.goto(else_block, source_info, join_block); - - join_block.unit() + let rhs = unpack!(this.expr_into_dest(destination, continuation, &this.thir[rhs])); + let target = this.cfg.start_new_block(); + this.cfg.goto(rhs, source_info, target); + this.cfg.goto(short_circuit, source_info, target); + target.unit() } ExprKind::Loop { body } => { // [block] diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 3c450740712c0..5ec216cea616b 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -64,6 +64,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { rhs_then_block.unit() } + ExprKind::LogicalOp { op: LogicalOp::Or, lhs, rhs } => { + let local_scope = this.local_scope(); + let (lhs_success_block, failure_block) = + this.in_if_then_scope(local_scope, expr_span, |this| { + this.then_else_break( + block, + &this.thir[lhs], + temp_scope_override, + local_scope, + variable_source_info, + ) + }); + let rhs_success_block = unpack!(this.then_else_break( + failure_block, + &this.thir[rhs], + temp_scope_override, + break_scope, + variable_source_info, + )); + this.cfg.goto(lhs_success_block, variable_source_info, rhs_success_block); + rhs_success_block.unit() + } + ExprKind::Unary { op: UnOp::Not, arg } => { + let local_scope = this.local_scope(); + let (success_block, failure_block) = + this.in_if_then_scope(local_scope, expr_span, |this| { + this.then_else_break( + block, + &this.thir[arg], + temp_scope_override, + local_scope, + variable_source_info, + ) + }); + this.break_for_else(success_block, break_scope, variable_source_info); + failure_block.unit() + } ExprKind::Scope { region_scope, lint_level, value } => { let region_scope = (region_scope, this.source_info(expr_span)); this.in_scope(region_scope, lint_level, |this| { @@ -76,6 +113,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) }) } + ExprKind::Use { source } => this.then_else_break( + block, + &this.thir[source], + temp_scope_override, + break_scope, + variable_source_info, + ), ExprKind::Let { expr, ref pat } => this.lower_let_expr( block, &this.thir[expr], diff --git a/tests/codegen/slice-as_chunks.rs b/tests/codegen/slice-as_chunks.rs index 48e3f73fc8637..efac9f3d68da8 100644 --- a/tests/codegen/slice-as_chunks.rs +++ b/tests/codegen/slice-as_chunks.rs @@ -22,9 +22,9 @@ pub fn chunks4(x: &[u8]) -> &[[u8; 4]] { // CHECK-LABEL: @chunks4_with_remainder #[no_mangle] pub fn chunks4_with_remainder(x: &[u8]) -> (&[[u8; 4]], &[u8]) { - // CHECK: and i64 %x.1, -4 - // CHECK: and i64 %x.1, 3 - // CHECK: lshr exact + // CHECK-DAG: and i64 %x.1, -4 + // CHECK-DAG: and i64 %x.1, 3 + // CHECK-DAG: lshr // CHECK-NOT: mul // CHECK-NOT: udiv // CHECK-NOT: urem diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs index f7d164bc8564c..8749226d40173 100644 --- a/tests/codegen/slice-iter-nonnull.rs +++ b/tests/codegen/slice-iter-nonnull.rs @@ -100,13 +100,13 @@ pub fn slice_iter_is_empty(it: &std::slice::Iter<'_, u32>) -> bool { // CHECK-LABEL: @slice_iter_len #[no_mangle] pub fn slice_iter_len(it: &std::slice::Iter<'_, u32>) -> usize { - // CHECK: %[[START:.+]] = load ptr, ptr %it, - // CHECK-SAME: !nonnull - // CHECK-SAME: !noundef // CHECK: %[[ENDP:.+]] = getelementptr{{.+}}ptr %it,{{.+}} 1 // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]] // CHECK-SAME: !nonnull // CHECK-SAME: !noundef + // CHECK: %[[START:.+]] = load ptr, ptr %it, + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef // CHECK: ptrtoint // CHECK: ptrtoint diff --git a/tests/mir-opt/bool_compare.opt1.InstSimplify.diff b/tests/mir-opt/bool_compare.opt1.InstSimplify.diff index 8d0011d5067f7..657c11516a172 100644 --- a/tests/mir-opt/bool_compare.opt1.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt1.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(move _3, const true); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt2.InstSimplify.diff b/tests/mir-opt/bool_compare.opt2.InstSimplify.diff index 35f1068709b26..bc8be62bd49d6 100644 --- a/tests/mir-opt/bool_compare.opt2.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt2.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(const true, move _3); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt3.InstSimplify.diff b/tests/mir-opt/bool_compare.opt3.InstSimplify.diff index ab15c30ca1185..034d5e44013cf 100644 --- a/tests/mir-opt/bool_compare.opt3.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt3.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(move _3, const false); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/bool_compare.opt4.InstSimplify.diff b/tests/mir-opt/bool_compare.opt4.InstSimplify.diff index 40fd1cfe112d2..d3096da6c5a2f 100644 --- a/tests/mir-opt/bool_compare.opt4.InstSimplify.diff +++ b/tests/mir-opt/bool_compare.opt4.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(const false, move _3); + _2 = Not(move _3); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/building/logical_or_in_conditional.rs b/tests/mir-opt/building/logical_or_in_conditional.rs new file mode 100644 index 0000000000000..ae159f7e12239 --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.rs @@ -0,0 +1,39 @@ +// compile-flags: -Z validate-mir +#![feature(let_chains)] +struct Droppy(u8); +impl Drop for Droppy { + fn drop(&mut self) { + println!("drop {}", self.0); + } +} + +enum E { + A(u8), + B, +} + +impl E { + fn f() -> Self { + Self::A(1) + } +} + +fn always_true() -> bool { + true +} + +// EMIT_MIR logical_or_in_conditional.test_or.built.after.mir +fn test_or() { + if Droppy(0).0 > 0 || Droppy(1).0 > 1 {} +} + +// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir +fn test_complex() { + if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {} + + if !always_true() && let E::B = E::f() {} +} + +fn main() { + test_or(); +} diff --git a/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir new file mode 100644 index 0000000000000..096aaec4a3888 --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.test_complex.built.after.mir @@ -0,0 +1,186 @@ +// MIR for `test_complex` after built + +fn test_complex() -> () { + let mut _0: (); + let _1: (); + let mut _2: E; + let mut _3: isize; + let mut _4: bool; + let mut _5: bool; + let mut _6: u8; + let mut _7: Droppy; + let mut _8: bool; + let mut _9: u8; + let mut _10: Droppy; + let mut _11: bool; + let mut _12: E; + let mut _13: isize; + + bb0: { + StorageLive(_1); + StorageLive(_2); + _2 = E::f() -> [return: bb1, unwind: bb31]; + } + + bb1: { + FakeRead(ForMatchedPlace(None), _2); + _3 = discriminant(_2); + switchInt(move _3) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + falseEdge -> [real: bb4, imaginary: bb3]; + } + + bb3: { + goto -> bb19; + } + + bb4: { + StorageLive(_4); + _4 = always_true() -> [return: bb5, unwind: bb31]; + } + + bb5: { + switchInt(move _4) -> [0: bb7, otherwise: bb6]; + } + + bb6: { + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _7 = Droppy(const 0_u8); + _6 = (_7.0: u8); + _5 = Gt(move _6, const 0_u8); + switchInt(move _5) -> [0: bb9, otherwise: bb8]; + } + + bb7: { + goto -> bb13; + } + + bb8: { + drop(_7) -> [return: bb10, unwind: bb31]; + } + + bb9: { + goto -> bb11; + } + + bb10: { + StorageDead(_7); + StorageDead(_6); + goto -> bb16; + } + + bb11: { + drop(_7) -> [return: bb12, unwind: bb31]; + } + + bb12: { + StorageDead(_7); + StorageDead(_6); + goto -> bb13; + } + + bb13: { + StorageLive(_8); + StorageLive(_9); + StorageLive(_10); + _10 = Droppy(const 1_u8); + _9 = (_10.0: u8); + _8 = Gt(move _9, const 1_u8); + switchInt(move _8) -> [0: bb15, otherwise: bb14]; + } + + bb14: { + drop(_10) -> [return: bb16, unwind: bb31]; + } + + bb15: { + goto -> bb17; + } + + bb16: { + StorageDead(_10); + StorageDead(_9); + _1 = const (); + goto -> bb20; + } + + bb17: { + drop(_10) -> [return: bb18, unwind: bb31]; + } + + bb18: { + StorageDead(_10); + StorageDead(_9); + goto -> bb19; + } + + bb19: { + _1 = const (); + goto -> bb20; + } + + bb20: { + StorageDead(_8); + StorageDead(_5); + StorageDead(_4); + StorageDead(_2); + StorageDead(_1); + StorageLive(_11); + _11 = always_true() -> [return: bb21, unwind: bb31]; + } + + bb21: { + switchInt(move _11) -> [0: bb23, otherwise: bb22]; + } + + bb22: { + goto -> bb29; + } + + bb23: { + goto -> bb24; + } + + bb24: { + StorageLive(_12); + _12 = E::f() -> [return: bb25, unwind: bb31]; + } + + bb25: { + FakeRead(ForMatchedPlace(None), _12); + _13 = discriminant(_12); + switchInt(move _13) -> [1: bb27, otherwise: bb26]; + } + + bb26: { + goto -> bb29; + } + + bb27: { + falseEdge -> [real: bb28, imaginary: bb26]; + } + + bb28: { + _0 = const (); + goto -> bb30; + } + + bb29: { + _0 = const (); + goto -> bb30; + } + + bb30: { + StorageDead(_11); + StorageDead(_12); + return; + } + + bb31 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir b/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir new file mode 100644 index 0000000000000..b84c17c21886e --- /dev/null +++ b/tests/mir-opt/building/logical_or_in_conditional.test_or.built.after.mir @@ -0,0 +1,87 @@ +// MIR for `test_or` after built + +fn test_or() -> () { + let mut _0: (); + let mut _1: bool; + let mut _2: u8; + let mut _3: Droppy; + let mut _4: bool; + let mut _5: u8; + let mut _6: Droppy; + + bb0: { + StorageLive(_1); + StorageLive(_2); + StorageLive(_3); + _3 = Droppy(const 0_u8); + _2 = (_3.0: u8); + _1 = Gt(move _2, const 0_u8); + switchInt(move _1) -> [0: bb2, otherwise: bb1]; + } + + bb1: { + drop(_3) -> [return: bb3, unwind: bb12]; + } + + bb2: { + goto -> bb4; + } + + bb3: { + StorageDead(_3); + StorageDead(_2); + goto -> bb8; + } + + bb4: { + drop(_3) -> [return: bb5, unwind: bb12]; + } + + bb5: { + StorageDead(_3); + StorageDead(_2); + StorageLive(_4); + StorageLive(_5); + StorageLive(_6); + _6 = Droppy(const 1_u8); + _5 = (_6.0: u8); + _4 = Gt(move _5, const 1_u8); + switchInt(move _4) -> [0: bb7, otherwise: bb6]; + } + + bb6: { + drop(_6) -> [return: bb8, unwind: bb12]; + } + + bb7: { + goto -> bb9; + } + + bb8: { + StorageDead(_6); + StorageDead(_5); + _0 = const (); + goto -> bb11; + } + + bb9: { + drop(_6) -> [return: bb10, unwind: bb12]; + } + + bb10: { + StorageDead(_6); + StorageDead(_5); + _0 = const (); + goto -> bb11; + } + + bb11: { + StorageDead(_4); + StorageDead(_1); + return; + } + + bb12 (cleanup): { + resume; + } +} diff --git a/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff b/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff index d1dbc7089a1cd..1768298d52181 100644 --- a/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff +++ b/tests/mir-opt/const_goto_storage.match_nested_if.ConstGoto.diff @@ -43,31 +43,33 @@ } bb3: { -- StorageDead(_6); - switchInt(move _5) -> [0: bb5, otherwise: bb4]; - } - - bb4: { +- StorageDead(_6); - _4 = const true; - goto -> bb6; - } - - bb5: { +- StorageDead(_6); - _4 = const false; - goto -> bb6; - } - - bb6: { -- StorageDead(_5); - switchInt(move _4) -> [0: bb8, otherwise: bb7]; - } - - bb7: { +- StorageDead(_5); - _3 = const true; - goto -> bb9; - } - - bb8: { +- StorageDead(_5); - _3 = const false; - goto -> bb9; - } diff --git a/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff b/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff index 08b599f9f5d0d..355f28b03db53 100644 --- a/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff +++ b/tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff @@ -39,19 +39,20 @@ StorageLive(_4); - _4 = _1; - _3 = Eq(move _4, const 1_i32); +- switchInt(move _3) -> [0: bb2, otherwise: bb1]; + _4 = const 1_i32; + _3 = const true; - StorageDead(_4); -- switchInt(move _3) -> [0: bb2, otherwise: bb1]; + switchInt(const true) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_4); _2 = const 2_i32; goto -> bb3; } bb2: { + StorageDead(_4); _2 = const 3_i32; goto -> bb3; } @@ -70,20 +71,21 @@ StorageLive(_9); - _9 = _1; - _8 = Eq(move _9, const 1_i32); +- switchInt(move _8) -> [0: bb5, otherwise: bb4]; + _9 = const 1_i32; + _8 = const true; - StorageDead(_9); -- switchInt(move _8) -> [0: bb5, otherwise: bb4]; + switchInt(const true) -> [0: bb5, otherwise: bb4]; } bb4: { + StorageDead(_9); - _7 = _1; + _7 = const 1_i32; goto -> bb6; } bb5: { + StorageDead(_9); StorageLive(_10); _10 = _1; _7 = Add(move _10, const 1_i32); diff --git a/tests/mir-opt/equal_true.opt.InstSimplify.diff b/tests/mir-opt/equal_true.opt.InstSimplify.diff index 7b38862e4d563..88a51000c9331 100644 --- a/tests/mir-opt/equal_true.opt.InstSimplify.diff +++ b/tests/mir-opt/equal_true.opt.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Eq(move _3, const true); + _2 = move _3; - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_i32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_i32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff index 8483b89f81477..15319586062b8 100644 --- a/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff @@ -12,16 +12,17 @@ StorageLive(_3); _3 = _1; _2 = Eq(move _3, const -42f32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_i32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_i32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff index 837841b009b79..fedbd6cdd24a6 100644 --- a/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_char.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 'x'); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [120: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff index 3cbf912996cc5..9c38d8fe06577 100644 --- a/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_i8.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_i8); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff index 8d6f3b2249e87..8c85ce78565c3 100644 --- a/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff @@ -14,40 +14,36 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_u32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb6; } bb2: { -+ StorageDead(_3); + StorageDead(_3); StorageLive(_4); StorageLive(_5); _5 = _1; - _4 = Ne(move _5, const 21_u32); -- StorageDead(_5); - switchInt(move _4) -> [0: bb4, otherwise: bb3]; + nop; -+ nop; + switchInt(move _5) -> [21: bb4, otherwise: bb3]; } bb3: { -+ StorageDead(_5); + StorageDead(_5); _0 = const 1_u32; goto -> bb5; } bb4: { -+ StorageDead(_5); + StorageDead(_5); _0 = const 2_u32; goto -> bb5; } diff --git a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff index e2566b13c598c..876ed61e9fa3a 100644 --- a/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_negative.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const -42_i32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [4294967254: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff b/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff index dc8da5b44b219..ed3eb47dd3d9d 100644 --- a/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff +++ b/tests/mir-opt/if_condition_int.opt_u32.SimplifyComparisonIntegral.diff @@ -12,21 +12,19 @@ StorageLive(_3); _3 = _1; - _2 = Eq(move _3, const 42_u32); -- StorageDead(_3); - switchInt(move _2) -> [0: bb2, otherwise: bb1]; + nop; -+ nop; + switchInt(move _3) -> [42: bb1, otherwise: bb2]; } bb1: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { -+ StorageDead(_3); + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff index 9db0d385da7fd..d675695eb1047 100644 --- a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-abort.diff @@ -18,11 +18,11 @@ StorageLive(_3); _3 = _1; _2 = Gt(move _3, const 0_i32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); StorageLive(_4); _4 = _1; _0 = move _4 as u32 (IntToInt); @@ -32,6 +32,7 @@ } bb2: { + StorageDead(_3); StorageLive(_6); - _6 = panic() -> unwind unreachable; + StorageLive(_7); diff --git a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff index 5663b4624001a..1142616115fb7 100644 --- a/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_diverging.g.Inline.panic-unwind.diff @@ -18,11 +18,11 @@ StorageLive(_3); _3 = _1; _2 = Gt(move _3, const 0_i32); - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); StorageLive(_4); _4 = _1; _0 = move _4 as u32 (IntToInt); @@ -32,6 +32,7 @@ } bb2: { + StorageDead(_3); StorageLive(_6); - _6 = panic() -> unwind continue; + StorageLive(_7); diff --git a/tests/mir-opt/issue_99325.main.built.after.mir b/tests/mir-opt/issue_99325.main.built.after.mir index aef89c7f9f742..f12179a890535 100644 --- a/tests/mir-opt/issue_99325.main.built.after.mir +++ b/tests/mir-opt/issue_99325.main.built.after.mir @@ -16,51 +16,49 @@ fn main() -> () { let _8: &&[u8]; let _9: &&[u8; 4]; let mut _10: bool; - let mut _11: bool; - let mut _12: &&[u8]; - let mut _13: &&[u8; 4]; - let mut _14: !; - let _16: !; - let mut _17: core::panicking::AssertKind; - let mut _18: &&[u8]; - let _19: &&[u8]; - let mut _20: &&[u8; 4]; - let _21: &&[u8; 4]; - let mut _22: std::option::Option>; - let _23: (); - let mut _24: (&&[u8], &&[u8; 4]); - let mut _25: &&[u8]; - let _26: &[u8]; - let mut _27: &&[u8; 4]; - let _28: &[u8; 4]; - let _29: &&[u8]; - let _30: &&[u8; 4]; - let mut _31: bool; - let mut _32: bool; - let mut _33: &&[u8]; - let mut _34: &&[u8; 4]; - let mut _35: !; - let _37: !; - let mut _38: core::panicking::AssertKind; - let mut _39: &&[u8]; - let _40: &&[u8]; - let mut _41: &&[u8; 4]; - let _42: &&[u8; 4]; - let mut _43: std::option::Option>; + let mut _11: &&[u8]; + let mut _12: &&[u8; 4]; + let mut _13: !; + let _15: !; + let mut _16: core::panicking::AssertKind; + let mut _17: &&[u8]; + let _18: &&[u8]; + let mut _19: &&[u8; 4]; + let _20: &&[u8; 4]; + let mut _21: std::option::Option>; + let _22: (); + let mut _23: (&&[u8], &&[u8; 4]); + let mut _24: &&[u8]; + let _25: &[u8]; + let mut _26: &&[u8; 4]; + let _27: &[u8; 4]; + let _28: &&[u8]; + let _29: &&[u8; 4]; + let mut _30: bool; + let mut _31: &&[u8]; + let mut _32: &&[u8; 4]; + let mut _33: !; + let _35: !; + let mut _36: core::panicking::AssertKind; + let mut _37: &&[u8]; + let _38: &&[u8]; + let mut _39: &&[u8; 4]; + let _40: &&[u8; 4]; + let mut _41: std::option::Option>; scope 1 { debug left_val => _8; debug right_val => _9; - let _15: core::panicking::AssertKind; + let _14: core::panicking::AssertKind; scope 2 { - debug kind => _15; + debug kind => _14; } } scope 3 { - debug left_val => _29; - debug right_val => _30; - let _36: core::panicking::AssertKind; + debug left_val => _28; + debug right_val => _29; + let _34: core::panicking::AssertKind; scope 4 { - debug kind => _36; + debug kind => _34; } } @@ -69,7 +67,7 @@ fn main() -> () { StorageLive(_2); StorageLive(_3); StorageLive(_4); - _4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb19]; + _4 = function_with_bytes::<&*b"AAAA">() -> [return: bb1, unwind: bb21]; } bb1: { @@ -90,179 +88,185 @@ fn main() -> () { _9 = (_2.1: &&[u8; 4]); StorageLive(_10); StorageLive(_11); + _11 = &(*_8); StorageLive(_12); - _12 = &(*_8); - StorageLive(_13); - _13 = &(*_9); - _11 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _12, move _13) -> [return: bb2, unwind: bb19]; + _12 = &(*_9); + _10 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _11, move _12) -> [return: bb2, unwind: bb21]; } bb2: { - StorageDead(_13); - StorageDead(_12); - _10 = Not(move _11); - StorageDead(_11); switchInt(move _10) -> [0: bb4, otherwise: bb3]; } bb3: { + StorageDead(_12); + StorageDead(_11); + goto -> bb8; + } + + bb4: { + goto -> bb5; + } + + bb5: { + StorageDead(_12); + StorageDead(_11); + StorageLive(_14); + _14 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _14); StorageLive(_15); - _15 = core::panicking::AssertKind::Eq; - FakeRead(ForLet(None), _15); StorageLive(_16); + _16 = move _14; StorageLive(_17); - _17 = move _15; StorageLive(_18); + _18 = &(*_8); + _17 = &(*_18); StorageLive(_19); - _19 = &(*_8); - _18 = &(*_19); StorageLive(_20); + _20 = &(*_9); + _19 = &(*_20); StorageLive(_21); - _21 = &(*_9); - _20 = &(*_21); - StorageLive(_22); - _22 = Option::>::None; - _16 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _17, move _18, move _20, move _22) -> bb19; - } - - bb4: { - goto -> bb7; + _21 = Option::>::None; + _15 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _16, move _17, move _19, move _21) -> bb21; } - bb5: { - StorageDead(_22); - StorageDead(_20); - StorageDead(_18); - StorageDead(_17); + bb6: { StorageDead(_21); StorageDead(_19); + StorageDead(_17); StorageDead(_16); + StorageDead(_20); + StorageDead(_18); StorageDead(_15); + StorageDead(_14); unreachable; } - bb6: { - goto -> bb8; + bb7: { + goto -> bb9; } - bb7: { + bb8: { _1 = const (); - goto -> bb8; + goto -> bb9; } - bb8: { + bb9: { StorageDead(_10); StorageDead(_9); StorageDead(_8); - goto -> bb9; + goto -> bb10; } - bb9: { + bb10: { StorageDead(_7); StorageDead(_6); StorageDead(_4); StorageDead(_2); StorageDead(_1); + StorageLive(_22); StorageLive(_23); StorageLive(_24); StorageLive(_25); - StorageLive(_26); - _26 = function_with_bytes::<&*b"AAAA">() -> [return: bb10, unwind: bb19]; + _25 = function_with_bytes::<&*b"AAAA">() -> [return: bb11, unwind: bb21]; } - bb10: { - _25 = &_26; + bb11: { + _24 = &_25; + StorageLive(_26); StorageLive(_27); + _27 = const b"AAAA"; + _26 = &_27; + _23 = (move _24, move _26); + StorageDead(_26); + StorageDead(_24); + FakeRead(ForMatchedPlace(None), _23); StorageLive(_28); - _28 = const b"AAAA"; - _27 = &_28; - _24 = (move _25, move _27); - StorageDead(_27); - StorageDead(_25); - FakeRead(ForMatchedPlace(None), _24); + _28 = (_23.0: &&[u8]); StorageLive(_29); - _29 = (_24.0: &&[u8]); + _29 = (_23.1: &&[u8; 4]); StorageLive(_30); - _30 = (_24.1: &&[u8; 4]); StorageLive(_31); + _31 = &(*_28); StorageLive(_32); - StorageLive(_33); - _33 = &(*_29); - StorageLive(_34); - _34 = &(*_30); - _32 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _33, move _34) -> [return: bb11, unwind: bb19]; + _32 = &(*_29); + _30 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _31, move _32) -> [return: bb12, unwind: bb21]; } - bb11: { - StorageDead(_34); - StorageDead(_33); - _31 = Not(move _32); + bb12: { + switchInt(move _30) -> [0: bb14, otherwise: bb13]; + } + + bb13: { StorageDead(_32); - switchInt(move _31) -> [0: bb13, otherwise: bb12]; + StorageDead(_31); + goto -> bb18; } - bb12: { + bb14: { + goto -> bb15; + } + + bb15: { + StorageDead(_32); + StorageDead(_31); + StorageLive(_34); + _34 = core::panicking::AssertKind::Eq; + FakeRead(ForLet(None), _34); + StorageLive(_35); StorageLive(_36); - _36 = core::panicking::AssertKind::Eq; - FakeRead(ForLet(None), _36); + _36 = move _34; StorageLive(_37); StorageLive(_38); - _38 = move _36; + _38 = &(*_28); + _37 = &(*_38); StorageLive(_39); StorageLive(_40); _40 = &(*_29); _39 = &(*_40); StorageLive(_41); - StorageLive(_42); - _42 = &(*_30); - _41 = &(*_42); - StorageLive(_43); - _43 = Option::>::None; - _37 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _38, move _39, move _41, move _43) -> bb19; - } - - bb13: { - goto -> bb16; + _41 = Option::>::None; + _35 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _36, move _37, move _39, move _41) -> bb21; } - bb14: { - StorageDead(_43); + bb16: { StorageDead(_41); StorageDead(_39); - StorageDead(_38); - StorageDead(_42); - StorageDead(_40); StorageDead(_37); StorageDead(_36); + StorageDead(_40); + StorageDead(_38); + StorageDead(_35); + StorageDead(_34); unreachable; } - bb15: { - goto -> bb17; + bb17: { + goto -> bb19; } - bb16: { - _23 = const (); - goto -> bb17; + bb18: { + _22 = const (); + goto -> bb19; } - bb17: { - StorageDead(_31); + bb19: { StorageDead(_30); StorageDead(_29); - goto -> bb18; + StorageDead(_28); + goto -> bb20; } - bb18: { - StorageDead(_28); - StorageDead(_26); - StorageDead(_24); + bb20: { + StorageDead(_27); + StorageDead(_25); StorageDead(_23); + StorageDead(_22); _0 = const (); return; } - bb19 (cleanup): { + bb21 (cleanup): { resume; } } diff --git a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff index 6174d5259d0a0..5242c5f6afd87 100644 --- a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-abort.diff @@ -32,12 +32,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -52,6 +52,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff index 60c0772d8ecc2..a9e99933b123f 100644 --- a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff @@ -32,12 +32,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -52,6 +52,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff index e2de184529689..7749ba6beca76 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-abort.diff @@ -35,12 +35,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -55,6 +55,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); StorageLive(_11); _11 = const 0_usize; _12 = Len((*_2)); diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff index eb81e0eea2cf0..fcc2c1653dc1d 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.NormalizeArrayLen.panic-unwind.diff @@ -35,12 +35,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_8); _8 = _1; _9 = Len((*_2)); @@ -55,6 +55,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); StorageLive(_11); _11 = const 0_usize; _12 = Len((*_2)); diff --git a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff index 70b33fb703bc0..7f752ca0f5a2c 100644 --- a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff +++ b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-abort.diff @@ -28,12 +28,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_7); _7 = _1; _8 = Len((*_2)); @@ -48,6 +48,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff index 310b3b26ac563..d73b563a0e5de 100644 --- a/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff +++ b/tests/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.panic-unwind.diff @@ -28,12 +28,12 @@ bb1: { StorageDead(_6); _3 = Lt(move _4, move _5); - StorageDead(_5); - StorageDead(_4); switchInt(move _3) -> [0: bb4, otherwise: bb2]; } bb2: { + StorageDead(_5); + StorageDead(_4); StorageLive(_7); _7 = _1; _8 = Len((*_2)); @@ -48,6 +48,8 @@ } bb4: { + StorageDead(_5); + StorageDead(_4); _0 = const 42_u8; goto -> bb5; } diff --git a/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff index b5edbfee0fc1e..5a71bef93416d 100644 --- a/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff +++ b/tests/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff @@ -40,39 +40,43 @@ - } - - bb3: { +- switchInt(move _5) -> [0: bb5, otherwise: bb4]; +- } +- +- bb4: { + StorageLive(_7); + _7 = move _6; + _5 = Ne(_7, const false); + StorageDead(_7); ++ StorageLive(_8); ++ _8 = move _5; StorageDead(_6); -- switchInt(move _5) -> [0: bb5, otherwise: bb4]; -- } -- -- bb4: { - _4 = const true; - goto -> bb6; - } - - bb5: { +- StorageDead(_6); - _4 = const false; - goto -> bb6; - } - - bb6: { -+ StorageLive(_8); -+ _8 = move _5; -+ _4 = Ne(_8, const false); -+ StorageDead(_8); - StorageDead(_5); - switchInt(move _4) -> [0: bb8, otherwise: bb7]; - } - - bb7: { ++ _4 = Ne(_8, const false); ++ StorageDead(_8); ++ StorageLive(_9); ++ _9 = move _4; + StorageDead(_5); - _3 = const true; - goto -> bb9; - } - - bb8: { +- StorageDead(_5); - _3 = const false; - goto -> bb9; - } @@ -82,8 +86,6 @@ - } - - bb10: { -+ StorageLive(_9); -+ _9 = move _4; + _3 = Ne(_9, const false); + StorageDead(_9); + StorageLive(_10); diff --git a/tests/mir-opt/not_equal_false.opt.InstSimplify.diff b/tests/mir-opt/not_equal_false.opt.InstSimplify.diff index 71353be24a67c..1342966aa15e5 100644 --- a/tests/mir-opt/not_equal_false.opt.InstSimplify.diff +++ b/tests/mir-opt/not_equal_false.opt.InstSimplify.diff @@ -13,16 +13,17 @@ _3 = _1; - _2 = Ne(move _3, const false); + _2 = move _3; - StorageDead(_3); switchInt(move _2) -> [0: bb2, otherwise: bb1]; } bb1: { + StorageDead(_3); _0 = const 0_u32; goto -> bb3; } bb2: { + StorageDead(_3); _0 = const 1_u32; goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir index c7fd397fcd4ff..838e30fa35ebb 100644 --- a/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/chained_comparison.naive.PreCodegen.after.mir @@ -7,130 +7,111 @@ fn naive(_1: &Blueprint, _2: &Blueprint) -> bool { let mut _3: u32; let mut _4: u32; let mut _5: bool; - let mut _6: bool; + let mut _6: u32; let mut _7: u32; - let mut _8: u32; - let mut _9: bool; - let mut _10: bool; - let mut _11: u32; + let mut _8: bool; + let mut _9: u32; + let mut _10: u32; + let mut _11: bool; let mut _12: u32; - let mut _13: bool; + let mut _13: u32; let mut _14: bool; let mut _15: u32; let mut _16: u32; - let mut _17: bool; - let mut _18: u32; - let mut _19: u32; - let mut _20: bool; bb0: { - StorageLive(_14); - StorageLive(_10); - StorageLive(_6); StorageLive(_5); StorageLive(_3); _3 = ((*_1).0: u32); StorageLive(_4); _4 = ((*_2).0: u32); _5 = Eq(move _3, move _4); - StorageDead(_4); - StorageDead(_3); switchInt(move _5) -> [0: bb1, otherwise: bb2]; } bb1: { - _6 = const false; - goto -> bb3; + StorageDead(_4); + StorageDead(_3); + goto -> bb8; } bb2: { - StorageLive(_9); - StorageLive(_7); - _7 = ((*_1).1: u32); + StorageDead(_4); + StorageDead(_3); StorageLive(_8); - _8 = ((*_2).1: u32); - _9 = Eq(move _7, move _8); - StorageDead(_8); - StorageDead(_7); - _6 = move _9; - goto -> bb3; + StorageLive(_6); + _6 = ((*_1).1: u32); + StorageLive(_7); + _7 = ((*_2).1: u32); + _8 = Eq(move _6, move _7); + switchInt(move _8) -> [0: bb3, otherwise: bb4]; } bb3: { - StorageDead(_9); - StorageDead(_5); - switchInt(move _6) -> [0: bb4, otherwise: bb5]; + StorageDead(_7); + StorageDead(_6); + goto -> bb8; } bb4: { - _10 = const false; - goto -> bb6; + StorageDead(_7); + StorageDead(_6); + StorageLive(_11); + StorageLive(_9); + _9 = ((*_1).2: u32); + StorageLive(_10); + _10 = ((*_2).2: u32); + _11 = Eq(move _9, move _10); + switchInt(move _11) -> [0: bb5, otherwise: bb6]; } bb5: { - StorageLive(_13); - StorageLive(_11); - _11 = ((*_1).2: u32); - StorageLive(_12); - _12 = ((*_2).2: u32); - _13 = Eq(move _11, move _12); - StorageDead(_12); - StorageDead(_11); - _10 = move _13; - goto -> bb6; + StorageDead(_10); + StorageDead(_9); + goto -> bb8; } bb6: { - StorageDead(_13); - StorageDead(_6); - switchInt(move _10) -> [0: bb7, otherwise: bb8]; + StorageDead(_10); + StorageDead(_9); + StorageLive(_14); + StorageLive(_12); + _12 = ((*_1).3: u32); + StorageLive(_13); + _13 = ((*_2).3: u32); + _14 = Eq(move _12, move _13); + switchInt(move _14) -> [0: bb7, otherwise: bb9]; } bb7: { - _14 = const false; - goto -> bb9; + StorageDead(_13); + StorageDead(_12); + goto -> bb8; } bb8: { - StorageLive(_17); + _0 = const false; + goto -> bb10; + } + + bb9: { + StorageDead(_13); + StorageDead(_12); StorageLive(_15); - _15 = ((*_1).3: u32); + _15 = ((*_1).4: u32); StorageLive(_16); - _16 = ((*_2).3: u32); - _17 = Eq(move _15, move _16); + _16 = ((*_2).4: u32); + _0 = Eq(move _15, move _16); StorageDead(_16); StorageDead(_15); - _14 = move _17; - goto -> bb9; - } - - bb9: { - StorageDead(_17); - StorageDead(_10); - switchInt(move _14) -> [0: bb10, otherwise: bb11]; + goto -> bb10; } bb10: { - _0 = const false; - goto -> bb12; - } - - bb11: { - StorageLive(_20); - StorageLive(_18); - _18 = ((*_1).4: u32); - StorageLive(_19); - _19 = ((*_2).4: u32); - _20 = Eq(move _18, move _19); - StorageDead(_19); - StorageDead(_18); - _0 = move _20; - goto -> bb12; - } - - bb12: { - StorageDead(_20); StorageDead(_14); + StorageDead(_11); + StorageDead(_8); + StorageDead(_5); return; } } diff --git a/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir index 1e619bc9704ac..8452fa12f31de 100644 --- a/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/chained_comparison.returning.PreCodegen.after.mir @@ -27,12 +27,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_4); _4 = ((*_2).0: u32); _5 = Ne(move _3, move _4); - StorageDead(_4); - StorageDead(_3); switchInt(move _5) -> [0: bb1, otherwise: bb10]; } bb1: { + StorageDead(_4); + StorageDead(_3); StorageDead(_5); StorageLive(_8); StorageLive(_6); @@ -40,12 +40,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_7); _7 = ((*_2).1: u32); _8 = Ne(move _6, move _7); - StorageDead(_7); - StorageDead(_6); switchInt(move _8) -> [0: bb2, otherwise: bb9]; } bb2: { + StorageDead(_7); + StorageDead(_6); StorageDead(_8); StorageLive(_11); StorageLive(_9); @@ -53,12 +53,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_10); _10 = ((*_2).2: u32); _11 = Ne(move _9, move _10); - StorageDead(_10); - StorageDead(_9); switchInt(move _11) -> [0: bb3, otherwise: bb8]; } bb3: { + StorageDead(_10); + StorageDead(_9); StorageDead(_11); StorageLive(_14); StorageLive(_12); @@ -66,12 +66,12 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_13); _13 = ((*_2).3: u32); _14 = Ne(move _12, move _13); - StorageDead(_13); - StorageDead(_12); switchInt(move _14) -> [0: bb4, otherwise: bb7]; } bb4: { + StorageDead(_13); + StorageDead(_12); StorageDead(_14); StorageLive(_17); StorageLive(_15); @@ -79,42 +79,52 @@ fn returning(_1: &Blueprint, _2: &Blueprint) -> bool { StorageLive(_16); _16 = ((*_2).4: u32); _17 = Ne(move _15, move _16); - StorageDead(_16); - StorageDead(_15); switchInt(move _17) -> [0: bb5, otherwise: bb6]; } bb5: { + StorageDead(_16); + StorageDead(_15); StorageDead(_17); _0 = const true; goto -> bb11; } bb6: { + StorageDead(_16); + StorageDead(_15); _0 = const false; StorageDead(_17); goto -> bb11; } bb7: { + StorageDead(_13); + StorageDead(_12); _0 = const false; StorageDead(_14); goto -> bb11; } bb8: { + StorageDead(_10); + StorageDead(_9); _0 = const false; StorageDead(_11); goto -> bb11; } bb9: { + StorageDead(_7); + StorageDead(_6); _0 = const false; StorageDead(_8); goto -> bb11; } bb10: { + StorageDead(_4); + StorageDead(_3); _0 = const false; StorageDead(_5); goto -> bb11; diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir index b2ea96f033ef0..75f81c5aacaf2 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir @@ -40,16 +40,22 @@ fn step_forward(_1: u32, _2: usize) -> u32 { _5 = Eq(_4, const 1_isize); _6 = Not(move _5); StorageDead(_5); - StorageDead(_3); - StorageDead(_8); - switchInt(move _6) -> [0: bb3, otherwise: bb2]; + switchInt(move _6) -> [0: bb2, otherwise: bb3]; } bb2: { - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb3, unwind continue]; + StorageDead(_3); + StorageDead(_8); + goto -> bb4; } bb3: { + StorageDead(_3); + StorageDead(_8); + assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue]; + } + + bb4: { StorageDead(_6); StorageLive(_7); _7 = _2 as u32 (IntToInt); diff --git a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir index 2e51faeba5ae8..0d79f2de10d7b 100644 --- a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir @@ -63,17 +63,19 @@ fn int_range(_1: usize, _2: usize) -> () { _7 = Lt(move _5, move _6); StorageDead(_6); StorageDead(_5); - StorageDead(_16); - StorageDead(_15); switchInt(move _7) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_16); + StorageDead(_15); _8 = Option::::None; goto -> bb5; } bb3: { + StorageDead(_16); + StorageDead(_15); _9 = (_4.0: usize); StorageLive(_10); _10 = ::forward_unchecked(_9, const 1_usize) -> [return: bb4, unwind continue]; diff --git a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir index 26919dd98dd27..630babaa821a3 100644 --- a/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/mem_replace.mem_replace.PreCodegen.after.mir @@ -10,23 +10,53 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 { scope 2 { scope 3 { debug result => _0; - scope 6 (inlined std::ptr::write::) { + scope 16 (inlined std::ptr::write::) { debug dst => _1; debug src => _2; - scope 7 { + scope 17 { } } } scope 4 (inlined std::ptr::read::) { debug src => _1; scope 5 { + scope 6 (inlined std::ptr::read::runtime::) { + debug src => _1; + scope 7 (inlined intrinsics::is_aligned_and_not_null::) { + debug ptr => _1; + scope 8 (inlined ptr::const_ptr::::is_null) { + debug self => _1; + let mut _3: *const u8; + scope 9 { + scope 10 (inlined ptr::const_ptr::::is_null::runtime_impl) { + debug ptr => _3; + scope 11 (inlined ptr::const_ptr::::addr) { + debug self => _3; + scope 12 { + scope 13 (inlined ptr::const_ptr::::cast::<()>) { + debug self => _3; + } + } + } + } + } + } + scope 14 (inlined ptr::const_ptr::::is_aligned) { + debug self => _1; + scope 15 (inlined align_of::) { + } + } + } + } } } } } bb0: { + StorageLive(_3); _0 = (*_1); + StorageDead(_3); (*_1) = _2; return; } diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir index d76b46bdd94a0..9664ccfb094f7 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir @@ -66,17 +66,19 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_19); - StorageDead(_18); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_19); + StorageDead(_18); _9 = Option::::None; goto -> bb5; } bb3: { + StorageDead(_19); + StorageDead(_18); _10 = (_5.0: u32); StorageLive(_11); _11 = ::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 35f7356d47a61..dc8b46b6c08e3 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -66,17 +66,19 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_19); - StorageDead(_18); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_19); + StorageDead(_18); _9 = Option::::None; goto -> bb5; } bb3: { + StorageDead(_19); + StorageDead(_18); _10 = (_5.0: u32); StorageLive(_11); _11 = ::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb11]; diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir index 7360aa3e69826..fff713b5a795d 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir @@ -38,17 +38,19 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { _4 = Lt(move _2, move _3); StorageDead(_3); StorageDead(_2); - StorageDead(_8); - StorageDead(_7); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_8); + StorageDead(_7); _0 = Option::::None; goto -> bb4; } bb2: { + StorageDead(_8); + StorageDead(_7); _5 = ((*_1).0: u32); StorageLive(_6); _6 = ::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir index 61957082d8bb0..cc12c0122b7eb 100644 --- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir @@ -38,17 +38,19 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { _4 = Lt(move _2, move _3); StorageDead(_3); StorageDead(_2); - StorageDead(_8); - StorageDead(_7); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_8); + StorageDead(_7); _0 = Option::::None; goto -> bb4; } bb2: { + StorageDead(_8); + StorageDead(_7); _5 = ((*_1).0: u32); StorageLive(_6); _6 = ::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind continue]; diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir index 1488779f93b84..ddfd5b0fefc3e 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir @@ -12,30 +12,27 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 let _10: &usize; let _11: &usize; let mut _16: bool; - let mut _17: bool; - let _18: &usize; - let mut _23: bool; - let _24: &usize; - let mut _29: bool; - let mut _30: bool; - let _31: &usize; - let mut _36: bool; + let _17: &usize; + let mut _22: bool; + let _23: &usize; + let mut _28: bool; + let _29: &usize; + let mut _34: &&usize; + let mut _35: &&usize; + let mut _36: &&usize; let mut _37: &&usize; let mut _38: &&usize; let mut _39: &&usize; let mut _40: &&usize; let mut _41: &&usize; - let mut _42: &&usize; - let mut _43: &&usize; - let mut _44: &&usize; scope 1 { debug a => _4; debug b => _6; debug c => _8; debug d => _10; scope 2 (inlined cmp::impls::::le) { - debug self => _37; - debug other => _38; + debug self => _34; + debug other => _35; let mut _12: &usize; let mut _13: &usize; scope 3 (inlined cmp::impls::::le) { @@ -46,39 +43,39 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 } } scope 4 (inlined cmp::impls::::le) { - debug self => _41; - debug other => _42; - let mut _25: &usize; - let mut _26: &usize; + debug self => _36; + debug other => _37; + let mut _18: &usize; + let mut _19: &usize; scope 5 (inlined cmp::impls::::le) { - debug self => _25; - debug other => _26; - let mut _27: usize; - let mut _28: usize; + debug self => _18; + debug other => _19; + let mut _20: usize; + let mut _21: usize; } } scope 6 (inlined cmp::impls::::le) { - debug self => _39; - debug other => _40; - let mut _19: &usize; - let mut _20: &usize; + debug self => _38; + debug other => _39; + let mut _24: &usize; + let mut _25: &usize; scope 7 (inlined cmp::impls::::le) { - debug self => _19; - debug other => _20; - let mut _21: usize; - let mut _22: usize; + debug self => _24; + debug other => _25; + let mut _26: usize; + let mut _27: usize; } } scope 8 (inlined cmp::impls::::le) { - debug self => _43; - debug other => _44; - let mut _32: &usize; - let mut _33: &usize; + debug self => _40; + debug other => _41; + let mut _30: &usize; + let mut _31: &usize; scope 9 (inlined cmp::impls::::le) { - debug self => _32; - debug other => _33; - let mut _34: usize; - let mut _35: usize; + debug self => _30; + debug other => _31; + let mut _32: usize; + let mut _33: usize; } } } @@ -96,10 +93,9 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 StorageLive(_10); _9 = deref_copy (*_2); _10 = &((*_9).3: usize); - StorageLive(_17); StorageLive(_16); - StorageLive(_37); - StorageLive(_38); + StorageLive(_34); + StorageLive(_35); StorageLive(_11); _11 = _8; _12 = deref_copy _4; @@ -111,109 +107,109 @@ fn variant_a::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:7:25: 7:39], _2 _16 = Le(move _14, move _15); StorageDead(_15); StorageDead(_14); - StorageDead(_11); - StorageDead(_38); - StorageDead(_37); switchInt(move _16) -> [0: bb1, otherwise: bb2]; } bb1: { - _17 = const false; - goto -> bb3; + StorageDead(_11); + StorageDead(_35); + StorageDead(_34); + goto -> bb4; } bb2: { - StorageLive(_23); - StorageLive(_39); - StorageLive(_40); - StorageLive(_18); - _18 = _6; - _19 = deref_copy _10; - _20 = deref_copy _18; + StorageDead(_11); + StorageDead(_35); + StorageDead(_34); + StorageLive(_22); + StorageLive(_36); + StorageLive(_37); + StorageLive(_17); + _17 = _6; + _18 = deref_copy _10; + _19 = deref_copy _17; + StorageLive(_20); + _20 = (*_18); StorageLive(_21); _21 = (*_19); - StorageLive(_22); - _22 = (*_20); - _23 = Le(move _21, move _22); - StorageDead(_22); + _22 = Le(move _20, move _21); StorageDead(_21); - StorageDead(_18); - StorageDead(_40); - StorageDead(_39); - _17 = move _23; - goto -> bb3; + StorageDead(_20); + switchInt(move _22) -> [0: bb3, otherwise: bb8]; } bb3: { - StorageDead(_23); - StorageDead(_16); - switchInt(move _17) -> [0: bb4, otherwise: bb8]; + StorageDead(_17); + StorageDead(_37); + StorageDead(_36); + goto -> bb4; } bb4: { - StorageLive(_30); - StorageLive(_29); - StorageLive(_41); - StorageLive(_42); - StorageLive(_24); - _24 = _4; - _25 = deref_copy _8; - _26 = deref_copy _24; + StorageLive(_28); + StorageLive(_38); + StorageLive(_39); + StorageLive(_23); + _23 = _4; + _24 = deref_copy _8; + _25 = deref_copy _23; + StorageLive(_26); + _26 = (*_24); StorageLive(_27); _27 = (*_25); - StorageLive(_28); - _28 = (*_26); - _29 = Le(move _27, move _28); - StorageDead(_28); + _28 = Le(move _26, move _27); StorageDead(_27); - StorageDead(_24); - StorageDead(_42); - StorageDead(_41); - switchInt(move _29) -> [0: bb5, otherwise: bb6]; + StorageDead(_26); + switchInt(move _28) -> [0: bb5, otherwise: bb6]; } bb5: { - _30 = const false; + StorageDead(_23); + StorageDead(_39); + StorageDead(_38); + _0 = const false; goto -> bb7; } bb6: { - StorageLive(_36); - StorageLive(_43); - StorageLive(_44); - StorageLive(_31); - _31 = _10; - _32 = deref_copy _6; - _33 = deref_copy _31; - StorageLive(_34); - _34 = (*_32); - StorageLive(_35); - _35 = (*_33); - _36 = Le(move _34, move _35); - StorageDead(_35); - StorageDead(_34); - StorageDead(_31); - StorageDead(_44); - StorageDead(_43); - _30 = move _36; + StorageDead(_23); + StorageDead(_39); + StorageDead(_38); + StorageLive(_40); + StorageLive(_41); + StorageLive(_29); + _29 = _10; + _30 = deref_copy _6; + _31 = deref_copy _29; + StorageLive(_32); + _32 = (*_30); + StorageLive(_33); + _33 = (*_31); + _0 = Le(move _32, move _33); + StorageDead(_33); + StorageDead(_32); + StorageDead(_29); + StorageDead(_41); + StorageDead(_40); goto -> bb7; } bb7: { - StorageDead(_36); - StorageDead(_29); - _0 = move _30; + StorageDead(_28); goto -> bb9; } bb8: { + StorageDead(_17); + StorageDead(_37); + StorageDead(_36); _0 = const true; goto -> bb9; } bb9: { - StorageDead(_30); - StorageDead(_17); + StorageDead(_22); + StorageDead(_16); StorageDead(_10); StorageDead(_8); StorageDead(_6); diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index bab9f0b58aae4..7e70c6290a8b8 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -13,9 +13,6 @@ fn variant_b::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:11:25: 11:41], let mut _11: bool; let mut _12: bool; let mut _13: bool; - let mut _14: bool; - let mut _15: bool; - let mut _16: bool; scope 1 { debug a => _4; debug b => _6; @@ -32,64 +29,46 @@ fn variant_b::{closure#0}(_1: &mut [closure@$DIR/slice_filter.rs:11:25: 11:41], _8 = ((*_7).2: usize); _9 = deref_copy (*_2); _10 = ((*_9).3: usize); - StorageLive(_12); StorageLive(_11); _11 = Le(_4, _8); - switchInt(move _11) -> [0: bb1, otherwise: bb2]; + switchInt(move _11) -> [0: bb2, otherwise: bb1]; } bb1: { - _12 = const false; - goto -> bb3; + StorageLive(_12); + _12 = Le(_10, _6); + switchInt(move _12) -> [0: bb2, otherwise: bb6]; } bb2: { StorageLive(_13); - _13 = Le(_10, _6); - _12 = move _13; - goto -> bb3; + _13 = Le(_8, _4); + switchInt(move _13) -> [0: bb3, otherwise: bb4]; } bb3: { - StorageDead(_13); - StorageDead(_11); - switchInt(move _12) -> [0: bb4, otherwise: bb8]; + _0 = const false; + goto -> bb5; } bb4: { - StorageLive(_15); - StorageLive(_14); - _14 = Le(_8, _4); - switchInt(move _14) -> [0: bb5, otherwise: bb6]; + _0 = Le(_6, _10); + goto -> bb5; } bb5: { - _15 = const false; + StorageDead(_13); goto -> bb7; } bb6: { - StorageLive(_16); - _16 = Le(_6, _10); - _15 = move _16; + _0 = const true; goto -> bb7; } bb7: { - StorageDead(_16); - StorageDead(_14); - _0 = move _15; - goto -> bb9; - } - - bb8: { - _0 = const true; - goto -> bb9; - } - - bb9: { - StorageDead(_15); StorageDead(_12); + StorageDead(_11); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir index 07a58309ee46b..8590c9d3b8375 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir @@ -58,16 +58,17 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_3); _3 = Len((*_1)); _4 = Lt(_2, move _3); - StorageDead(_3); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_3); _0 = const Option::<&mut u32>::None; goto -> bb3; } bb2: { + StorageDead(_3); StorageLive(_8); StorageLive(_5); _5 = &raw mut (*_1); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir index 07a58309ee46b..8590c9d3b8375 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir @@ -58,16 +58,17 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_3); _3 = Len((*_1)); _4 = Lt(_2, move _3); - StorageDead(_3); switchInt(move _4) -> [0: bb1, otherwise: bb2]; } bb1: { + StorageDead(_3); _0 = const Option::<&mut u32>::None; goto -> bb3; } bb2: { + StorageDead(_3); StorageLive(_8); StorageLive(_5); _5 = &raw mut (*_1); diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir index 2f5d356a26df8..8dd2cd7900f3f 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir @@ -17,37 +17,50 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _14: usize; let _15: usize; + let _16: usize; scope 4 { - debug this => std::ops::Range{ .0 => _14, .1 => _15, }; + debug this => std::ops::Range{ .0 => _15, .1 => _16, }; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 7 (inlined ptr::mut_ptr::::as_mut_ptr) { + scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 8 (inlined ptr::mut_ptr::::add) { + scope 12 (inlined ptr::mut_ptr::::add) { debug self => _7; debug count => _3; - scope 9 { + scope 13 { } } - scope 10 (inlined slice_from_raw_parts_mut::) { + scope 14 (inlined slice_from_raw_parts_mut::) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 11 (inlined ptr::mut_ptr::::cast::<()>) { + scope 15 (inlined ptr::mut_ptr::::cast::<()>) { debug self => _8; } - scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 13 { + scope 17 { + } + } + } + } + scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { + debug this => std::ops::Range{ .0 => _15, .1 => _16, }; + debug slice => _5; + scope 8 (inlined ptr::mut_ptr::::len) { + debug self => _5; + let mut _14: *const [u32]; + scope 9 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _14; + scope 10 { } } } @@ -63,9 +76,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); + StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_6); + StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -86,9 +100,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_6); - StorageDead(_14); + StorageDead(_16); StorageDead(_15); + StorageDead(_14); + StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); return; diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir index 2f5d356a26df8..8dd2cd7900f3f 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir @@ -17,37 +17,50 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> debug slice => _5; let mut _7: *mut u32; let mut _8: *mut u32; - let _14: usize; let _15: usize; + let _16: usize; scope 4 { - debug this => std::ops::Range{ .0 => _14, .1 => _15, }; + debug this => std::ops::Range{ .0 => _15, .1 => _16, }; scope 5 { let _6: usize; scope 6 { debug new_len => _6; - scope 7 (inlined ptr::mut_ptr::::as_mut_ptr) { + scope 11 (inlined ptr::mut_ptr::::as_mut_ptr) { debug self => _5; } - scope 8 (inlined ptr::mut_ptr::::add) { + scope 12 (inlined ptr::mut_ptr::::add) { debug self => _7; debug count => _3; - scope 9 { + scope 13 { } } - scope 10 (inlined slice_from_raw_parts_mut::) { + scope 14 (inlined slice_from_raw_parts_mut::) { debug data => _8; debug len => _6; let mut _9: *mut (); - scope 11 (inlined ptr::mut_ptr::::cast::<()>) { + scope 15 (inlined ptr::mut_ptr::::cast::<()>) { debug self => _8; } - scope 12 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { + scope 16 (inlined std::ptr::from_raw_parts_mut::<[u32]>) { debug data_address => _9; debug metadata => _6; let mut _10: *const (); let mut _11: std::ptr::metadata::PtrComponents<[u32]>; let mut _12: std::ptr::metadata::PtrRepr<[u32]>; - scope 13 { + scope 17 { + } + } + } + } + scope 7 (inlined as SliceIndex<[T]>>::get_unchecked_mut::runtime::) { + debug this => std::ops::Range{ .0 => _15, .1 => _16, }; + debug slice => _5; + scope 8 (inlined ptr::mut_ptr::::len) { + debug self => _5; + let mut _14: *const [u32]; + scope 9 (inlined std::ptr::metadata::<[u32]>) { + debug ptr => _14; + scope 10 { } } } @@ -63,9 +76,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> _4 = move (_2.1: usize); StorageLive(_5); _5 = &raw mut (*_1); + StorageLive(_6); StorageLive(_14); StorageLive(_15); - StorageLive(_6); + StorageLive(_16); _6 = SubUnchecked(_4, _3); StorageLive(_8); StorageLive(_7); @@ -86,9 +100,10 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - StorageDead(_6); - StorageDead(_14); + StorageDead(_16); StorageDead(_15); + StorageDead(_14); + StorageDead(_6); StorageDead(_5); _0 = &mut (*_13); return; diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir index 4edf4b4fb444f..4afe2eda188fb 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir @@ -75,17 +75,19 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_22); - StorageDead(_21); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_22); + StorageDead(_21); _9 = Option::::None; goto -> bb5; } bb3: { + StorageDead(_22); + StorageDead(_21); _10 = (_5.0: usize); StorageLive(_11); _11 = ::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable]; diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index 8bd072fd625e7..48092608d9ca2 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -75,17 +75,19 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { _8 = Lt(move _6, move _7); StorageDead(_7); StorageDead(_6); - StorageDead(_22); - StorageDead(_21); switchInt(move _8) -> [0: bb2, otherwise: bb3]; } bb2: { + StorageDead(_22); + StorageDead(_21); _9 = Option::::None; goto -> bb5; } bb3: { + StorageDead(_22); + StorageDead(_21); _10 = (_5.0: usize); StorageLive(_11); _11 = ::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb12]; diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir index 70efdbf4b34d9..566b6af95baad 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-abort.mir @@ -19,17 +19,16 @@ fn array_casts() -> () { let mut _18: &usize; let _19: usize; let mut _22: bool; - let mut _23: bool; + let mut _23: usize; let mut _24: usize; - let mut _25: usize; - let mut _26: !; - let _28: !; - let mut _29: core::panicking::AssertKind; - let mut _30: &usize; - let _31: &usize; - let mut _32: &usize; - let _33: &usize; - let mut _34: std::option::Option>; + let mut _25: !; + let _27: !; + let mut _28: core::panicking::AssertKind; + let mut _29: &usize; + let _30: &usize; + let mut _31: &usize; + let _32: &usize; + let mut _33: std::option::Option>; scope 1 { debug x => _1; let _2: *mut usize; @@ -45,15 +44,15 @@ fn array_casts() -> () { debug p => _9; let _20: &usize; let _21: &usize; - let mut _35: &usize; + let mut _34: &usize; scope 6 { } scope 7 { debug left_val => _20; debug right_val => _21; - let _27: core::panicking::AssertKind; + let _26: core::panicking::AssertKind; scope 8 { - debug kind => _27; + debug kind => _26; } } } @@ -110,9 +109,9 @@ fn array_casts() -> () { _15 = (*_16); _14 = &_15; StorageLive(_18); - _35 = const _; - Retag(_35); - _18 = &(*_35); + _34 = const _; + Retag(_34); + _18 = &(*_34); _13 = (move _14, move _18); Retag(_13); StorageDead(_18); @@ -125,39 +124,16 @@ fn array_casts() -> () { Retag(_21); StorageLive(_22); StorageLive(_23); + _23 = (*_20); StorageLive(_24); - _24 = (*_20); - StorageLive(_25); - _25 = (*_21); - _23 = Eq(move _24, move _25); - StorageDead(_25); - StorageDead(_24); - _22 = Not(move _23); - StorageDead(_23); + _24 = (*_21); + _22 = Eq(move _23, move _24); switchInt(move _22) -> [0: bb4, otherwise: bb3]; } bb3: { - StorageLive(_27); - _27 = core::panicking::AssertKind::Eq; - StorageLive(_28); - StorageLive(_29); - _29 = move _27; - StorageLive(_30); - StorageLive(_31); - _31 = &(*_20); - _30 = &(*_31); - StorageLive(_32); - StorageLive(_33); - _33 = &(*_21); - _32 = &(*_33); - StorageLive(_34); - _34 = Option::>::None; - Retag(_34); - _28 = core::panicking::assert_failed::(move _29, move _30, move _32, move _34) -> unwind unreachable; - } - - bb4: { + StorageDead(_24); + StorageDead(_23); _12 = const (); StorageDead(_22); StorageDead(_21); @@ -173,4 +149,26 @@ fn array_casts() -> () { StorageDead(_1); return; } + + bb4: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_26); + _26 = core::panicking::AssertKind::Eq; + StorageLive(_27); + StorageLive(_28); + _28 = move _26; + StorageLive(_29); + StorageLive(_30); + _30 = &(*_20); + _29 = &(*_30); + StorageLive(_31); + StorageLive(_32); + _32 = &(*_21); + _31 = &(*_32); + StorageLive(_33); + _33 = Option::>::None; + Retag(_33); + _27 = core::panicking::assert_failed::(move _28, move _29, move _31, move _33) -> unwind unreachable; + } } diff --git a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index cfa9628d49841..d0d3176320bab 100644 --- a/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -19,17 +19,16 @@ fn array_casts() -> () { let mut _18: &usize; let _19: usize; let mut _22: bool; - let mut _23: bool; + let mut _23: usize; let mut _24: usize; - let mut _25: usize; - let mut _26: !; - let _28: !; - let mut _29: core::panicking::AssertKind; - let mut _30: &usize; - let _31: &usize; - let mut _32: &usize; - let _33: &usize; - let mut _34: std::option::Option>; + let mut _25: !; + let _27: !; + let mut _28: core::panicking::AssertKind; + let mut _29: &usize; + let _30: &usize; + let mut _31: &usize; + let _32: &usize; + let mut _33: std::option::Option>; scope 1 { debug x => _1; let _2: *mut usize; @@ -45,15 +44,15 @@ fn array_casts() -> () { debug p => _9; let _20: &usize; let _21: &usize; - let mut _35: &usize; + let mut _34: &usize; scope 6 { } scope 7 { debug left_val => _20; debug right_val => _21; - let _27: core::panicking::AssertKind; + let _26: core::panicking::AssertKind; scope 8 { - debug kind => _27; + debug kind => _26; } } } @@ -110,9 +109,9 @@ fn array_casts() -> () { _15 = (*_16); _14 = &_15; StorageLive(_18); - _35 = const _; - Retag(_35); - _18 = &(*_35); + _34 = const _; + Retag(_34); + _18 = &(*_34); _13 = (move _14, move _18); Retag(_13); StorageDead(_18); @@ -125,39 +124,16 @@ fn array_casts() -> () { Retag(_21); StorageLive(_22); StorageLive(_23); + _23 = (*_20); StorageLive(_24); - _24 = (*_20); - StorageLive(_25); - _25 = (*_21); - _23 = Eq(move _24, move _25); - StorageDead(_25); - StorageDead(_24); - _22 = Not(move _23); - StorageDead(_23); + _24 = (*_21); + _22 = Eq(move _23, move _24); switchInt(move _22) -> [0: bb4, otherwise: bb3]; } bb3: { - StorageLive(_27); - _27 = core::panicking::AssertKind::Eq; - StorageLive(_28); - StorageLive(_29); - _29 = move _27; - StorageLive(_30); - StorageLive(_31); - _31 = &(*_20); - _30 = &(*_31); - StorageLive(_32); - StorageLive(_33); - _33 = &(*_21); - _32 = &(*_33); - StorageLive(_34); - _34 = Option::>::None; - Retag(_34); - _28 = core::panicking::assert_failed::(move _29, move _30, move _32, move _34) -> unwind continue; - } - - bb4: { + StorageDead(_24); + StorageDead(_23); _12 = const (); StorageDead(_22); StorageDead(_21); @@ -173,4 +149,26 @@ fn array_casts() -> () { StorageDead(_1); return; } + + bb4: { + StorageDead(_24); + StorageDead(_23); + StorageLive(_26); + _26 = core::panicking::AssertKind::Eq; + StorageLive(_27); + StorageLive(_28); + _28 = move _26; + StorageLive(_29); + StorageLive(_30); + _30 = &(*_20); + _29 = &(*_30); + StorageLive(_31); + StorageLive(_32); + _32 = &(*_21); + _31 = &(*_32); + StorageLive(_33); + _33 = Option::>::None; + Retag(_33); + _27 = core::panicking::assert_failed::(move _28, move _29, move _31, move _33) -> unwind continue; + } } diff --git a/tests/run-coverage/lazy_boolean.coverage b/tests/run-coverage/lazy_boolean.coverage index 2d927a083560f..8f14082ef6825 100644 --- a/tests/run-coverage/lazy_boolean.coverage +++ b/tests/run-coverage/lazy_boolean.coverage @@ -32,7 +32,7 @@ ^0 LL| | LL| | if - LL| 1| ! + LL| | ! LL| 1| is_true LL| 0| { LL| 0| a = 2 diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs index e0dded1521760..2c0571a7bdd3e 100644 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs +++ b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs @@ -1,19 +1,18 @@ +// check-pass + fn and_chain() { let z; if true && { z = 3; true} && z == 3 {} - //~^ ERROR E0381 } fn and_chain_2() { let z; true && { z = 3; true} && z == 3; - //~^ ERROR E0381 } fn or_chain() { let z; if false || { z = 3; false} || z == 3 {} - //~^ ERROR E0381 } fn main() { diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr deleted file mode 100644 index 30d5a6779fcd7..0000000000000 --- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:3:34 - | -LL | let z; - | - binding declared here but left uninitialized -LL | if true && { z = 3; true} && z == 3 {} - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:9:31 - | -LL | let z; - | - binding declared here but left uninitialized -LL | true && { z = 3; true} && z == 3; - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error[E0381]: used binding `z` is possibly-uninitialized - --> $DIR/chains-without-let.rs:15:36 - | -LL | let z; - | - binding declared here but left uninitialized -LL | if false || { z = 3; false} || z == 3 {} - | ----- ^ `z` used here but it is possibly-uninitialized - | | - | binding initialized here in some conditions - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0381`.