Skip to content

Commit

Permalink
mir-opt tests: rename unit-test -> test-mir-pass
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 20, 2024
1 parent a61b14d commit 75d0fdd
Show file tree
Hide file tree
Showing 152 changed files with 157 additions and 156 deletions.
6 changes: 3 additions & 3 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ mod directives {
pub const STDERR_PER_BITWIDTH: &'static str = "stderr-per-bitwidth";
pub const INCREMENTAL: &'static str = "incremental";
pub const KNOWN_BUG: &'static str = "known-bug";
pub const MIR_UNIT_TEST: &'static str = "unit-test";
pub const TEST_MIR_PASS: &'static str = "test-mir-pass";
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
pub const COMPARE_OUTPUT_LINES_BY_SUBSET: &'static str = "compare-output-lines-by-subset";
pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
Expand Down Expand Up @@ -549,7 +549,7 @@ impl TestProps {

config.set_name_value_directive(
ln,
MIR_UNIT_TEST,
TEST_MIR_PASS,
&mut self.mir_unit_test,
|s| s.trim().to_string(),
);
Expand Down Expand Up @@ -922,7 +922,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"should-fail",
"should-ice",
"stderr-per-bitwidth",
"unit-test",
"test-mir-pass",
"unset-exec-env",
"unset-rustc-env",
// tidy-alphabetical-end
Expand Down
7 changes: 4 additions & 3 deletions tests/mir-opt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ presence of pointers in constants or other bit width dependent things. In that c

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

## Unit testing
## Testing a particular MIR pass

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
//@ test-mir-pass: 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.
you expected and your test won't break when other code changes. This also lets you test passes
that are disabled by default.

## Emit a diff of the mir for a specific optimization

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/array_index_is_temporary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: SimplifyCfg-pre-optimizations
//@ test-mir-pass: SimplifyCfg-pre-optimizations
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// Retagging (from Stacked Borrows) relies on the array index being a fresh
// temporary, so that side-effects cannot change it.
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/basic_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: ElaborateDrops
//@ test-mir-pass: ElaborateDrops
//@ needs-unwind
// this tests move up progration, which is not yet implemented

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/box_expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: ElaborateDrops
//@ test-mir-pass: ElaborateDrops
//@ needs-unwind

#![feature(rustc_attrs, stmt_expr_attributes)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_allocation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
static FOO: &[(Option<i32>, &[&str])] =
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_allocation2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR const_allocation2.main.GVN.after.mir
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_allocation3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR const_allocation3.main.GVN.after.mir
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: ConstDebugInfo
//@ test-mir-pass: ConstDebugInfo
//@ compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN

struct Point {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/address_of_pair.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR address_of_pair.fn0.GVN.diff
pub fn fn0() -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -O

// EMIT_MIR aggregate.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/array_index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/bad_op_div_by_zero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

// EMIT_MIR bad_op_div_by_zero.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/bad_op_mod_by_zero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

// EMIT_MIR bad_op_mod_by_zero.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/boolean_identities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR boolean_identities.test.GVN.diff
pub fn test(x: bool, y: bool) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/boxes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -O
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR cast.main.GVN.diff

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/checked_add.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -C overflow-checks=on

// EMIT_MIR checked_add.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/control_flow_simplification.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-opt-level=1

trait NeedsDrop: Sized {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/discriminant.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// FIXME(wesleywiser): Ideally, we could const-prop away all of this and just be left with
// `let x = 42` but that doesn't work because const-prop doesn't support `Operand::Indirect`
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/indirect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -C overflow-checks=on

// EMIT_MIR indirect.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/indirect_mutation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// Check that we do not propagate past an indirect mutation.
#![feature(raw_ref_op)]

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/inherit_overflow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-enable-passes=+Inline

// After inlining, this will contain a `CheckedBinaryOp`.
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/invalid_constant.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-enable-passes=+RemoveZsts
// Verify that we can pretty print invalid constants.

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/issue_66971.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN

// Due to a bug in propagating scalar pairs the assertion below used to fail. In the expected
// outputs below, after GVN this is how _2 would look like with the bug:
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/issue_67019.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN

// This used to ICE in const-prop

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/large_array_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/mult_by_zero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mult_by_zero.test.GVN.diff
fn test(x: i32) -> i32 {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/mutable_variable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mutable_variable.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/mutable_variable_aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mutable_variable_aggregate.main.GVN.diff
fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mutable_variable_aggregate_mut_ref.main.GVN.diff
fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mutable_variable_aggregate_partial_read.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/mutable_variable_no_prop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// Verify that we do not propagate the contents of this mutable static.
static mut STATIC: u32 = 0x42424242;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/mutable_variable_unprop_assign.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR mutable_variable_unprop_assign.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/offset_of.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// skip-filecheck
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![feature(offset_of_enum, offset_of_nested)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -O

// Regression test for https://github.com/rust-lang/rust/issues/118328
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/pointer_expose_provenance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: GVN
//@ test-mir-pass: GVN

#[inline(never)]
fn read(_: usize) { }
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/read_immutable_static.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

static FOO: u8 = 2;

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/ref_deref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR ref_deref.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/ref_deref_project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This does not currently propagate (#67862)
//@ unit-test: GVN
//@ test-mir-pass: GVN

// EMIT_MIR ref_deref_project.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/reify_fn_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR reify_fn_ptr.main.GVN.diff

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/repeat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/return_place.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ compile-flags: -C overflow-checks=on

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/scalar_literal_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

// EMIT_MIR scalar_literal_propagation.main.GVN.diff
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/slice_len.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-enable-passes=+InstSimplify
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/switch_int.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -Zmir-enable-passes=+SimplifyConstCondition-after-const-prop
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/transmute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
//@ compile-flags: -O --crate-type=lib
//@ ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/tuple_literal_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR tuple_literal_propagation.main.GVN.diff

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/while_let_loops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ unit-test: GVN
//@ test-mir-pass: GVN
// EMIT_MIR while_let_loops.change_loop_body.GVN.diff

pub fn change_loop_body() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/copy-prop/borrowed_local.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: CopyProp
//@ test-mir-pass: CopyProp

#![feature(custom_mir, core_intrinsics)]
#![allow(unused_assignments)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/copy-prop/branch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//! Tests that we bail out when there are multiple assignments to the same local.
//@ unit-test: CopyProp
//@ test-mir-pass: CopyProp
fn val() -> i32 {
1
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/copy-prop/calls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// skip-filecheck
// Check that CopyProp does propagate return values of call terminators.
//@ unit-test: CopyProp
//@ test-mir-pass: CopyProp
//@ needs-unwind

#![feature(custom_mir, core_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/copy-prop/copy_propagation_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// Check that CopyProp does not propagate an assignment to a function argument
// (doing so can break usages of the original argument value)
//@ unit-test: CopyProp
//@ test-mir-pass: CopyProp
fn dummy(x: u8) -> u8 {
x
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/copy-prop/custom_move_arg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ unit-test: CopyProp
//@ test-mir-pass: CopyProp

#![feature(custom_mir, core_intrinsics)]
#![allow(unused_assignments)]
Expand Down
Loading

0 comments on commit 75d0fdd

Please sign in to comment.