rust/tests/mir-opt
Dylan DPC a3eb2f0f22
Rollup merge of #109664 - m-ou-se:format-args-placeholder-span, r=oli-obk
Use span of placeholders in format_args!() expansion.

`format_args!("{}", x)` expands to something that contains `Argument::new_display(&x)`. That entire expression was generated with the span of `x`.

After this PR, `&x` uses the span of `x`, but the `new_display` call uses the span of the `{}` placeholder within the format string. If an implicitly captured argument was used like in `format_args!("{x}")`, both use the span of the `{x}` placeholder.

This fixes https://github.com/rust-lang/rust/issues/109576, and also allows for more improvements to similar diagnostics in the future, since the usage of `x` can now be traced to the exact `{}` placeholder that required it to be `Display` (or `Debug` etc.)
2023-03-29 14:07:28 +05:30
..
building Auto merge of #106428 - saethlin:inline-diverging-functions, r=cjgillot 2023-03-26 05:55:32 +00:00
const_prop Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
copy-prop
dataflow-const-prop
dead-store-elimination
deref-patterns
dest-prop
inline Ignore the unwrap_unchecked test on wasm32-unknown-unknown 2023-03-25 19:33:19 -04:00
issues Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
nll
sroa Bless mir-opt tests. 2023-03-27 14:57:02 +02:00
address_of.address_of_reborrow.SimplifyCfg-initial.after.mir
address_of.borrow_and_cast.SimplifyCfg-initial.after.mir
address_of.rs
array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir
array_index_is_temporary.rs
asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir
asm_unwind_panic_abort.rs
basic_assignment.main.ElaborateDrops.diff
basic_assignment.main.SimplifyCfg-initial.after.mir
basic_assignment.rs
bool_compare.opt1.InstCombine.diff
bool_compare.opt2.InstCombine.diff
bool_compare.opt3.InstCombine.diff
bool_compare.opt4.InstCombine.diff
bool_compare.rs
box_expr.main.ElaborateDrops.before.mir Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
box_expr.rs Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
byte_slice.main.SimplifyCfg-elaborate-drops.after.mir
byte_slice.rs
casts.redundant.InstCombine.diff
casts.redundant.PreCodegen.after.mir
casts.roundtrip.PreCodegen.after.mir
casts.rs
combine_array_len.norm2.InstCombine.diff
combine_array_len.rs
combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
combine_clone_of_primitives.rs
combine_transmutes.adt_transmutes.InstCombine.diff Simplify transmutes in MIR InstCombine 2023-03-28 18:18:10 -07:00
combine_transmutes.identity_transmutes.InstCombine.diff Simplify transmutes in MIR InstCombine 2023-03-28 18:18:10 -07:00
combine_transmutes.integer_transmutes.InstCombine.diff Simplify transmutes in MIR InstCombine 2023-03-28 18:18:10 -07:00
combine_transmutes.rs Simplify transmutes in MIR InstCombine 2023-03-28 18:18:10 -07:00
const_allocation2.main.ConstProp.after.32bit.mir
const_allocation2.main.ConstProp.after.64bit.mir
const_allocation2.rs
const_allocation3.main.ConstProp.after.32bit.mir
const_allocation3.main.ConstProp.after.64bit.mir
const_allocation3.rs
const_allocation.main.ConstProp.after.32bit.mir
const_allocation.main.ConstProp.after.64bit.mir
const_allocation.rs
const_debuginfo.main.ConstDebugInfo.diff
const_debuginfo.rs
const_goto_const_eval_fail.f.ConstGoto.diff
const_goto_const_eval_fail.rs
const_goto_storage.match_nested_if.ConstGoto.diff
const_goto_storage.rs
const_goto.issue_77355_opt.ConstGoto.diff
const_goto.rs
const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir
const_promotion_extern_static.BAR.PromoteTemps.diff
const_promotion_extern_static.BOP.built.after.mir
const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir
const_promotion_extern_static.FOO.PromoteTemps.diff
const_promotion_extern_static.rs
const_prop_miscompile.bar.ConstProp.diff
const_prop_miscompile.foo.ConstProp.diff
const_prop_miscompile.rs
coverage_graphviz.bar.InstrumentCoverage.0.dot
coverage_graphviz.main.InstrumentCoverage.0.dot
coverage_graphviz.rs
deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff
deduplicate_blocks.rs
derefer_complex_case.main.Derefer.diff
derefer_complex_case.rs
derefer_inline_test.main.Derefer.diff Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
derefer_inline_test.rs Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
derefer_terminator_test.main.Derefer.diff
derefer_terminator_test.rs
derefer_test_multiple.main.Derefer.diff
derefer_test_multiple.rs
derefer_test.main.Derefer.diff
derefer_test.rs
div_overflow.const_dividend.PreCodegen.after.mir
div_overflow.const_divisor.PreCodegen.after.mir
div_overflow.rs
dont_yeet_assert.generic.InstCombine.diff
dont_yeet_assert.rs
early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff
early_otherwise_branch_3_element_tuple.rs
early_otherwise_branch_68867.rs
early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff
early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff
early_otherwise_branch_noopt.rs
early_otherwise_branch_soundness.no_deref_ptr.EarlyOtherwiseBranch.diff
early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
early_otherwise_branch_soundness.rs
early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff
early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
early_otherwise_branch.rs
enum_opt.cand.EnumSizeOpt.32bit.diff
enum_opt.cand.EnumSizeOpt.64bit.diff
enum_opt.invalid.EnumSizeOpt.32bit.diff
enum_opt.invalid.EnumSizeOpt.64bit.diff
enum_opt.rs
enum_opt.trunc.EnumSizeOpt.32bit.diff
enum_opt.trunc.EnumSizeOpt.64bit.diff
enum_opt.unin.EnumSizeOpt.32bit.diff
enum_opt.unin.EnumSizeOpt.64bit.diff
equal_true.opt.InstCombine.diff
equal_true.rs
exponential_or.match_tuple.SimplifyCfg-initial.after.mir
exponential_or.rs
fn_ptr_shim.core.ops-function-Fn-call.AddMovesForPackedDrops.before.mir
fn_ptr_shim.rs
funky_arms.float_to_exponential_common.ConstProp.diff
funky_arms.rs
generator_drop_cleanup.main-{closure#0}.generator_drop.0.mir
generator_drop_cleanup.rs
generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.mir
generator_storage_dead_unwind.rs
generator_tiny.main-{closure#0}.generator_resume.0.mir
generator_tiny.rs
graphviz.main.built.after.dot
graphviz.rs
if_condition_int.dont_opt_bool.SimplifyComparisonIntegral.diff
if_condition_int.dont_opt_floats.SimplifyComparisonIntegral.diff
if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff
if_condition_int.opt_char.SimplifyComparisonIntegral.diff
if_condition_int.opt_i8.SimplifyComparisonIntegral.diff
if_condition_int.opt_multiple_ifs.SimplifyComparisonIntegral.diff
if_condition_int.opt_negative.SimplifyComparisonIntegral.diff
if_condition_int.opt_u32.SimplifyComparisonIntegral.diff
if_condition_int.rs
instcombine_duplicate_switch_targets.assert_zero.InstCombine.diff Remove duplicate switch targets 2023-03-18 14:29:13 -04:00
instcombine_duplicate_switch_targets.rs Remove duplicate switch targets 2023-03-18 14:29:13 -04:00
instrument_coverage.bar.InstrumentCoverage.diff
instrument_coverage.main.InstrumentCoverage.diff
instrument_coverage.rs
intrinsic_asserts.generic.InstCombine.diff Generalize operation. 2023-03-13 18:22:55 +00:00
intrinsic_asserts.panics.InstCombine.diff Generalize operation. 2023-03-13 18:22:55 +00:00
intrinsic_asserts.removable.InstCombine.diff Generalize operation. 2023-03-13 18:22:55 +00:00
intrinsic_asserts.rs
issue_38669.main.SimplifyCfg-initial.after.mir
issue_38669.rs
issue_41110.main.ElaborateDrops.diff
issue_41110.rs
issue_41110.test.ElaborateDrops.diff
issue_41697.{impl#0}-{constant#0}.SimplifyCfg-promote-consts.after.mir
issue_41697.rs
issue_41888.main.ElaborateDrops.diff
issue_41888.rs
issue_62289.rs Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
issue_62289.test.ElaborateDrops.before.mir Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
issue_72181_1.f.built.after.mir
issue_72181_1.main.built.after.mir
issue_72181_1.rs
issue_72181.bar.built.after.mir
issue_72181.foo.built.after.mir
issue_72181.main.built.after.mir Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
issue_72181.rs
issue_76432.rs
issue_76432.test.SimplifyComparisonIntegral.diff Generalize operation. 2023-03-13 18:22:55 +00:00
issue_78192.f.InstCombine.diff
issue_78192.rs
issue_91633.bar.built.after.mir Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
issue_91633.foo.built.after.mir
issue_91633.fun.built.after.mir
issue_91633.hey.built.after.mir Introduce a no-op PlaceMention statement for let _ =. 2023-03-09 17:45:13 +00:00
issue_91633.rs
issue_99325.main.built.after.mir
issue_99325.rs
issue_101973.inner.ConstProp.diff Generate simpler MIR for shifts 2023-03-22 13:32:12 -07:00
issue_101973.rs
loop_test.main.SimplifyCfg-promote-consts.after.mir
loop_test.rs
lower_array_len.array_bound_mut.NormalizeArrayLen.diff
lower_array_len.array_bound.NormalizeArrayLen.diff
lower_array_len.array_len_by_value.NormalizeArrayLen.diff
lower_array_len.array_len_raw.NormalizeArrayLen.diff
lower_array_len.array_len_reborrow.NormalizeArrayLen.diff
lower_array_len.array_len.NormalizeArrayLen.diff
lower_array_len.rs
lower_intrinsics_e2e.f_u64.PreCodegen.after.mir Generalize operation. 2023-03-13 18:22:55 +00:00
lower_intrinsics_e2e.f_unit.PreCodegen.after.mir Generalize operation. 2023-03-13 18:22:55 +00:00
lower_intrinsics_e2e.rs
lower_intrinsics.align_of.LowerIntrinsics.diff
lower_intrinsics.assume.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.discriminant.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.forget.LowerIntrinsics.diff
lower_intrinsics.non_const.LowerIntrinsics.diff
lower_intrinsics.option_payload.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.rs Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.size_of.LowerIntrinsics.diff
lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.transmute_ref_dst.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.transmute_uninhabited.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.unreachable.LowerIntrinsics.diff
lower_intrinsics.with_overflow.LowerIntrinsics.diff Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
lower_intrinsics.wrapping.LowerIntrinsics.diff
lower_slice_len.bound.LowerSliceLenCalls.diff
lower_slice_len.rs
match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff
match_arm_scopes.rs
match_test.main.SimplifyCfg-initial.after.mir
match_test.rs
matches_reduce_branches.bar.MatchBranchSimplification.diff
matches_reduce_branches.foo.MatchBranchSimplification.diff
matches_reduce_branches.match_nested_if.MatchBranchSimplification.diff
matches_reduce_branches.rs
matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
matches_u8.exhaustive_match.MatchBranchSimplification.diff
matches_u8.rs
multiple_return_terminators.rs
multiple_return_terminators.test.MultipleReturnTerminators.diff
no_drop_for_inactive_variant.rs
no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir
no_spurious_drop_after_call.main.ElaborateDrops.before.mir
no_spurious_drop_after_call.rs
not_equal_false.opt.InstCombine.diff
not_equal_false.rs
nrvo_simple.nrvo.RenameReturnPlace.diff
nrvo_simple.rs
packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.mir
packed_struct_drop_aligned.rs
README.md
remove_fake_borrows.match_guard.CleanupPostBorrowck.diff
remove_fake_borrows.rs
remove_never_const.no_codegen.PreCodegen.after.mir
remove_never_const.rs
remove_storage_markers.main.RemoveStorageMarkers.diff
remove_storage_markers.rs
remove_unneeded_drops.cannot_opt_generic.RemoveUnneededDrops.diff Generalize operation. 2023-03-13 18:22:55 +00:00
remove_unneeded_drops.dont_opt.RemoveUnneededDrops.diff Generalize operation. 2023-03-13 18:22:55 +00:00
remove_unneeded_drops.opt_generic_copy.RemoveUnneededDrops.diff Generalize operation. 2023-03-13 18:22:55 +00:00
remove_unneeded_drops.opt.RemoveUnneededDrops.diff Generalize operation. 2023-03-13 18:22:55 +00:00
remove_unneeded_drops.rs
remove_zsts.get_union.PreCodegen.after.mir Replace ZST operands and debuginfo by constants. 2023-03-13 18:19:57 +00:00
remove_zsts.get_union.RemoveZsts.diff Generalize operation. 2023-03-13 18:22:55 +00:00
remove_zsts.rs
retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir
retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir
retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir
retag.main.SimplifyCfg-elaborate-drops.after.mir
retag.rs
return_an_array.rs
separate_const_switch.identity.SeparateConstSwitch.diff Wrap the whole LocalInfo in ClearCrossCrate. 2023-03-14 20:52:42 +01:00
separate_const_switch.rs
separate_const_switch.too_complex.SeparateConstSwitch.diff Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
simple_option_map_e2e.ezmap.PreCodegen.after.mir Replace ZST operands and debuginfo by constants. 2023-03-13 18:19:57 +00:00
simple_option_map_e2e.rs
simplify_arm_identity.rs
simplify_arm.id_try.SimplifyArmIdentity.diff
simplify_arm.id_try.SimplifyBranchSame.diff
simplify_arm.rs
simplify_cfg.main.SimplifyCfg-early-opt.diff
simplify_cfg.main.SimplifyCfg-initial.diff
simplify_cfg.rs
simplify_duplicate_unreachable_blocks.assert_nonzero_nonmax.SimplifyCfg-after-uninhabited-enum-branching.diff Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
simplify_duplicate_unreachable_blocks.rs Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
simplify_if.main.SimplifyConstCondition-after-const-prop.diff Generalize operation. 2023-03-13 18:22:55 +00:00
simplify_if.rs
simplify_locals_fixedpoint.foo.SimplifyLocals-final.diff
simplify_locals_fixedpoint.rs
simplify_locals_removes_unused_consts.main.SimplifyLocals-before-const-prop.diff
simplify_locals_removes_unused_consts.rs
simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals-before-const-prop.diff
simplify_locals_removes_unused_discriminant_reads.rs
simplify_locals.c.SimplifyLocals-before-const-prop.diff
simplify_locals.d1.SimplifyLocals-before-const-prop.diff
simplify_locals.d2.SimplifyLocals-before-const-prop.diff
simplify_locals.expose_addr.SimplifyLocals-before-const-prop.diff
simplify_locals.r.SimplifyLocals-before-const-prop.diff
simplify_locals.rs
simplify_locals.t1.SimplifyLocals-before-const-prop.diff
simplify_locals.t2.SimplifyLocals-before-const-prop.diff
simplify_locals.t3.SimplifyLocals-before-const-prop.diff
simplify_locals.t4.SimplifyLocals-before-const-prop.diff
simplify_match.main.ConstProp.diff
simplify_match.rs
simplify_try_if_let.{impl#0}-append.SimplifyArmIdentity.diff
simplify_try_if_let.rs
slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir Use index based drop loop for slices and arrays 2023-03-14 21:29:32 +01:00
slice_drop_shim.rs
slice_filter.rs
slice_filter.variant_a-{closure#0}.CopyProp.diff
slice_filter.variant_a-{closure#0}.DestinationPropagation.diff
slice_filter.variant_b-{closure#0}.CopyProp.diff
slice_filter.variant_b-{closure#0}.DestinationPropagation.diff
spanview_block.main.built.after.html
spanview_block.rs
spanview_statement.main.built.after.html
spanview_statement.rs
spanview_terminator.main.built.after.html
spanview_terminator.rs
storage_ranges.main.nll.0.mir
storage_ranges.rs
tls_access.main.PreCodegen.after.mir
tls_access.rs
try_identity_e2e.new.PreCodegen.after.mir Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
try_identity_e2e.old.PreCodegen.after.mir
try_identity_e2e.rs
uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
uninhabited_enum_branching2.rs
uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
uninhabited_enum_branching.main.UninhabitedEnumBranching.diff Remove duplicate unreachable blocks 2023-03-18 14:29:04 -04:00
uninhabited_enum_branching.rs
uninhabited_enum.process_never.SimplifyLocals-final.after.mir
uninhabited_enum.process_void.SimplifyLocals-final.after.mir
uninhabited_enum.rs
uninhabited_fallthrough_elimination.eliminate_fallthrough.UninhabitedEnumBranching.diff
uninhabited_fallthrough_elimination.keep_fallthrough.UninhabitedEnumBranching.diff
uninhabited_fallthrough_elimination.rs
unreachable_diverging.main.UnreachablePropagation.diff
unreachable_diverging.rs
unreachable.main.UnreachablePropagation.diff
unreachable.rs
unusual_item_types.{impl#0}-ASSOCIATED_CONSTANT.built.after.mir
unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
unusual_item_types.E-V-{constant#0}.built.after.mir
unusual_item_types.rs
unusual_item_types.Test-X-{constructor#0}.built.after.mir
while_let_loops.change_loop_body.ConstProp.diff
while_let_loops.change_loop_body.PreCodegen.after.mir
while_let_loops.rs
while_storage.rs
while_storage.while_loop.PreCodegen.after.mir

This folder contains tests for MIR optimizations.

The mir-opt test format emits MIR to extra files that you can automatically update by specifying --bless on the command line (just like ui tests updating .stderr files).

--blessable test format

By default 32 bit and 64 bit targets use the same dump files, which can be problematic in the presence of pointers in constants or other bit width dependent things. In that case you can add

// EMIT_MIR_FOR_EACH_BIT_WIDTH

to your test, causing separate files to be generated for 32bit and 64bit systems.

Unit testing

If you are only testing the behavior of a particular mir-opt pass on some specific input (as is usually the case), you should add

// unit-test: PassName

to the top of the file. This makes sure that other passes don't run which means you'll get the input you expected and your test won't break when other code changes.

Emit a diff of the mir for a specific optimization

This is what you want most often when you want to see how an optimization changes the MIR.

// EMIT_MIR $file_name_of_some_mir_dump.diff

Emit mir after a specific optimization

Use this if you are just interested in the final state after an optimization.

// EMIT_MIR $file_name_of_some_mir_dump.after.mir

Emit mir before a specific optimization

This exists mainly for completeness and is rarely useful.

// EMIT_MIR $file_name_of_some_mir_dump.before.mir