Skip to content

Commit a084e06

Browse files
committedJan 4, 2024
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.
1 parent 12b92c8 commit a084e06

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed
 

‎compiler/rustc_mir_transform/src/pass_manager.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ fn run_passes_inner<'tcx>(
109109
phase_change: Option<MirPhase>,
110110
validate_each: bool,
111111
) {
112-
let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip();
113-
let validate = validate_each & tcx.sess.opts.unstable_opts.validate_mir & !body.should_skip();
114112
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
115113
trace!(?overridden_passes);
116114

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

119117
if !body.should_skip() {
118+
let validate = validate_each & tcx.sess.opts.unstable_opts.validate_mir;
119+
let lint = tcx.sess.opts.unstable_opts.lint_mir;
120+
120121
for pass in passes {
121122
let name = pass.name();
122123

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

164165
dump_mir_for_phase_change(tcx, body);
165-
if validate || new_phase == MirPhase::Runtime(RuntimePhase::Optimized) {
166+
167+
let validate =
168+
(validate_each & tcx.sess.opts.unstable_opts.validate_mir & !body.should_skip())
169+
|| new_phase == MirPhase::Runtime(RuntimePhase::Optimized);
170+
let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip();
171+
if validate {
166172
validate_body(tcx, body, format!("after phase change to {}", new_phase.name()));
167173
}
168174
if lint {

‎tests/mir-opt/copy-prop/custom_move_arg.f.CopyProp.panic-unwind.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

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

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

2121
bb2: {

‎tests/mir-opt/copy-prop/custom_move_arg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use core::intrinsics::mir::*;
1010
struct NotCopy(bool);
1111

1212
// EMIT_MIR custom_move_arg.f.CopyProp.diff
13-
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
13+
#[custom_mir(dialect = "runtime")]
1414
fn f(_1: NotCopy) {
1515
mir!({
1616
let _2 = _1;
17-
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindContinue())
17+
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
1818
}
1919
bb1 = {
2020
let _3 = Move(_2);
21-
Call(RET = opaque(_3), ReturnTo(bb2), UnwindContinue())
21+
Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable())
2222
}
2323
bb2 = {
2424
Return()

‎tests/mir-opt/copy-prop/move_projection.f.CopyProp.panic-unwind.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
bb0: {
1010
- _2 = _1;
1111
- _3 = move (_2.0: u8);
12-
- _0 = opaque::<Foo>(move _1) -> [return: bb1, unwind continue];
12+
- _0 = opaque::<Foo>(move _1) -> [return: bb1, unwind unreachable];
1313
+ _3 = (_1.0: u8);
14-
+ _0 = opaque::<Foo>(_1) -> [return: bb1, unwind continue];
14+
+ _0 = opaque::<Foo>(_1) -> [return: bb1, unwind unreachable];
1515
}
1616

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

2121
bb2: {

‎tests/mir-opt/copy-prop/move_projection.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ fn opaque(_: impl Sized) -> bool { true }
1111

1212
struct Foo(u8);
1313

14-
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
14+
#[custom_mir(dialect = "runtime")]
1515
fn f(a: Foo) -> bool {
1616
mir!(
1717
{
1818
let b = a;
1919
// This is a move out of a copy, so must become a copy of `a.0`.
2020
let c = Move(b.0);
21-
Call(RET = opaque(Move(a)), ReturnTo(bb1), UnwindContinue())
21+
Call(RET = opaque(Move(a)), ReturnTo(bb1), UnwindUnreachable())
2222
}
2323
bb1 = {
24-
Call(RET = opaque(Move(c)), ReturnTo(ret), UnwindContinue())
24+
Call(RET = opaque(Move(c)), ReturnTo(ret), UnwindUnreachable())
2525
}
2626
ret = {
2727
Return()

0 commit comments

Comments
 (0)
Please sign in to comment.