Skip to content

Commit

Permalink
Fix validation and linting of injected MIR
Browse files Browse the repository at this point in the history
Reevaluate `body.should_skip()` after updating the MIR phase to ensure
that injected MIR is processed correctly.

Update a few custom MIR tests that were ill-formed for the injected
phase.
  • Loading branch information
tmiasko committed Jan 4, 2024
1 parent 1dc1c49 commit 6e9a4e5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
12 changes: 9 additions & 3 deletions compiler/rustc_mir_transform/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ fn run_passes_inner<'tcx>(
phase_change: Option<MirPhase>,
validate_each: bool,
) {
let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip();
let validate = validate_each & tcx.sess.opts.unstable_opts.validate_mir & !body.should_skip();
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
trace!(?overridden_passes);

let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));

if !body.should_skip() {
let validate = validate_each & tcx.sess.opts.unstable_opts.validate_mir;
let lint = tcx.sess.opts.unstable_opts.lint_mir;

for pass in passes {
let name = pass.name();

Expand Down Expand Up @@ -162,7 +163,12 @@ fn run_passes_inner<'tcx>(
body.pass_count = 0;

dump_mir_for_phase_change(tcx, body);
if validate || new_phase == MirPhase::Runtime(RuntimePhase::Optimized) {

let validate =
(validate_each & tcx.sess.opts.unstable_opts.validate_mir & !body.should_skip())
|| new_phase == MirPhase::Runtime(RuntimePhase::Optimized);
let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip();
if validate {
validate_body(tcx, body, format!("after phase change to {}", new_phase.name()));
}
if lint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

bb0: {
- _2 = _1;
- _0 = opaque::<NotCopy>(move _1) -> [return: bb1, unwind continue];
+ _0 = opaque::<NotCopy>(_1) -> [return: bb1, unwind continue];
- _0 = opaque::<NotCopy>(move _1) -> [return: bb1, unwind unreachable];
+ _0 = opaque::<NotCopy>(_1) -> [return: bb1, unwind unreachable];
}

bb1: {
- _3 = move _2;
- _0 = opaque::<NotCopy>(_3) -> [return: bb2, unwind continue];
+ _0 = opaque::<NotCopy>(_1) -> [return: bb2, unwind continue];
- _0 = opaque::<NotCopy>(_3) -> [return: bb2, unwind unreachable];
+ _0 = opaque::<NotCopy>(_1) -> [return: bb2, unwind unreachable];
}

bb2: {
Expand Down
6 changes: 3 additions & 3 deletions tests/mir-opt/copy-prop/custom_move_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use core::intrinsics::mir::*;
struct NotCopy(bool);

// EMIT_MIR custom_move_arg.f.CopyProp.diff
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
#[custom_mir(dialect = "runtime")]
fn f(_1: NotCopy) {
mir!({
let _2 = _1;
Call(RET = opaque(Move(_1)), bb1, UnwindContinue())
Call(RET = opaque(Move(_1)), bb1, UnwindUnreachable())
}
bb1 = {
let _3 = Move(_2);
Call(RET = opaque(_3), bb2, UnwindContinue())
Call(RET = opaque(_3), bb2, UnwindUnreachable())
}
bb2 = {
Return()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
bb0: {
- _2 = _1;
- _3 = move (_2.0: u8);
- _0 = opaque::<Foo>(move _1) -> [return: bb1, unwind continue];
- _0 = opaque::<Foo>(move _1) -> [return: bb1, unwind unreachable];
+ _3 = (_1.0: u8);
+ _0 = opaque::<Foo>(_1) -> [return: bb1, unwind continue];
+ _0 = opaque::<Foo>(_1) -> [return: bb1, unwind unreachable];
}

bb1: {
_0 = opaque::<u8>(move _3) -> [return: bb2, unwind continue];
_0 = opaque::<u8>(move _3) -> [return: bb2, unwind unreachable];
}

bb2: {
Expand Down
6 changes: 3 additions & 3 deletions tests/mir-opt/copy-prop/move_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ fn opaque(_: impl Sized) -> bool { true }

struct Foo(u8);

#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
#[custom_mir(dialect = "runtime")]
fn f(a: Foo) -> bool {
mir!(
{
let b = a;
// This is a move out of a copy, so must become a copy of `a.0`.
let c = Move(b.0);
Call(RET = opaque(Move(a)), bb1, UnwindContinue())
Call(RET = opaque(Move(a)), bb1, UnwindUnreachable())
}
bb1 = {
Call(RET = opaque(Move(c)), ret, UnwindContinue())
Call(RET = opaque(Move(c)), ret, UnwindUnreachable())
}
ret = {
Return()
Expand Down

0 comments on commit 6e9a4e5

Please sign in to comment.