From d97a7d259432e50bb1c9daaeb9e1174d51f2aaee Mon Sep 17 00:00:00 2001 From: =?utf8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 11 Sep 2017 12:15:35 +0200 Subject: [PATCH] Make sure we aren't using dead locals --- src/librustc_mir/transform/generator.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 3be21b72731..0517963a1a0 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -244,6 +244,12 @@ fn visit_basic_block_data(&mut self, if let Some((state_idx, resume, v, drop)) = ret_val { let source_info = data.terminator().source_info; + // We must assign the value first in case it gets declared dead below + data.statements.push(Statement { + source_info, + kind: StatementKind::Assign(Lvalue::Local(RETURN_POINTER), + self.make_state(state_idx, v)), + }); let state = if let Some(resume) = resume { // Yield let state = 3 + self.suspension_points.len() as u32; @@ -272,11 +278,6 @@ fn visit_basic_block_data(&mut self, 1 // state for returned }; data.statements.push(self.set_state(state, source_info)); - data.statements.push(Statement { - source_info, - kind: StatementKind::Assign(Lvalue::Local(RETURN_POINTER), - self.make_state(state_idx, v)), - }); data.terminator.as_mut().unwrap().kind = TerminatorKind::Return; } -- 2.44.0