rust/tests/mir-opt/const_prop
Matthias Krüger 434232f7b2
Rollup merge of #118426 - aDotInTheVoid:const-wat, r=compiler-errors,cjgillot
ConstProp: Correctly remove const if unknown value assigned to it.

Closes #118328

The problematic sequence of MIR is:

```rust
          _1 = const 0_usize;
          _1 = const _; // This is an associated constant we can't know before monomorphization.
          _0 = _1;
```

1. When `ConstProp::visit_assign` happens on `_1 = const 0_usize;`, it records that `0x0usize` is the value for `_1`.
2. Next `visit_assign` happens on `_1 = const _;`. Because the rvalue `.has_param()`, it can't be const evaled.
3. Finaly, `visit_assign` happens on `_0 = _1;`. Here it would think the value of `_1` was `0x0usize` from step 1.

The solution is to remove consts when checking the RValue fails, as they may have contained values that should now be invalidated, as that local was overwritten.

This should probably be back-ported to beta. Stable is more iffy, as it's gone unidentified since 1.70, so I only think it's worthwhile if there's another reason for a 1.74.1 release anyway.
2023-11-29 12:34:50 +01:00
..
address_of_pair.fn0.ConstProp.diff
address_of_pair.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
aggregate.foo.ConstProp.panic-abort.diff
aggregate.foo.ConstProp.panic-unwind.diff
aggregate.foo.PreCodegen.after.panic-abort.mir
aggregate.foo.PreCodegen.after.panic-unwind.mir
aggregate.main.ConstProp.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
aggregate.main.ConstProp.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
aggregate.main.PreCodegen.after.panic-abort.mir Always propagate into operands. 2023-07-20 21:30:51 +00:00
aggregate.main.PreCodegen.after.panic-unwind.mir Always propagate into operands. 2023-07-20 21:30:51 +00:00
aggregate.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
array_index.main.ConstProp.32bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
array_index.main.ConstProp.32bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
array_index.main.ConstProp.64bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
array_index.main.ConstProp.64bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
array_index.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
bad_op_div_by_zero.main.ConstProp.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
bad_op_div_by_zero.main.ConstProp.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
bad_op_div_by_zero.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
bad_op_mod_by_zero.main.ConstProp.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
bad_op_mod_by_zero.main.ConstProp.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
bad_op_mod_by_zero.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff Support array length. 2023-09-06 16:05:04 +00:00
bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff Support array length. 2023-09-06 16:05:04 +00:00
bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff Support array length. 2023-09-06 16:05:04 +00:00
bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff Support array length. 2023-09-06 16:05:04 +00:00
bad_op_unsafe_oob_for_slices.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
boolean_identities.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
boolean_identities.test.ConstProp.diff
boxes.main.ConstProp.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
boxes.main.ConstProp.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
boxes.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
cast.main.ConstProp.diff
cast.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
checked_add.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
checked_add.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
checked_add.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
const_prop_fails_gracefully.main.ConstProp.panic-abort.diff
const_prop_fails_gracefully.main.ConstProp.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
const_prop_fails_gracefully.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
control_flow_simplification.hello.ConstProp.panic-abort.diff Also propagate ScalarPair operands. 2023-07-20 21:30:51 +00:00
control_flow_simplification.hello.ConstProp.panic-unwind.diff Also propagate ScalarPair operands. 2023-07-20 21:30:51 +00:00
control_flow_simplification.hello.PreCodegen.before.panic-abort.mir
control_flow_simplification.hello.PreCodegen.before.panic-unwind.mir
control_flow_simplification.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
discriminant.main.ConstProp.32bit.diff
discriminant.main.ConstProp.64bit.diff
discriminant.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
indirect_mutation.bar.ConstProp.diff FileCheck const_prop_miscompile. 2023-10-31 22:56:02 +00:00
indirect_mutation.foo.ConstProp.diff FileCheck const_prop_miscompile. 2023-10-31 22:56:02 +00:00
indirect_mutation.rs FileCheck const_prop_miscompile. 2023-10-31 22:56:02 +00:00
indirect.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
indirect.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
indirect.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
inherit_overflow.main.ConstProp.panic-abort.diff add track_caller for arith ops 2023-11-24 00:54:06 +08:00
inherit_overflow.main.ConstProp.panic-unwind.diff add track_caller for arith ops 2023-11-24 00:54:06 +08:00
inherit_overflow.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
invalid_constant.main.ConstProp.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
invalid_constant.main.RemoveZsts.diff
invalid_constant.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
issue_66971.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
issue_66971.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
issue_66971.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
issue_67019.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
issue_67019.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
issue_67019.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
large_array_index.main.ConstProp.32bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
large_array_index.main.ConstProp.32bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
large_array_index.main.ConstProp.64bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
large_array_index.main.ConstProp.64bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
large_array_index.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mult_by_zero.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mult_by_zero.test.ConstProp.diff
mutable_variable_aggregate_mut_ref.main.ConstProp.diff
mutable_variable_aggregate_mut_ref.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mutable_variable_aggregate_partial_read.main.ConstProp.panic-abort.diff
mutable_variable_aggregate_partial_read.main.ConstProp.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
mutable_variable_aggregate_partial_read.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mutable_variable_aggregate.main.ConstProp.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
mutable_variable_aggregate.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mutable_variable_no_prop.main.ConstProp.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
mutable_variable_no_prop.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mutable_variable_unprop_assign.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
mutable_variable_unprop_assign.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
mutable_variable_unprop_assign.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
mutable_variable.main.ConstProp.diff
mutable_variable.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
offset_of.concrete.ConstProp.panic-abort.diff Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
offset_of.concrete.ConstProp.panic-unwind.diff Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
offset_of.generic.ConstProp.panic-abort.diff Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
offset_of.generic.ConstProp.panic-unwind.diff Update MIR tests for offset_of 2023-10-31 23:26:02 +00:00
offset_of.rs Feature gate enums in offset_of 2023-11-03 13:16:47 +00:00
overwrite_with_const_with_params.rs Rename and add another test 2023-11-28 23:17:28 +00:00
overwrite_with_const_with_params.size_of.ConstProp.diff Rename and add another test 2023-11-28 23:17:28 +00:00
read_immutable_static.main.ConstProp.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
read_immutable_static.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
ref_deref_project.main.ConstProp.diff
ref_deref_project.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
ref_deref.main.ConstProp.diff
ref_deref.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
reify_fn_ptr.main.ConstProp.diff Rename adjustment::PointerCast and variants using it to PointerCoercion 2023-07-07 18:17:16 +02:00
reify_fn_ptr.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
repeat.main.ConstProp.32bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
repeat.main.ConstProp.32bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
repeat.main.ConstProp.64bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
repeat.main.ConstProp.64bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
repeat.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
return_place.add.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
return_place.add.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
return_place.add.PreCodegen.before.panic-abort.mir Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
return_place.add.PreCodegen.before.panic-unwind.mir Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
return_place.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
scalar_literal_propagation.main.ConstProp.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
scalar_literal_propagation.main.ConstProp.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
scalar_literal_propagation.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
slice_len.main.ConstProp.32bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
slice_len.main.ConstProp.32bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
slice_len.main.ConstProp.64bit.panic-abort.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
slice_len.main.ConstProp.64bit.panic-unwind.diff Always propagate into operands. 2023-07-20 21:30:51 +00:00
slice_len.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
switch_int.main.ConstProp.panic-abort.diff
switch_int.main.ConstProp.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
switch_int.main.SimplifyConstCondition-after-const-prop.panic-abort.diff
switch_int.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff Bless tests 2023-06-23 18:36:25 +01:00
switch_int.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
transmute.from_char.ConstProp.32bit.diff
transmute.from_char.ConstProp.64bit.diff
transmute.invalid_bool.ConstProp.32bit.diff
transmute.invalid_bool.ConstProp.64bit.diff
transmute.invalid_char.ConstProp.32bit.diff
transmute.invalid_char.ConstProp.64bit.diff
transmute.less_as_i8.ConstProp.32bit.diff
transmute.less_as_i8.ConstProp.64bit.diff
transmute.rs FileCheck transmute. 2023-10-19 15:51:54 +00:00
transmute.undef_union_as_integer.ConstProp.32bit.diff
transmute.undef_union_as_integer.ConstProp.64bit.diff
transmute.unreachable_box.ConstProp.32bit.diff Use PlaceMention for match scrutinees. 2023-10-24 15:30:17 +00:00
transmute.unreachable_box.ConstProp.64bit.diff Use PlaceMention for match scrutinees. 2023-10-24 15:30:17 +00:00
transmute.unreachable_direct.ConstProp.32bit.diff
transmute.unreachable_direct.ConstProp.64bit.diff
transmute.unreachable_mut.ConstProp.32bit.diff
transmute.unreachable_mut.ConstProp.64bit.diff
transmute.unreachable_ref.ConstProp.32bit.diff
transmute.unreachable_ref.ConstProp.64bit.diff
transmute.valid_char.ConstProp.32bit.diff
transmute.valid_char.ConstProp.64bit.diff
tuple_literal_propagation.main.ConstProp.panic-abort.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
tuple_literal_propagation.main.ConstProp.panic-unwind.diff Normalize alloc-id in tests. 2023-10-16 16:29:35 +00:00
tuple_literal_propagation.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00
while_let_loops.change_loop_body.ConstProp.diff
while_let_loops.rs Allow to run filecheck in mir-opt tests. 2023-10-19 15:51:52 +00:00