Skip to content

Commit c3af456

Browse files
authored
Rollup merge of rust-lang#105930 - JakobDegen:nal-unsound, r=oli-obk
Disable `NormalizeArrayLen` cc rust-lang#105929 r? mir-opt
2 parents 52fe5a1 + 4251289 commit c3af456

5 files changed

+12
-19
lines changed

compiler/rustc_mir_transform/src/normalize_array_len.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct NormalizeArrayLen;
1616

1717
impl<'tcx> MirPass<'tcx> for NormalizeArrayLen {
1818
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
19-
sess.mir_opt_level() >= 4
19+
// See #105929
20+
sess.mir_opt_level() >= 4 && sess.opts.unstable_opts.unsound_mir_opts
2021
}
2122

2223
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

src/test/mir-opt/const_prop/slice_len.main.ConstProp.32bit.diff

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
let mut _7: usize; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33
1313
let mut _8: bool; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33
1414
let mut _9: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19
15-
let mut _10: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19
1615

1716
bb0: {
1817
StorageLive(_1); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
@@ -25,16 +24,14 @@
2524
// + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) }
2625
_4 = _9; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
2726
_3 = _4; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
28-
StorageLive(_10); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
29-
_10 = _3; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
3027
_2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
3128
StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19
3229
StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
3330
_6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
34-
_7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
35-
StorageDead(_10); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
31+
- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3632
- _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3733
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
34+
+ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3835
+ _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3936
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
4037
}

src/test/mir-opt/const_prop/slice_len.main.ConstProp.64bit.diff

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
let mut _7: usize; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33
1313
let mut _8: bool; // in scope 0 at $DIR/slice_len.rs:+1:5: +1:33
1414
let mut _9: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19
15-
let mut _10: &[u32; 3]; // in scope 0 at $DIR/slice_len.rs:+1:6: +1:19
1615

1716
bb0: {
1817
StorageLive(_1); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
@@ -25,16 +24,14 @@
2524
// + literal: Const { ty: &[u32; 3], val: Unevaluated(main, [], Some(promoted[0])) }
2625
_4 = _9; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
2726
_3 = _4; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
28-
StorageLive(_10); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
29-
_10 = _3; // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
3027
_2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:+1:6: +1:19
3128
StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19
3229
StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
3330
_6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
34-
_7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
35-
StorageDead(_10); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
31+
- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3632
- _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3733
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
34+
+ _7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3835
+ _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3936
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> bb1; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
4037
}

src/test/mir-opt/issue_76432.test.SimplifyComparisonIntegral.diff

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:+3:70: +3:84
2323
let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:+3:70: +3:84
2424
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
25-
let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
2625
scope 1 {
2726
debug v => _2; // in scope 1 at $DIR/issue_76432.rs:+1:9: +1:10
2827
let _13: &T; // in scope 1 at $DIR/issue_76432.rs:+3:10: +3:16
@@ -52,17 +51,16 @@
5251
StorageDead(_6); // scope 0 at $DIR/issue_76432.rs:+1:28: +1:29
5352
_4 = &_5; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
5453
_3 = _4; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
55-
StorageLive(_23); // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
56-
_23 = _3; // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
5754
_2 = move _3 as &[T] (Pointer(Unsize)); // scope 0 at $DIR/issue_76432.rs:+1:19: +1:29
5855
StorageDead(_3); // scope 0 at $DIR/issue_76432.rs:+1:28: +1:29
5956
StorageDead(_4); // scope 0 at $DIR/issue_76432.rs:+1:29: +1:30
6057
StorageLive(_9); // scope 1 at $DIR/issue_76432.rs:+2:5: +5:6
61-
_10 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
62-
StorageDead(_23); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
58+
_10 = Len((*_2)); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
6359
_11 = const 3_usize; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
64-
_12 = const true; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
65-
goto -> bb2; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
60+
- _12 = Eq(move _10, const 3_usize); // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
61+
- switchInt(move _12) -> [0: bb1, otherwise: bb2]; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
62+
+ nop; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
63+
+ switchInt(move _10) -> [3: bb2, otherwise: bb1]; // scope 1 at $DIR/issue_76432.rs:+3:9: +3:33
6664
}
6765

6866
bb1: {

src/test/mir-opt/lower_array_len_e2e.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z mir-opt-level=4
1+
// compile-flags: -Z mir-opt-level=4 -Zunsound-mir-opts
22

33
// EMIT_MIR lower_array_len_e2e.array_bound.PreCodegen.after.mir
44
pub fn array_bound<const N: usize>(index: usize, slice: &[u8; N]) -> u8 {

0 commit comments

Comments
 (0)