Skip to content
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

Generate StorageLive after DropAndReplace for locals #61060

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc::mir::*;
use rustc::util::nodemap::FxHashMap;
use rustc_data_structures::bit_set::BitSet;
use std::fmt;
use std::iter;
use syntax_pos::Span;

pub struct ElaborateDrops;
Expand Down Expand Up @@ -468,14 +469,22 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let terminator = data.terminator();
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");

let storage_live = match location {
Place::Base(PlaceBase::Local(local)) => Some(Statement {
kind: StatementKind::StorageLive(*local),
source_info: terminator.source_info
}),
_ => None,
};
let assign = Statement {
kind: StatementKind::Assign(location.clone(), box Rvalue::Use(value.clone())),
source_info: terminator.source_info
};
let statements = storage_live.into_iter().chain(iter::once(assign)).collect::<Vec<_>>();

let unwind = unwind.unwrap_or_else(|| self.patch.resume_block());
let unwind = self.patch.new_block(BasicBlockData {
statements: vec![assign.clone()],
statements: statements.clone(),
terminator: Some(Terminator {
kind: TerminatorKind::Goto { target: unwind },
..*terminator
Expand All @@ -484,7 +493,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
});

let target = self.patch.new_block(BasicBlockData {
statements: vec![assign],
statements,
terminator: Some(Terminator {
kind: TerminatorKind::Goto { target },
..*terminator
Expand Down