Skip to content

Commit 8a61d49

Browse files
committed
make inliner remove the fn_entry flag on Retag statements
1 parent 96ba4af commit 8a61d49

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

src/librustc/mir/visit.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ macro_rules! make_mir_visitor {
152152
self.super_ascribe_user_ty(place, variance, user_ty, location);
153153
}
154154

155+
fn visit_retag(&mut self,
156+
fn_entry: & $($mutability)* bool,
157+
place: & $($mutability)* Place<'tcx>,
158+
location: Location) {
159+
self.super_retag(fn_entry, place, location);
160+
}
161+
155162
fn visit_place(&mut self,
156163
place: & $($mutability)* Place<'tcx>,
157164
context: PlaceContext<'tcx>,
@@ -371,13 +378,6 @@ macro_rules! make_mir_visitor {
371378
);
372379
}
373380
StatementKind::EndRegion(_) => {}
374-
StatementKind::Retag { fn_entry: _, ref $($mutability)* place } => {
375-
self.visit_place(
376-
place,
377-
PlaceContext::MutatingUse(MutatingUseContext::Retag),
378-
location,
379-
);
380-
}
381381
StatementKind::SetDiscriminant{ ref $($mutability)* place, .. } => {
382382
self.visit_place(
383383
place,
@@ -413,6 +413,9 @@ macro_rules! make_mir_visitor {
413413
self.visit_operand(input, location);
414414
}
415415
}
416+
StatementKind::Retag { ref $($mutability)* fn_entry, ref $($mutability)* place } => {
417+
self.visit_retag(fn_entry, place, location);
418+
}
416419
StatementKind::AscribeUserType(
417420
ref $($mutability)* place,
418421
ref $($mutability)* variance,
@@ -715,6 +718,17 @@ macro_rules! make_mir_visitor {
715718
self.visit_user_type_projection(user_ty);
716719
}
717720

721+
fn super_retag(&mut self,
722+
_fn_entry: & $($mutability)* bool,
723+
place: & $($mutability)* Place<'tcx>,
724+
location: Location) {
725+
self.visit_place(
726+
place,
727+
PlaceContext::MutatingUse(MutatingUseContext::Retag),
728+
location,
729+
);
730+
}
731+
718732
fn super_place(&mut self,
719733
place: & $($mutability)* Place<'tcx>,
720734
context: PlaceContext<'tcx>,

src/librustc_mir/transform/inline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
691691
self.in_cleanup_block = false;
692692
}
693693

694+
fn visit_retag(&mut self, fn_entry: &mut bool, place: &mut Place<'tcx>, loc: Location) {
695+
self.super_retag(fn_entry, place, loc);
696+
697+
// We have to patch all inlined retags to be aware that they are no longer
698+
// happening on function entry.
699+
*fn_entry = false;
700+
}
701+
694702
fn visit_terminator_kind(&mut self, block: BasicBlock,
695703
kind: &mut TerminatorKind<'tcx>, loc: Location) {
696704
self.super_terminator_kind(block, kind, loc);

src/test/mir-opt/inline-retag.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z span_free_formats -Z mir-emit-retag
12+
13+
// Tests that MIR inliner fixes up `Retag`'s `fn_entry` flag
14+
15+
fn main() {
16+
println!("{}", bar());
17+
}
18+
19+
#[inline(always)]
20+
fn foo(x: &i32, y: &i32) -> bool {
21+
*x == *y
22+
}
23+
24+
fn bar() -> bool {
25+
let f = foo;
26+
f(&1, &-1)
27+
}
28+
29+
// END RUST SOURCE
30+
// START rustc.bar.Inline.after.mir
31+
// ...
32+
// bb0: {
33+
// ...
34+
// Retag(_3);
35+
// Retag(_6);
36+
// StorageLive(_9);
37+
// _9 = (*_3);
38+
// StorageLive(_10);
39+
// _10 = (*_6);
40+
// _0 = Eq(move _9, move _10);
41+
// ...
42+
// return;
43+
// }
44+
// ...
45+
// END rustc.bar.Inline.after.mir

0 commit comments

Comments
 (0)