Skip to content

Commit 1e739d7

Browse files
committed
Do not attempt to const-prop unsize.
1 parent 294a797 commit 1e739d7

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
532532

533533
return None;
534534
}
535+
// We do not track pointers, and unsized lengths are handled by `NormalizeArrayLen`.
536+
Rvalue::Cast(CastKind::Pointer(_), ..) => return None,
535537

536538
// There's no other checking to do at this time.
537539
Rvalue::Aggregate(..)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@
2828
StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19
2929
StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
3030
_6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
31-
- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
31+
_7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3232
- _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3333
- 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
3534
+ _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3635
+ assert(const true, "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
3736
}
3837

3938
bb1: {
40-
- _1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
41-
+ _1 = const 2_u32; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
39+
_1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
4240
StorageDead(_6); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34
4341
StorageDead(_4); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34
4442
StorageDead(_2); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@
2828
StorageDead(_3); // scope 0 at $DIR/slice_len.rs:+1:18: +1:19
2929
StorageLive(_6); // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
3030
_6 = const 1_usize; // scope 0 at $DIR/slice_len.rs:+1:31: +1:32
31-
- _7 = Len((*_2)); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
31+
_7 = const 3_usize; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3232
- _8 = Lt(_6, _7); // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3333
- 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
3534
+ _8 = const true; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
3635
+ assert(const true, "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
3736
}
3837

3938
bb1: {
40-
- _1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
41-
+ _1 = const 2_u32; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
39+
_1 = (*_2)[_6]; // scope 0 at $DIR/slice_len.rs:+1:5: +1:33
4240
StorageDead(_6); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34
4341
StorageDead(_4); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34
4442
StorageDead(_2); // scope 0 at $DIR/slice_len.rs:+1:33: +1:34

tests/mir-opt/const_prop/slice_len.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// unit-test: ConstProp
2-
// compile-flags: -Zmir-enable-passes=+InstCombine
2+
// compile-flags: -Zmir-enable-passes=+InstCombine,+NormalizeArrayLen
33
// EMIT_MIR_FOR_EACH_BIT_WIDTH
44

55
// EMIT_MIR slice_len.main.ConstProp.diff

0 commit comments

Comments
 (0)