From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/mir-opt/const_prop/address_of_pair.rs | 1 + tests/mir-opt/const_prop/aggregate.rs | 1 + tests/mir-opt/const_prop/array_index.rs | 1 + tests/mir-opt/const_prop/bad_op_div_by_zero.rs | 1 + tests/mir-opt/const_prop/bad_op_mod_by_zero.rs | 1 + .../const_prop/bad_op_unsafe_oob_for_slices.rs | 1 + tests/mir-opt/const_prop/boolean_identities.rs | 1 + tests/mir-opt/const_prop/boxes.rs | 1 + tests/mir-opt/const_prop/cast.rs | 1 + .../checked_add.main.ConstProp.panic-abort.diff | 2 +- .../checked_add.main.ConstProp.panic-unwind.diff | 2 +- tests/mir-opt/const_prop/checked_add.rs | 1 + .../const_prop/const_prop_fails_gracefully.rs | 1 + .../const_prop/control_flow_simplification.rs | 1 + tests/mir-opt/const_prop/discriminant.rs | 1 + .../indirect.main.ConstProp.panic-abort.diff | 2 +- .../indirect.main.ConstProp.panic-unwind.diff | 2 +- tests/mir-opt/const_prop/indirect.rs | 1 + .../indirect_mutation.bar.ConstProp.diff | 41 ++++++++++++++++ .../indirect_mutation.foo.ConstProp.diff | 35 ++++++++++++++ tests/mir-opt/const_prop/indirect_mutation.rs | 41 ++++++++++++++++ ...nherit_overflow.main.ConstProp.panic-abort.diff | 4 +- ...herit_overflow.main.ConstProp.panic-unwind.diff | 4 +- tests/mir-opt/const_prop/inherit_overflow.rs | 1 + tests/mir-opt/const_prop/invalid_constant.rs | 1 + .../issue_66971.main.ConstProp.panic-abort.diff | 4 +- .../issue_66971.main.ConstProp.panic-unwind.diff | 4 +- tests/mir-opt/const_prop/issue_66971.rs | 1 + .../issue_67019.main.ConstProp.panic-abort.diff | 6 +-- .../issue_67019.main.ConstProp.panic-unwind.diff | 6 +-- tests/mir-opt/const_prop/issue_67019.rs | 1 + tests/mir-opt/const_prop/large_array_index.rs | 1 + tests/mir-opt/const_prop/mult_by_zero.rs | 1 + tests/mir-opt/const_prop/mutable_variable.rs | 1 + .../mutable_variable_aggregate.main.ConstProp.diff | 4 +- .../const_prop/mutable_variable_aggregate.rs | 1 + .../mutable_variable_aggregate_mut_ref.rs | 1 + .../mutable_variable_aggregate_partial_read.rs | 1 + .../mutable_variable_no_prop.main.ConstProp.diff | 4 +- .../mir-opt/const_prop/mutable_variable_no_prop.rs | 1 + ...e_unprop_assign.main.ConstProp.panic-abort.diff | 2 +- ..._unprop_assign.main.ConstProp.panic-unwind.diff | 2 +- .../const_prop/mutable_variable_unprop_assign.rs | 1 + .../offset_of.concrete.ConstProp.panic-abort.diff | 56 ++++++++++++++++++++-- .../offset_of.concrete.ConstProp.panic-unwind.diff | 56 ++++++++++++++++++++-- .../offset_of.generic.ConstProp.panic-abort.diff | 50 +++++++++++++++++-- .../offset_of.generic.ConstProp.panic-unwind.diff | 50 +++++++++++++++++-- tests/mir-opt/const_prop/offset_of.rs | 20 +++++++- .../const_prop/overwrite_with_const_with_params.rs | 26 ++++++++++ ...e_with_const_with_params.size_of.ConstProp.diff | 20 ++++++++ .../read_immutable_static.main.ConstProp.diff | 6 +-- tests/mir-opt/const_prop/read_immutable_static.rs | 1 + tests/mir-opt/const_prop/ref_deref.rs | 1 + tests/mir-opt/const_prop/ref_deref_project.rs | 1 + tests/mir-opt/const_prop/reify_fn_ptr.rs | 1 + tests/mir-opt/const_prop/repeat.rs | 1 + .../return_place.add.ConstProp.panic-abort.diff | 2 +- .../return_place.add.ConstProp.panic-unwind.diff | 2 +- ...urn_place.add.PreCodegen.before.panic-abort.mir | 2 +- ...rn_place.add.PreCodegen.before.panic-unwind.mir | 2 +- tests/mir-opt/const_prop/return_place.rs | 1 + .../const_prop/scalar_literal_propagation.rs | 1 + tests/mir-opt/const_prop/slice_len.rs | 1 + tests/mir-opt/const_prop/switch_int.rs | 1 + tests/mir-opt/const_prop/transmute.rs | 22 +++++++++ .../transmute.unreachable_box.ConstProp.32bit.diff | 3 ++ .../transmute.unreachable_box.ConstProp.64bit.diff | 3 ++ ...ral_propagation.main.ConstProp.panic-abort.diff | 6 +-- ...al_propagation.main.ConstProp.panic-unwind.diff | 6 +-- .../const_prop/tuple_literal_propagation.rs | 1 + tests/mir-opt/const_prop/while_let_loops.rs | 1 + 71 files changed, 482 insertions(+), 52 deletions(-) create mode 100644 tests/mir-opt/const_prop/indirect_mutation.bar.ConstProp.diff create mode 100644 tests/mir-opt/const_prop/indirect_mutation.foo.ConstProp.diff create mode 100644 tests/mir-opt/const_prop/indirect_mutation.rs create mode 100644 tests/mir-opt/const_prop/overwrite_with_const_with_params.rs create mode 100644 tests/mir-opt/const_prop/overwrite_with_const_with_params.size_of.ConstProp.diff (limited to 'tests/mir-opt/const_prop') diff --git a/tests/mir-opt/const_prop/address_of_pair.rs b/tests/mir-opt/const_prop/address_of_pair.rs index 43dc9bae6..169469a07 100644 --- a/tests/mir-opt/const_prop/address_of_pair.rs +++ b/tests/mir-opt/const_prop/address_of_pair.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR address_of_pair.fn0.ConstProp.diff diff --git a/tests/mir-opt/const_prop/aggregate.rs b/tests/mir-opt/const_prop/aggregate.rs index 62cd3dd68..2e043af08 100644 --- a/tests/mir-opt/const_prop/aggregate.rs +++ b/tests/mir-opt/const_prop/aggregate.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -O diff --git a/tests/mir-opt/const_prop/array_index.rs b/tests/mir-opt/const_prop/array_index.rs index f85d23b97..3bd232165 100644 --- a/tests/mir-opt/const_prop/array_index.rs +++ b/tests/mir-opt/const_prop/array_index.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // EMIT_MIR_FOR_EACH_BIT_WIDTH diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.rs b/tests/mir-opt/const_prop/bad_op_div_by_zero.rs index 963084bf7..ab41f64a5 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.rs +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // EMIT_MIR bad_op_div_by_zero.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs b/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs index 9d7d2aa10..e747b21cf 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR bad_op_mod_by_zero.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs index d6b1a93f3..38c97a4cf 100644 --- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs +++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH diff --git a/tests/mir-opt/const_prop/boolean_identities.rs b/tests/mir-opt/const_prop/boolean_identities.rs index c7b609949..781cce8c7 100644 --- a/tests/mir-opt/const_prop/boolean_identities.rs +++ b/tests/mir-opt/const_prop/boolean_identities.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // compile-flags: -O -Zmir-opt-level=4 diff --git a/tests/mir-opt/const_prop/boxes.rs b/tests/mir-opt/const_prop/boxes.rs index 78599174b..c6807ece1 100644 --- a/tests/mir-opt/const_prop/boxes.rs +++ b/tests/mir-opt/const_prop/boxes.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // compile-flags: -O // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/const_prop/cast.rs b/tests/mir-opt/const_prop/cast.rs index 984086eda..3d543bada 100644 --- a/tests/mir-opt/const_prop/cast.rs +++ b/tests/mir-opt/const_prop/cast.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR cast.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff index c2fd7f65f..5a958cc7a 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff @@ -26,7 +26,7 @@ } + } + -+ alloc3 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff index 21a31f9ab..ab48186ae 100644 --- a/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff @@ -26,7 +26,7 @@ } + } + -+ alloc3 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 02 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/checked_add.rs b/tests/mir-opt/const_prop/checked_add.rs index fd40876cb..6a53aced0 100644 --- a/tests/mir-opt/const_prop/checked_add.rs +++ b/tests/mir-opt/const_prop/checked_add.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -C overflow-checks=on diff --git a/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs b/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs index c92831f92..5bd4731bf 100644 --- a/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs +++ b/tests/mir-opt/const_prop/const_prop_fails_gracefully.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp #[inline(never)] diff --git a/tests/mir-opt/const_prop/control_flow_simplification.rs b/tests/mir-opt/const_prop/control_flow_simplification.rs index 21d727b3e..5fc13e202 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.rs +++ b/tests/mir-opt/const_prop/control_flow_simplification.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -Zmir-opt-level=1 diff --git a/tests/mir-opt/const_prop/discriminant.rs b/tests/mir-opt/const_prop/discriminant.rs index fdd67ca8a..11405f38b 100644 --- a/tests/mir-opt/const_prop/discriminant.rs +++ b/tests/mir-opt/const_prop/discriminant.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // compile-flags: -O diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff index c0efc8730..530cfc653 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-abort.diff @@ -31,7 +31,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff index 2aee6f164..08cf72e47 100644 --- a/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/indirect.main.ConstProp.panic-unwind.diff @@ -31,7 +31,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 03 00 │ .. } diff --git a/tests/mir-opt/const_prop/indirect.rs b/tests/mir-opt/const_prop/indirect.rs index 72af6cd95..0e6e1d78d 100644 --- a/tests/mir-opt/const_prop/indirect.rs +++ b/tests/mir-opt/const_prop/indirect.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -C overflow-checks=on diff --git a/tests/mir-opt/const_prop/indirect_mutation.bar.ConstProp.diff b/tests/mir-opt/const_prop/indirect_mutation.bar.ConstProp.diff new file mode 100644 index 000000000..4eafb8d09 --- /dev/null +++ b/tests/mir-opt/const_prop/indirect_mutation.bar.ConstProp.diff @@ -0,0 +1,41 @@ +- // MIR for `bar` before ConstProp ++ // MIR for `bar` after ConstProp + + fn bar() -> () { + let mut _0: (); + let mut _1: (i32,); + let _2: (); + let mut _3: *mut i32; + let mut _5: i32; + scope 1 { + debug v => _1; + let _4: bool; + scope 2 { + } + scope 3 { + debug y => _4; + } + } + + bb0: { + StorageLive(_1); + _1 = (const 1_i32,); + StorageLive(_2); + StorageLive(_3); + _3 = &raw mut (_1.0: i32); + (*_3) = const 5_i32; + StorageDead(_3); + _2 = const (); + StorageDead(_2); + StorageLive(_4); + StorageLive(_5); + _5 = (_1.0: i32); + _4 = Eq(move _5, const 5_i32); + StorageDead(_5); + _0 = const (); + StorageDead(_4); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/const_prop/indirect_mutation.foo.ConstProp.diff b/tests/mir-opt/const_prop/indirect_mutation.foo.ConstProp.diff new file mode 100644 index 000000000..445d9895d --- /dev/null +++ b/tests/mir-opt/const_prop/indirect_mutation.foo.ConstProp.diff @@ -0,0 +1,35 @@ +- // MIR for `foo` before ConstProp ++ // MIR for `foo` after ConstProp + + fn foo() -> () { + let mut _0: (); + let mut _1: (i32,); + let mut _2: &mut i32; + let mut _4: i32; + scope 1 { + debug u => _1; + let _3: bool; + scope 2 { + debug y => _3; + } + } + + bb0: { + StorageLive(_1); + _1 = (const 1_i32,); + StorageLive(_2); + _2 = &mut (_1.0: i32); + (*_2) = const 5_i32; + StorageDead(_2); + StorageLive(_3); + StorageLive(_4); + _4 = (_1.0: i32); + _3 = Eq(move _4, const 5_i32); + StorageDead(_4); + _0 = const (); + StorageDead(_3); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/const_prop/indirect_mutation.rs b/tests/mir-opt/const_prop/indirect_mutation.rs new file mode 100644 index 000000000..ec9da6e8e --- /dev/null +++ b/tests/mir-opt/const_prop/indirect_mutation.rs @@ -0,0 +1,41 @@ +// unit-test: ConstProp +// Check that we do not propagate past an indirect mutation. +#![feature(raw_ref_op)] + +// EMIT_MIR indirect_mutation.foo.ConstProp.diff +fn foo() { + // CHECK-LABEL: fn foo( + // CHECK: debug u => _1; + // CHECK: debug y => _3; + // CHECK: _1 = (const 1_i32,); + // CHECK: _2 = &mut (_1.0: i32); + // CHECK: (*_2) = const 5_i32; + // CHECK: _4 = (_1.0: i32); + // CHECK: _3 = Eq(move _4, const 5_i32); + + let mut u = (1,); + *&mut u.0 = 5; + let y = { u.0 } == 5; +} + +// EMIT_MIR indirect_mutation.bar.ConstProp.diff +fn bar() { + // CHECK-LABEL: fn bar( + // CHECK: debug v => _1; + // CHECK: debug y => _4; + // CHECK: _3 = &raw mut (_1.0: i32); + // CHECK: (*_3) = const 5_i32; + // CHECK: _5 = (_1.0: i32); + // CHECK: _4 = Eq(move _5, const 5_i32); + + let mut v = (1,); + unsafe { + *&raw mut v.0 = 5; + } + let y = { v.0 } == 5; +} + +fn main() { + foo(); + bar(); +} diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff index 7ba51ccdb..b30deb2a4 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-abort.diff @@ -20,6 +20,7 @@ _2 = const u8::MAX; StorageLive(_3); _3 = const 1_u8; + StorageLive(_4); - _4 = CheckedAdd(_2, _3); - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable]; + _4 = const (0_u8, true); @@ -29,6 +30,7 @@ bb1: { - _1 = move (_4.0: u8); + _1 = const 0_u8; + StorageDead(_4); StorageDead(_3); StorageDead(_2); StorageDead(_1); @@ -37,7 +39,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff index 545b7f22f..47c51196c 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/inherit_overflow.main.ConstProp.panic-unwind.diff @@ -20,6 +20,7 @@ _2 = const u8::MAX; StorageLive(_3); _3 = const 1_u8; + StorageLive(_4); - _4 = CheckedAdd(_2, _3); - assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind continue]; + _4 = const (0_u8, true); @@ -29,6 +30,7 @@ bb1: { - _1 = move (_4.0: u8); + _1 = const 0_u8; + StorageDead(_4); StorageDead(_3); StorageDead(_2); StorageDead(_1); @@ -37,7 +39,7 @@ } + } + -+ alloc3 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 00 01 │ .. } diff --git a/tests/mir-opt/const_prop/inherit_overflow.rs b/tests/mir-opt/const_prop/inherit_overflow.rs index 6ebd36412..41989462d 100644 --- a/tests/mir-opt/const_prop/inherit_overflow.rs +++ b/tests/mir-opt/const_prop/inherit_overflow.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -Zmir-enable-passes=+Inline diff --git a/tests/mir-opt/const_prop/invalid_constant.rs b/tests/mir-opt/const_prop/invalid_constant.rs index bdbc5a199..ff6b31a1e 100644 --- a/tests/mir-opt/const_prop/invalid_constant.rs +++ b/tests/mir-opt/const_prop/invalid_constant.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // compile-flags: -Zmir-enable-passes=+RemoveZsts // Verify that we can pretty print invalid constants. diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff index 18341ba7d..6484b4b67 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-abort.diff @@ -20,11 +20,11 @@ } + } + -+ alloc8 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 00 00 │ .. + } + -+ alloc7 (size: 2, align: 1) { ++ ALLOC1 (size: 2, align: 1) { + 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff index 50763c10f..b02f04078 100644 --- a/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_66971.main.ConstProp.panic-unwind.diff @@ -20,11 +20,11 @@ } + } + -+ alloc8 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 00 00 │ .. + } + -+ alloc7 (size: 2, align: 1) { ++ ALLOC1 (size: 2, align: 1) { + 00 00 │ .. } diff --git a/tests/mir-opt/const_prop/issue_66971.rs b/tests/mir-opt/const_prop/issue_66971.rs index a0242ec63..386c95b5b 100644 --- a/tests/mir-opt/const_prop/issue_66971.rs +++ b/tests/mir-opt/const_prop/issue_66971.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -Z mir-opt-level=3 diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff index 015180db8..c1ef453e9 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-abort.diff @@ -25,15 +25,15 @@ } + } + -+ alloc12 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 01 02 │ .. + } + -+ alloc11 (size: 2, align: 1) { ++ ALLOC1 (size: 2, align: 1) { + 01 02 │ .. + } + -+ alloc8 (size: 2, align: 1) { ++ ALLOC2 (size: 2, align: 1) { + 01 02 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff index 8e41705c1..53cdcc181 100644 --- a/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/issue_67019.main.ConstProp.panic-unwind.diff @@ -25,15 +25,15 @@ } + } + -+ alloc12 (size: 2, align: 1) { ++ ALLOC0 (size: 2, align: 1) { + 01 02 │ .. + } + -+ alloc11 (size: 2, align: 1) { ++ ALLOC1 (size: 2, align: 1) { + 01 02 │ .. + } + -+ alloc8 (size: 2, align: 1) { ++ ALLOC2 (size: 2, align: 1) { + 01 02 │ .. } diff --git a/tests/mir-opt/const_prop/issue_67019.rs b/tests/mir-opt/const_prop/issue_67019.rs index 66b577f5b..2f61298bb 100644 --- a/tests/mir-opt/const_prop/issue_67019.rs +++ b/tests/mir-opt/const_prop/issue_67019.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -Z mir-opt-level=3 diff --git a/tests/mir-opt/const_prop/large_array_index.rs b/tests/mir-opt/const_prop/large_array_index.rs index d226bd546..d98d166ff 100644 --- a/tests/mir-opt/const_prop/large_array_index.rs +++ b/tests/mir-opt/const_prop/large_array_index.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH diff --git a/tests/mir-opt/const_prop/mult_by_zero.rs b/tests/mir-opt/const_prop/mult_by_zero.rs index 7bd30975a..47e15205e 100644 --- a/tests/mir-opt/const_prop/mult_by_zero.rs +++ b/tests/mir-opt/const_prop/mult_by_zero.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR mult_by_zero.test.ConstProp.diff diff --git a/tests/mir-opt/const_prop/mutable_variable.rs b/tests/mir-opt/const_prop/mutable_variable.rs index 95987ef7f..175d63d46 100644 --- a/tests/mir-opt/const_prop/mutable_variable.rs +++ b/tests/mir-opt/const_prop/mutable_variable.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR mutable_variable.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff index 56a127ae3..c3ace9687 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.main.ConstProp.diff @@ -27,11 +27,11 @@ } + } + -+ alloc7 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 2a 00 00 00 63 00 00 00 │ *...c... + } + -+ alloc5 (size: 8, align: 4) { ++ ALLOC1 (size: 8, align: 4) { + 2a 00 00 00 2b 00 00 00 │ *...+... } diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs index a145c0354..f926771ae 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR mutable_variable_aggregate.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs index 3099e659f..a81aa7b49 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR mutable_variable_aggregate_mut_ref.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs index 30ea5714a..54a5d9223 100644 --- a/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs +++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_partial_read.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp diff --git a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff index ac26f8ef4..1f74bdcfd 100644 --- a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.ConstProp.diff @@ -23,7 +23,7 @@ StorageLive(_2); StorageLive(_3); StorageLive(_4); - _4 = const {alloc1: *mut u32}; + _4 = const {ALLOC0: *mut u32}; _3 = (*_4); _1 = move _3; StorageDead(_3); @@ -39,7 +39,7 @@ } } - alloc1 (static: STATIC, size: 4, align: 4) { + ALLOC0 (static: STATIC, size: 4, align: 4) { 42 42 42 42 │ BBBB } diff --git a/tests/mir-opt/const_prop/mutable_variable_no_prop.rs b/tests/mir-opt/const_prop/mutable_variable_no_prop.rs index e51c62235..a7aeeccd8 100644 --- a/tests/mir-opt/const_prop/mutable_variable_no_prop.rs +++ b/tests/mir-opt/const_prop/mutable_variable_no_prop.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp static mut STATIC: u32 = 0x42424242; diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff index a1b433716..85bd2b6e7 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff @@ -48,7 +48,7 @@ } + } + -+ alloc7 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff index 2dc514194..06e96e57a 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff @@ -48,7 +48,7 @@ } + } + -+ alloc7 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs index 4e7c0597a..6bdb136a9 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp diff --git a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff index c73d217ae..711db3d21 100644 --- a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff @@ -8,6 +8,9 @@ let mut _4: usize; let mut _6: usize; let mut _8: usize; + let mut _10: usize; + let mut _12: usize; + let mut _14: usize; scope 1 { debug x => _1; let _3: usize; @@ -19,6 +22,18 @@ let _7: usize; scope 4 { debug z1 => _7; + let _9: usize; + scope 5 { + debug eA0 => _9; + let _11: usize; + scope 6 { + debug eA1 => _11; + let _13: usize; + scope 7 { + debug eC => _13; + } + } + } } } } @@ -27,7 +42,7 @@ bb0: { StorageLive(_1); StorageLive(_2); -- _2 = OffsetOf(Alpha, [0]); +- _2 = OffsetOf(Alpha, [(0, 0)]); - _1 = must_use::(move _2) -> [return: bb1, unwind unreachable]; + _2 = const 4_usize; + _1 = must_use::(const 4_usize) -> [return: bb1, unwind unreachable]; @@ -37,7 +52,7 @@ StorageDead(_2); StorageLive(_3); StorageLive(_4); -- _4 = OffsetOf(Alpha, [1]); +- _4 = OffsetOf(Alpha, [(0, 1)]); - _3 = must_use::(move _4) -> [return: bb2, unwind unreachable]; + _4 = const 0_usize; + _3 = must_use::(const 0_usize) -> [return: bb2, unwind unreachable]; @@ -47,7 +62,7 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); -- _6 = OffsetOf(Alpha, [2, 0]); +- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]); - _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; + _6 = const 2_usize; + _5 = must_use::(const 2_usize) -> [return: bb3, unwind unreachable]; @@ -57,7 +72,7 @@ StorageDead(_6); StorageLive(_7); StorageLive(_8); -- _8 = OffsetOf(Alpha, [2, 1]); +- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]); - _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; + _8 = const 3_usize; + _7 = must_use::(const 3_usize) -> [return: bb4, unwind unreachable]; @@ -65,7 +80,40 @@ bb4: { StorageDead(_8); + StorageLive(_9); + StorageLive(_10); +- _10 = OffsetOf(Epsilon, [(0, 0)]); +- _9 = must_use::(move _10) -> [return: bb5, unwind unreachable]; ++ _10 = const 1_usize; ++ _9 = must_use::(const 1_usize) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_10); + StorageLive(_11); + StorageLive(_12); +- _12 = OffsetOf(Epsilon, [(0, 1)]); +- _11 = must_use::(move _12) -> [return: bb6, unwind unreachable]; ++ _12 = const 2_usize; ++ _11 = must_use::(const 2_usize) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_12); + StorageLive(_13); + StorageLive(_14); +- _14 = OffsetOf(Epsilon, [(2, 0)]); +- _13 = must_use::(move _14) -> [return: bb7, unwind unreachable]; ++ _14 = const 4_usize; ++ _13 = must_use::(const 4_usize) -> [return: bb7, unwind unreachable]; + } + + bb7: { + StorageDead(_14); _0 = const (); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_7); StorageDead(_5); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff index 913ffca4a..494581454 100644 --- a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff @@ -8,6 +8,9 @@ let mut _4: usize; let mut _6: usize; let mut _8: usize; + let mut _10: usize; + let mut _12: usize; + let mut _14: usize; scope 1 { debug x => _1; let _3: usize; @@ -19,6 +22,18 @@ let _7: usize; scope 4 { debug z1 => _7; + let _9: usize; + scope 5 { + debug eA0 => _9; + let _11: usize; + scope 6 { + debug eA1 => _11; + let _13: usize; + scope 7 { + debug eC => _13; + } + } + } } } } @@ -27,7 +42,7 @@ bb0: { StorageLive(_1); StorageLive(_2); -- _2 = OffsetOf(Alpha, [0]); +- _2 = OffsetOf(Alpha, [(0, 0)]); - _1 = must_use::(move _2) -> [return: bb1, unwind continue]; + _2 = const 4_usize; + _1 = must_use::(const 4_usize) -> [return: bb1, unwind continue]; @@ -37,7 +52,7 @@ StorageDead(_2); StorageLive(_3); StorageLive(_4); -- _4 = OffsetOf(Alpha, [1]); +- _4 = OffsetOf(Alpha, [(0, 1)]); - _3 = must_use::(move _4) -> [return: bb2, unwind continue]; + _4 = const 0_usize; + _3 = must_use::(const 0_usize) -> [return: bb2, unwind continue]; @@ -47,7 +62,7 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); -- _6 = OffsetOf(Alpha, [2, 0]); +- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]); - _5 = must_use::(move _6) -> [return: bb3, unwind continue]; + _6 = const 2_usize; + _5 = must_use::(const 2_usize) -> [return: bb3, unwind continue]; @@ -57,7 +72,7 @@ StorageDead(_6); StorageLive(_7); StorageLive(_8); -- _8 = OffsetOf(Alpha, [2, 1]); +- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]); - _7 = must_use::(move _8) -> [return: bb4, unwind continue]; + _8 = const 3_usize; + _7 = must_use::(const 3_usize) -> [return: bb4, unwind continue]; @@ -65,7 +80,40 @@ bb4: { StorageDead(_8); + StorageLive(_9); + StorageLive(_10); +- _10 = OffsetOf(Epsilon, [(0, 0)]); +- _9 = must_use::(move _10) -> [return: bb5, unwind continue]; ++ _10 = const 1_usize; ++ _9 = must_use::(const 1_usize) -> [return: bb5, unwind continue]; + } + + bb5: { + StorageDead(_10); + StorageLive(_11); + StorageLive(_12); +- _12 = OffsetOf(Epsilon, [(0, 1)]); +- _11 = must_use::(move _12) -> [return: bb6, unwind continue]; ++ _12 = const 2_usize; ++ _11 = must_use::(const 2_usize) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_12); + StorageLive(_13); + StorageLive(_14); +- _14 = OffsetOf(Epsilon, [(2, 0)]); +- _13 = must_use::(move _14) -> [return: bb7, unwind continue]; ++ _14 = const 4_usize; ++ _13 = must_use::(const 4_usize) -> [return: bb7, unwind continue]; + } + + bb7: { + StorageDead(_14); _0 = const (); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_7); StorageDead(_5); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff index 7519331f6..768970a72 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff @@ -8,6 +8,9 @@ let mut _4: usize; let mut _6: usize; let mut _8: usize; + let mut _10: usize; + let mut _12: usize; + let mut _14: usize; scope 1 { debug gx => _1; let _3: usize; @@ -19,6 +22,18 @@ let _7: usize; scope 4 { debug dy => _7; + let _9: usize; + scope 5 { + debug zA0 => _9; + let _11: usize; + scope 6 { + debug zA1 => _11; + let _13: usize; + scope 7 { + debug zB => _13; + } + } + } } } } @@ -27,7 +42,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = OffsetOf(Gamma, [0]); + _2 = OffsetOf(Gamma, [(0, 0)]); _1 = must_use::(move _2) -> [return: bb1, unwind unreachable]; } @@ -35,7 +50,7 @@ StorageDead(_2); StorageLive(_3); StorageLive(_4); - _4 = OffsetOf(Gamma, [1]); + _4 = OffsetOf(Gamma, [(0, 1)]); _3 = must_use::(move _4) -> [return: bb2, unwind unreachable]; } @@ -43,7 +58,7 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); + _6 = OffsetOf(Delta, [(0, 1)]); _5 = must_use::(move _6) -> [return: bb3, unwind unreachable]; } @@ -51,13 +66,40 @@ StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); + _8 = OffsetOf(Delta, [(0, 2)]); _7 = must_use::(move _8) -> [return: bb4, unwind unreachable]; } bb4: { StorageDead(_8); + StorageLive(_9); + StorageLive(_10); + _10 = OffsetOf(Zeta, [(0, 0)]); + _9 = must_use::(move _10) -> [return: bb5, unwind unreachable]; + } + + bb5: { + StorageDead(_10); + StorageLive(_11); + StorageLive(_12); + _12 = OffsetOf(Zeta, [(0, 1)]); + _11 = must_use::(move _12) -> [return: bb6, unwind unreachable]; + } + + bb6: { + StorageDead(_12); + StorageLive(_13); + StorageLive(_14); + _14 = OffsetOf(Zeta, [(1, 0)]); + _13 = must_use::(move _14) -> [return: bb7, unwind unreachable]; + } + + bb7: { + StorageDead(_14); _0 = const (); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_7); StorageDead(_5); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff index fd5206e46..04ccd2b36 100644 --- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff @@ -8,6 +8,9 @@ let mut _4: usize; let mut _6: usize; let mut _8: usize; + let mut _10: usize; + let mut _12: usize; + let mut _14: usize; scope 1 { debug gx => _1; let _3: usize; @@ -19,6 +22,18 @@ let _7: usize; scope 4 { debug dy => _7; + let _9: usize; + scope 5 { + debug zA0 => _9; + let _11: usize; + scope 6 { + debug zA1 => _11; + let _13: usize; + scope 7 { + debug zB => _13; + } + } + } } } } @@ -27,7 +42,7 @@ bb0: { StorageLive(_1); StorageLive(_2); - _2 = OffsetOf(Gamma, [0]); + _2 = OffsetOf(Gamma, [(0, 0)]); _1 = must_use::(move _2) -> [return: bb1, unwind continue]; } @@ -35,7 +50,7 @@ StorageDead(_2); StorageLive(_3); StorageLive(_4); - _4 = OffsetOf(Gamma, [1]); + _4 = OffsetOf(Gamma, [(0, 1)]); _3 = must_use::(move _4) -> [return: bb2, unwind continue]; } @@ -43,7 +58,7 @@ StorageDead(_4); StorageLive(_5); StorageLive(_6); - _6 = OffsetOf(Delta, [1]); + _6 = OffsetOf(Delta, [(0, 1)]); _5 = must_use::(move _6) -> [return: bb3, unwind continue]; } @@ -51,13 +66,40 @@ StorageDead(_6); StorageLive(_7); StorageLive(_8); - _8 = OffsetOf(Delta, [2]); + _8 = OffsetOf(Delta, [(0, 2)]); _7 = must_use::(move _8) -> [return: bb4, unwind continue]; } bb4: { StorageDead(_8); + StorageLive(_9); + StorageLive(_10); + _10 = OffsetOf(Zeta, [(0, 0)]); + _9 = must_use::(move _10) -> [return: bb5, unwind continue]; + } + + bb5: { + StorageDead(_10); + StorageLive(_11); + StorageLive(_12); + _12 = OffsetOf(Zeta, [(0, 1)]); + _11 = must_use::(move _12) -> [return: bb6, unwind continue]; + } + + bb6: { + StorageDead(_12); + StorageLive(_13); + StorageLive(_14); + _14 = OffsetOf(Zeta, [(1, 0)]); + _13 = must_use::(move _14) -> [return: bb7, unwind continue]; + } + + bb7: { + StorageDead(_14); _0 = const (); + StorageDead(_13); + StorageDead(_11); + StorageDead(_9); StorageDead(_7); StorageDead(_5); StorageDead(_3); diff --git a/tests/mir-opt/const_prop/offset_of.rs b/tests/mir-opt/const_prop/offset_of.rs index 164db5957..2571c3856 100644 --- a/tests/mir-opt/const_prop/offset_of.rs +++ b/tests/mir-opt/const_prop/offset_of.rs @@ -1,7 +1,8 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -#![feature(offset_of)] +#![feature(offset_of, offset_of_enum)] use std::marker::PhantomData; use std::mem::offset_of; @@ -27,12 +28,26 @@ struct Delta { y: u16, } +enum Epsilon { + A(u8, u16), + B, + C { c: u32 } +} + +enum Zeta { + A(T, bool), + B(char), +} + // EMIT_MIR offset_of.concrete.ConstProp.diff fn concrete() { let x = offset_of!(Alpha, x); let y = offset_of!(Alpha, y); let z0 = offset_of!(Alpha, z.0); let z1 = offset_of!(Alpha, z.1); + let eA0 = offset_of!(Epsilon, A.0); + let eA1 = offset_of!(Epsilon, A.1); + let eC = offset_of!(Epsilon, C.c); } // EMIT_MIR offset_of.generic.ConstProp.diff @@ -41,6 +56,9 @@ fn generic() { let gy = offset_of!(Gamma, y); let dx = offset_of!(Delta, x); let dy = offset_of!(Delta, y); + let zA0 = offset_of!(Zeta, A.0); + let zA1 = offset_of!(Zeta, A.1); + let zB = offset_of!(Zeta, B.0); } fn main() { diff --git a/tests/mir-opt/const_prop/overwrite_with_const_with_params.rs b/tests/mir-opt/const_prop/overwrite_with_const_with_params.rs new file mode 100644 index 000000000..4cf6d7c13 --- /dev/null +++ b/tests/mir-opt/const_prop/overwrite_with_const_with_params.rs @@ -0,0 +1,26 @@ +// unit-test: ConstProp +// compile-flags: -O + +// Regression test for https://github.com/rust-lang/rust/issues/118328 + +#![allow(unused_assignments)] + +struct SizeOfConst(std::marker::PhantomData); +impl SizeOfConst { + const SIZE: usize = std::mem::size_of::(); +} + +// EMIT_MIR overwrite_with_const_with_params.size_of.ConstProp.diff +fn size_of() -> usize { + // CHECK-LABEL: fn size_of( + // CHECK: _1 = const 0_usize; + // CHECK-NEXT: _1 = const _; + // CHECK-NEXT: _0 = _1; + let mut a = 0; + a = SizeOfConst::::SIZE; + a +} + +fn main() { + assert_eq!(size_of::(), std::mem::size_of::()); +} diff --git a/tests/mir-opt/const_prop/overwrite_with_const_with_params.size_of.ConstProp.diff b/tests/mir-opt/const_prop/overwrite_with_const_with_params.size_of.ConstProp.diff new file mode 100644 index 000000000..ad8318832 --- /dev/null +++ b/tests/mir-opt/const_prop/overwrite_with_const_with_params.size_of.ConstProp.diff @@ -0,0 +1,20 @@ +- // MIR for `size_of` before ConstProp ++ // MIR for `size_of` after ConstProp + + fn size_of() -> usize { + let mut _0: usize; + let mut _1: usize; + scope 1 { + debug a => _1; + } + + bb0: { + StorageLive(_1); + _1 = const 0_usize; + _1 = const _; + _0 = _1; + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff b/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff index 29c455f35..e193c82d2 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff +++ b/tests/mir-opt/const_prop/read_immutable_static.main.ConstProp.diff @@ -16,12 +16,12 @@ StorageLive(_1); StorageLive(_2); StorageLive(_3); - _3 = const {alloc1: &u8}; + _3 = const {ALLOC0: &u8}; - _2 = (*_3); + _2 = const 2_u8; StorageLive(_4); StorageLive(_5); - _5 = const {alloc1: &u8}; + _5 = const {ALLOC0: &u8}; - _4 = (*_5); - _1 = Add(move _2, move _4); + _4 = const 2_u8; @@ -36,7 +36,7 @@ } } - alloc1 (static: FOO, size: 1, align: 1) { + ALLOC0 (static: FOO, size: 1, align: 1) { 02 │ . } diff --git a/tests/mir-opt/const_prop/read_immutable_static.rs b/tests/mir-opt/const_prop/read_immutable_static.rs index fb8f9fe99..a8d8cfacc 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.rs +++ b/tests/mir-opt/const_prop/read_immutable_static.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp static FOO: u8 = 2; diff --git a/tests/mir-opt/const_prop/ref_deref.rs b/tests/mir-opt/const_prop/ref_deref.rs index 76e56916a..f2fa024f7 100644 --- a/tests/mir-opt/const_prop/ref_deref.rs +++ b/tests/mir-opt/const_prop/ref_deref.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR ref_deref.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/ref_deref_project.rs b/tests/mir-opt/const_prop/ref_deref_project.rs index 04fc7f8da..1b9e0acb2 100644 --- a/tests/mir-opt/const_prop/ref_deref_project.rs +++ b/tests/mir-opt/const_prop/ref_deref_project.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR ref_deref_project.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/reify_fn_ptr.rs b/tests/mir-opt/const_prop/reify_fn_ptr.rs index 5f6382066..da7de80c5 100644 --- a/tests/mir-opt/const_prop/reify_fn_ptr.rs +++ b/tests/mir-opt/const_prop/reify_fn_ptr.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR reify_fn_ptr.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/repeat.rs b/tests/mir-opt/const_prop/repeat.rs index fb8b825ee..92194d6bb 100644 --- a/tests/mir-opt/const_prop/repeat.rs +++ b/tests/mir-opt/const_prop/repeat.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR_FOR_EACH_BIT_WIDTH diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff index 6c9de4764..974a42e50 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-abort.diff @@ -19,7 +19,7 @@ } + } + -+ alloc5 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff index 0f079278c..55dbc7002 100644 --- a/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/return_place.add.ConstProp.panic-unwind.diff @@ -19,7 +19,7 @@ } + } + -+ alloc5 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir index c2488f394..f87c26bb0 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-abort.mir @@ -15,6 +15,6 @@ fn add() -> u32 { } } -alloc5 (size: 8, align: 4) { +ALLOC0 (size: 8, align: 4) { 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir index fa0b9c77e..33f975913 100644 --- a/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir +++ b/tests/mir-opt/const_prop/return_place.add.PreCodegen.before.panic-unwind.mir @@ -15,6 +15,6 @@ fn add() -> u32 { } } -alloc5 (size: 8, align: 4) { +ALLOC0 (size: 8, align: 4) { 04 00 00 00 00 __ __ __ │ .....░░░ } diff --git a/tests/mir-opt/const_prop/return_place.rs b/tests/mir-opt/const_prop/return_place.rs index 0576b02a8..1263de793 100644 --- a/tests/mir-opt/const_prop/return_place.rs +++ b/tests/mir-opt/const_prop/return_place.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // compile-flags: -C overflow-checks=on diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.rs b/tests/mir-opt/const_prop/scalar_literal_propagation.rs index dfe41e614..9dcddf7c7 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.rs +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR scalar_literal_propagation.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/slice_len.rs b/tests/mir-opt/const_prop/slice_len.rs index e91724536..3b551b6b1 100644 --- a/tests/mir-opt/const_prop/slice_len.rs +++ b/tests/mir-opt/const_prop/slice_len.rs @@ -1,3 +1,4 @@ +// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // unit-test: ConstProp // compile-flags: -Zmir-enable-passes=+InstSimplify diff --git a/tests/mir-opt/const_prop/switch_int.rs b/tests/mir-opt/const_prop/switch_int.rs index bf708c829..7ec56e11e 100644 --- a/tests/mir-opt/const_prop/switch_int.rs +++ b/tests/mir-opt/const_prop/switch_int.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // compile-flags: -Zmir-enable-passes=+SimplifyConstCondition-after-const-prop // EMIT_MIR_FOR_EACH_PANIC_STRATEGY diff --git a/tests/mir-opt/const_prop/transmute.rs b/tests/mir-opt/const_prop/transmute.rs index 762c42171..99988d059 100644 --- a/tests/mir-opt/const_prop/transmute.rs +++ b/tests/mir-opt/const_prop/transmute.rs @@ -7,55 +7,77 @@ use std::mem::transmute; // EMIT_MIR transmute.less_as_i8.ConstProp.diff pub fn less_as_i8() -> i8 { + // CHECK-LABEL: fn less_as_i8( + // CHECK: _0 = const -1_i8; unsafe { transmute(std::cmp::Ordering::Less) } } // EMIT_MIR transmute.from_char.ConstProp.diff pub fn from_char() -> i32 { + // CHECK-LABEL: fn from_char( + // CHECK: _0 = const 82_i32; unsafe { transmute('R') } } // EMIT_MIR transmute.valid_char.ConstProp.diff pub fn valid_char() -> char { + // CHECK-LABEL: fn valid_char( + // CHECK: _0 = const 'R'; unsafe { transmute(0x52_u32) } } // EMIT_MIR transmute.invalid_char.ConstProp.diff pub unsafe fn invalid_char() -> char { + // CHECK-LABEL: fn invalid_char( + // CHECK: _0 = const {transmute(0x7fffffff): char}; unsafe { transmute(i32::MAX) } } // EMIT_MIR transmute.invalid_bool.ConstProp.diff pub unsafe fn invalid_bool() -> bool { + // CHECK-LABEL: fn invalid_bool( + // CHECK: _0 = const {transmute(0xff): bool}; unsafe { transmute(-1_i8) } } // EMIT_MIR transmute.undef_union_as_integer.ConstProp.diff pub unsafe fn undef_union_as_integer() -> u32 { + // CHECK-LABEL: fn undef_union_as_integer( + // CHECK: _1 = Union32 { + // CHECK: _0 = move _1 as u32 (Transmute); union Union32 { value: u32, unit: () } unsafe { transmute(Union32 { unit: () }) } } // EMIT_MIR transmute.unreachable_direct.ConstProp.diff pub unsafe fn unreachable_direct() -> ! { + // CHECK-LABEL: fn unreachable_direct( + // CHECK: [[unit:_.*]] = (); + // CHECK: move [[unit]] as Never (Transmute); let x: Never = unsafe { transmute(()) }; match x {} } // EMIT_MIR transmute.unreachable_ref.ConstProp.diff pub unsafe fn unreachable_ref() -> ! { + // CHECK-LABEL: fn unreachable_ref( + // CHECK: = const {0x1 as &Never}; let x: &Never = unsafe { transmute(1_usize) }; match *x {} } // EMIT_MIR transmute.unreachable_mut.ConstProp.diff pub unsafe fn unreachable_mut() -> ! { + // CHECK-LABEL: fn unreachable_mut( + // CHECK: = const {0x1 as &mut Never}; let x: &mut Never = unsafe { transmute(1_usize) }; match *x {} } // EMIT_MIR transmute.unreachable_box.ConstProp.diff pub unsafe fn unreachable_box() -> ! { + // CHECK-LABEL: fn unreachable_box( + // CHECK: = const Box::( let x: Box = unsafe { transmute(1_usize) }; match *x {} } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff index 100982382..16519749b 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.32bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -13,7 +14,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); +- _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never}; unreachable; } } diff --git a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff index 100982382..16519749b 100644 --- a/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff +++ b/tests/mir-opt/const_prop/transmute.unreachable_box.ConstProp.64bit.diff @@ -4,6 +4,7 @@ fn unreachable_box() -> ! { let mut _0: !; let _1: std::boxed::Box; + let mut _2: *const Never; scope 1 { debug x => _1; } @@ -13,7 +14,9 @@ bb0: { StorageLive(_1); - _1 = const 1_usize as std::boxed::Box (Transmute); +- _2 = (((_1.0: std::ptr::Unique).0: std::ptr::NonNull).0: *const Never); + _1 = const Box::(Unique:: {{ pointer: NonNull:: {{ pointer: {0x1 as *const Never} }}, _marker: PhantomData:: }}, std::alloc::Global); ++ _2 = const {0x1 as *const Never}; unreachable; } } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff index 988ef7dd2..f19650d5a 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-abort.diff @@ -31,15 +31,15 @@ } + } + -+ alloc9 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ + } + -+ alloc8 (size: 8, align: 4) { ++ ALLOC1 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ + } + -+ alloc6 (size: 8, align: 4) { ++ ALLOC2 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff index 298446197..67307c423 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.ConstProp.panic-unwind.diff @@ -31,15 +31,15 @@ } + } + -+ alloc9 (size: 8, align: 4) { ++ ALLOC0 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ + } + -+ alloc8 (size: 8, align: 4) { ++ ALLOC1 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ + } + -+ alloc6 (size: 8, align: 4) { ++ ALLOC2 (size: 8, align: 4) { + 01 00 00 00 02 00 00 00 │ ........ } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.rs b/tests/mir-opt/const_prop/tuple_literal_propagation.rs index 5890a343f..e0bc6e1be 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.rs +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // EMIT_MIR tuple_literal_propagation.main.ConstProp.diff diff --git a/tests/mir-opt/const_prop/while_let_loops.rs b/tests/mir-opt/const_prop/while_let_loops.rs index 595a94b88..39081c355 100644 --- a/tests/mir-opt/const_prop/while_let_loops.rs +++ b/tests/mir-opt/const_prop/while_let_loops.rs @@ -1,3 +1,4 @@ +// skip-filecheck // unit-test: ConstProp // EMIT_MIR while_let_loops.change_loop_body.ConstProp.diff -- cgit v1.2.3