1
Fork 0

Fix validation and linting of injected MIR

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.
This commit is contained in:
Tomasz Miąsko 2024-01-01 00:00:00 +00:00
parent 12b92c8a87
commit a084e063e6
5 changed files with 22 additions and 16 deletions

View file

@ -109,14 +109,15 @@ fn run_passes_inner<'tcx>(
phase_change: Option<MirPhase>, phase_change: Option<MirPhase>,
validate_each: bool, 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; let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
trace!(?overridden_passes); trace!(?overridden_passes);
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id())); let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
if !body.should_skip() { 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 { for pass in passes {
let name = pass.name(); let name = pass.name();
@ -162,7 +163,12 @@ fn run_passes_inner<'tcx>(
body.pass_count = 0; body.pass_count = 0;
dump_mir_for_phase_change(tcx, body); 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())); validate_body(tcx, body, format!("after phase change to {}", new_phase.name()));
} }
if lint { if lint {

View file

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

View file

@ -10,15 +10,15 @@ use core::intrinsics::mir::*;
struct NotCopy(bool); struct NotCopy(bool);
// EMIT_MIR custom_move_arg.f.CopyProp.diff // EMIT_MIR custom_move_arg.f.CopyProp.diff
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "runtime")]
fn f(_1: NotCopy) { fn f(_1: NotCopy) {
mir!({ mir!({
let _2 = _1; let _2 = _1;
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindContinue()) Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
} }
bb1 = { bb1 = {
let _3 = Move(_2); let _3 = Move(_2);
Call(RET = opaque(_3), ReturnTo(bb2), UnwindContinue()) Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable())
} }
bb2 = { bb2 = {
Return() Return()

View file

@ -9,13 +9,13 @@
bb0: { bb0: {
- _2 = _1; - _2 = _1;
- _3 = move (_2.0: u8); - _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); + _3 = (_1.0: u8);
+ _0 = opaque::<Foo>(_1) -> [return: bb1, unwind continue]; + _0 = opaque::<Foo>(_1) -> [return: bb1, unwind unreachable];
} }
bb1: { bb1: {
_0 = opaque::<u8>(move _3) -> [return: bb2, unwind continue]; _0 = opaque::<u8>(move _3) -> [return: bb2, unwind unreachable];
} }
bb2: { bb2: {

View file

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