Skip to content

Proactively update coroutine drop shim's phase to account for later passes applied during shim query #139699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
@@ -1169,6 +1169,13 @@ fn create_coroutine_drop_shim<'tcx>(
dump_mir(tcx, false, "coroutine_drop", &0, &body, |_, _| Ok(()));
body.source.instance = drop_instance;

// Creating a coroutine drop shim happens on `Analysis(PostCleanup) -> Runtime(Initial)`
// but the pass manager doesn't update the phase of the coroutine drop shim. Update the
// phase of the drop shim so that later on when we run the pass manager on the shim, in
// the `mir_shims` query, we don't ICE on the intra-pass validation before we've updated
// the phase of the body from analysis.
body.phase = MirPhase::Runtime(RuntimePhase::Initial);

body
}

19 changes: 19 additions & 0 deletions tests/ui/async-await/post-cleanup-phase-validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ compile-flags: -Zvalidate-mir
//@ edition: 2024
//@ build-pass

// Regression test that we don't ICE when encountering a transmute in a coroutine's
// drop shim body, which is conceptually in the Runtime phase but wasn't having the
// phase updated b/c the pass manager neither optimizes nor updates the phase for
// drop shim bodies.

struct HasDrop;
impl Drop for HasDrop {
fn drop(&mut self) {}
}

fn main() {
async {
vec![async { HasDrop }.await];
};
}
Loading