rust/src/test/mir-opt
Aaron Hill b5f8cd5c20
Fix ref-to-ptr coercions not working with NLL in certain cases
Implicit coercions from references to pointers were lowered to slightly
different Mir than explicit casts (e.g. 'foo as *mut T'). This resulted
in certain uses of self-referential structs compiling correctly when an
explicit cast was used, but not when the implicit coercion was used.

To fix this, this commit adds an outer 'Use' expr when applying a
raw-ptr-borrow adjustment. This makes the lowered Mir for coercions
identical to that of explicit coercions, allowing the original code to
compile regardless of how the raw ptr cast occurs.

Fixes #47722
2018-01-29 23:25:54 -05:00
..
nll convert region-liveness-drop{-,-no-}may-dangle.rs into ui tests 2017-12-20 14:38:13 -05:00
basic_assignment.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
box_expr.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
combine_array_len.rs InstCombine Len([_; N]) => const N in MIR 2017-11-25 11:59:16 -08:00
copy_propagation.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
copy_propagation_arg.rs Fix MIR CopyPropagation regression 2017-12-03 17:42:52 +09:00
deaggregator_test.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
deaggregator_test_enum.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
deaggregator_test_enum_2.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
deaggregator_test_multiple.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
end_region_1.rs change MIR dump filenames from nodeN to DefPath 2017-11-09 12:00:17 +03:00
end_region_2.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
end_region_3.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
end_region_4.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_5.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_6.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_7.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_8.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_9.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
end_region_cyclic.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
end_region_destruction_extents_1.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
inline-closure-borrows-arg.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
inline-closure.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
issue-38669.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
issue-41110.rs ci: Start running wasm32 tests on Travis 2017-11-28 09:27:35 -08:00
issue-41697.rs fix some typos 2017-11-21 15:33:45 +01:00
issue-41888.rs move "ADT master drop flag" logic to open_drop_for_adt_contents 2017-05-28 10:43:24 +03:00
issue-43457.rs change MIR dump filenames from nodeN to DefPath 2017-11-09 12:00:17 +03:00
lower_128bit_debug_test.rs Fix -Z lower_128bit_ops handling of statics 2017-12-19 15:08:17 -05:00
lower_128bit_test.rs Fix -Z lower_128bit_ops handling of statics 2017-12-19 15:08:17 -05:00
match_false_edges.rs fix tests in wasm 2017-12-03 14:50:47 +02:00
packed-struct-drop-aligned.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
README.md Update README and tests for new infrastructure 2017-10-09 23:22:34 -04:00
return_an_array.rs Add trailing newlines to files which have no trailing newlines. 2017-12-30 15:50:52 +08:00
simplify_if.rs funnel all unwind paths through a single Resume block 2017-12-03 02:47:44 +02:00
storage_live_dead_in_statics.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
storage_ranges.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
validate_1.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
validate_2.rs fix tests in wasm 2017-12-03 14:50:47 +02:00
validate_3.rs tests: update to include move annotations in MIR. 2017-11-28 04:18:32 +02:00
validate_4.rs initialize the destination in unit statements 2017-12-03 02:21:13 +02:00
validate_5.rs Fix ref-to-ptr coercions not working with NLL in certain cases 2018-01-29 23:25:54 -05:00

This folder contains tests for MIR optimizations.

The test format is:

(arbitrary rust code)
// END RUST SOURCE
// START $file_name_of_some_mir_dump_0
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_0
// (lines or elision)
// START $file_name_of_some_mir_dump_N
//  $expected_line_0
// (lines or elision)
// $expected_line_N
// END $file_name_of_some_mir_dump_N

All the test information is in comments so the test is runnable.

For each $file_name, compiletest expects [$expected_line_0, ..., $expected_line_N] to appear in the dumped MIR in order. Currently it allows other non-matched lines before and after, but not between $expected_lines, should you want to skip lines, you must include an elision comment, of the form (as a regex) //\s*...\s*. The lines will be skipped lazily, that is, if there are two identical lines in the output that match the line after the elision comment, the first one wil be matched.

Examples:

The following blocks will not match the one after it.

bb0: {
    StorageLive(_1);
    _1 = const true;
    StorageDead(_1);
}
bb0: {
    StorageLive(_1);
    _1 = const true;
    goto -> bb1
}
bb1: {
    StorageDead(_1);
    return;
}

But this will match the one above,

bb0: {
    StorageLive(_1);
    _1 = const true;
    ...
    StorageDead(_1);
    ...
}

Lines match ignoring whitespace, and the prefix "//" is removed.

It also currently strips trailing comments -- partly because the full file path in "scope comments" is unpredictable and partly because tidy complains about the lines being too long.

compiletest handles dumping the MIR before and after every pass for you. The test writer only has to specify the file names of the dumped files (not the full path to the file) and what lines to expect. There is an option to rustc that tells it to dump the mir into some directly (rather then always dumping to the current directory).