diff --git a/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff b/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff new file mode 100644 index 00000000000..94b8e6a7f2f --- /dev/null +++ b/tests/mir-opt/reference_prop.debuginfo.ReferencePropagation.diff @@ -0,0 +1,151 @@ +- // MIR for `debuginfo` before ReferencePropagation ++ // MIR for `debuginfo` after ReferencePropagation + + fn debuginfo() -> () { + let mut _0: (); // return place in scope 0 at $DIR/reference_prop.rs:+0:16: +0:16 + let _1: &mut u8; // in scope 0 at $DIR/reference_prop.rs:+3:9: +3:19 + let mut _2: u8; // in scope 0 at $DIR/reference_prop.rs:+3:27: +3:31 + let _4: debuginfo::T; // in scope 0 at $DIR/reference_prop.rs:+4:18: +4:22 + let _6: (); // in scope 0 at $DIR/reference_prop.rs:+9:5: +12:6 + let mut _7: std::option::Option; // in scope 0 at $DIR/reference_prop.rs:+9:11: +9:18 + let mut _8: isize; // in scope 0 at $DIR/reference_prop.rs:+10:9: +10:13 + let mut _10: &[i32]; // in scope 0 at $DIR/reference_prop.rs:+16:82: +16:94 + let _11: &[i32]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:94 + let mut _12: &[i32; 10]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:90 + let _13: [i32; 10]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:90 + let mut _14: std::ops::RangeFull; // in scope 0 at $DIR/reference_prop.rs:+16:91: +16:93 + let mut _15: usize; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79 + let mut _16: usize; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79 + let mut _17: bool; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79 + scope 1 { +- debug ref_mut_u8 => _1; // in scope 1 at $DIR/reference_prop.rs:+3:9: +3:19 ++ debug ref_mut_u8 => &_2; // in scope 1 at $DIR/reference_prop.rs:+3:9: +3:19 + let _3: &u8; // in scope 1 at $DIR/reference_prop.rs:+4:9: +4:14 + let mut _23: &debuginfo::T; // in scope 1 at $DIR/reference_prop.rs:+4:17: +4:24 + scope 2 { +- debug field => _3; // in scope 2 at $DIR/reference_prop.rs:+4:9: +4:14 ++ debug field => &((*_23).0: u8); // in scope 2 at $DIR/reference_prop.rs:+4:9: +4:14 + let _5: &u8; // in scope 2 at $DIR/reference_prop.rs:+7:9: +7:17 + scope 3 { +- debug reborrow => _5; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17 ++ debug reborrow => _1; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17 + let _9: &i32; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31 + let mut _22: &std::option::Option; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31 + scope 4 { +- debug variant_field => _9; // in scope 4 at $DIR/reference_prop.rs:+11:14: +11:31 ++ debug variant_field => &(((*_22) as Some).0: i32); // in scope 4 at $DIR/reference_prop.rs:+11:14: +11:31 + } + scope 5 { +- debug constant_index => _18; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34 ++ debug constant_index => &(*_10)[1 of 3]; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34 + debug subslice => _19; // in scope 5 at $DIR/reference_prop.rs:+16:36: +16:44 + debug constant_index_from_end => _20; // in scope 5 at $DIR/reference_prop.rs:+16:51: +16:78 + let _18: &i32; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34 + let _19: &[i32]; // in scope 5 at $DIR/reference_prop.rs:+16:36: +16:44 + let _20: &i32; // in scope 5 at $DIR/reference_prop.rs:+16:51: +16:78 + let mut _21: &[i32; 10]; // in scope 5 at $DIR/reference_prop.rs:+16:83: +16:90 + } + } + } + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+3:9: +3:19 + StorageLive(_2); // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31 + _2 = const 5_u8; // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31 + _1 = &mut _2; // scope 0 at $DIR/reference_prop.rs:+3:22: +3:31 +- StorageLive(_3); // scope 1 at $DIR/reference_prop.rs:+4:9: +4:14 + _23 = const _; // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24 + // mir::Constant + // + span: $DIR/reference_prop.rs:463:17: 463:24 + // + literal: Const { ty: &T, val: Unevaluated(debuginfo, [], Some(promoted[2])) } +- _3 = &((*_23).0: u8); // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24 +- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+7:9: +7:17 +- _5 = &(*_1); // scope 2 at $DIR/reference_prop.rs:+7:20: +7:32 +- StorageLive(_6); // scope 3 at $DIR/reference_prop.rs:+9:5: +12:6 + StorageLive(_7); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18 + _7 = Option::::Some(const 0_i32); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18 + _8 = discriminant(_7); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18 + switchInt(move _8) -> [0: bb3, 1: bb1, otherwise: bb2]; // scope 3 at $DIR/reference_prop.rs:+9:5: +9:18 + } + + bb1: { +- StorageLive(_9); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31 + _22 = const _; // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31 + // mir::Constant + // + span: $DIR/reference_prop.rs:470:14: 470:31 + // + literal: Const { ty: &Option, val: Unevaluated(debuginfo, [], Some(promoted[1])) } +- _9 = &(((*_22) as Some).0: i32); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31 +- _6 = const (); // scope 4 at $DIR/reference_prop.rs:+11:36: +11:38 +- StorageDead(_9); // scope 3 at $DIR/reference_prop.rs:+11:37: +11:38 + goto -> bb4; // scope 3 at $DIR/reference_prop.rs:+11:37: +11:38 + } + + bb2: { + unreachable; // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18 + } + + bb3: { +- _6 = const (); // scope 3 at $DIR/reference_prop.rs:+10:17: +10:19 + goto -> bb4; // scope 3 at $DIR/reference_prop.rs:+10:17: +10:19 + } + + bb4: { + StorageDead(_7); // scope 3 at $DIR/reference_prop.rs:+12:5: +12:6 +- StorageDead(_6); // scope 3 at $DIR/reference_prop.rs:+12:5: +12:6 + StorageLive(_10); // scope 5 at $DIR/reference_prop.rs:+16:82: +16:94 + StorageLive(_11); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:94 + StorageLive(_12); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90 + _21 = const _; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90 + // mir::Constant + // + span: $DIR/reference_prop.rs:475:83: 475:90 + // + literal: Const { ty: &[i32; 10], val: Unevaluated(debuginfo, [], Some(promoted[0])) } + _12 = &(*_21); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90 + StorageLive(_14); // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93 + _14 = RangeFull; // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93 + _11 = <[i32; 10] as Index>::index(move _12, move _14) -> bb5; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:94 + // mir::Constant + // + span: $DIR/reference_prop.rs:475:83: 475:94 + // + literal: Const { ty: for<'a> fn(&'a [i32; 10], RangeFull) -> &'a <[i32; 10] as Index>::Output {<[i32; 10] as Index>::index}, val: Value() } + } + + bb5: { + StorageDead(_14); // scope 5 at $DIR/reference_prop.rs:+16:93: +16:94 + StorageDead(_12); // scope 5 at $DIR/reference_prop.rs:+16:93: +16:94 + _10 = &(*_11); // scope 5 at $DIR/reference_prop.rs:+16:82: +16:94 + _15 = Len((*_10)); // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79 + _16 = const 3_usize; // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79 + _17 = Ge(move _15, move _16); // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79 + switchInt(move _17) -> [0: bb7, otherwise: bb6]; // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79 + } + + bb6: { +- StorageLive(_18); // scope 5 at $DIR/reference_prop.rs:+16:16: +16:34 +- _18 = &(*_10)[1 of 3]; // scope 5 at $DIR/reference_prop.rs:+16:16: +16:34 + StorageLive(_19); // scope 5 at $DIR/reference_prop.rs:+16:36: +16:44 + _19 = &(*_10)[2:-1]; // scope 5 at $DIR/reference_prop.rs:+16:36: +16:44 + StorageLive(_20); // scope 5 at $DIR/reference_prop.rs:+16:51: +16:78 + _20 = &(*_10)[-1 of 3]; // scope 5 at $DIR/reference_prop.rs:+16:51: +16:78 + _0 = const (); // scope 5 at $DIR/reference_prop.rs:+16:95: +17:6 + StorageDead(_20); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6 + StorageDead(_19); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6 +- StorageDead(_18); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6 + goto -> bb8; // scope 3 at $DIR/reference_prop.rs:+16:5: +17:6 + } + + bb7: { + _0 = const (); // scope 3 at $DIR/reference_prop.rs:+17:6: +17:6 + goto -> bb8; // scope 3 at $DIR/reference_prop.rs:+16:5: +17:6 + } + + bb8: { +- StorageDead(_5); // scope 2 at $DIR/reference_prop.rs:+18:1: +18:2 +- StorageDead(_3); // scope 1 at $DIR/reference_prop.rs:+18:1: +18:2 + StorageDead(_2); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2 + StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2 + StorageDead(_11); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2 + StorageDead(_10); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2 + return; // scope 0 at $DIR/reference_prop.rs:+18:2: +18:2 + } + } + diff --git a/tests/mir-opt/reference_prop.rs b/tests/mir-opt/reference_prop.rs index 6301ee839e9..207658860d2 100644 --- a/tests/mir-opt/reference_prop.rs +++ b/tests/mir-opt/reference_prop.rs @@ -456,6 +456,26 @@ fn unique_with_copies() { unsafe { opaque(*y) }; } +fn debuginfo() { + struct T(u8); + + let ref_mut_u8 = &mut 5_u8; + let field = &T(0).0; + + // Verify that we don't emit `&*` in debuginfo. + let reborrow = &*ref_mut_u8; + + match Some(0) { + None => {} + Some(ref variant_field) => {} + } + + // `constant_index_from_end` and `subslice` should not be promoted, as their value depends + // on the slice length. + if let [_, ref constant_index, subslice @ .., ref constant_index_from_end] = &[6; 10][..] { + } +} + fn main() { let mut x = 5_usize; let mut y = 7_usize; @@ -469,6 +489,7 @@ fn main() { maybe_dead(true); mut_raw_then_mut_shr(); unique_with_copies(); + debuginfo(); } // EMIT_MIR reference_prop.reference_propagation.ReferencePropagation.diff @@ -481,3 +502,4 @@ fn main() { // EMIT_MIR reference_prop.maybe_dead.ReferencePropagation.diff // EMIT_MIR reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff // EMIT_MIR reference_prop.unique_with_copies.ReferencePropagation.diff +// EMIT_MIR reference_prop.debuginfo.ReferencePropagation.diff