From cd1a42a95d1fa9b5f67eda4b17b702c9521bf1f4 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 28 Aug 2022 01:39:59 -0400 Subject: [PATCH] Use the declaration's SourceInfo for FnEntry retags, not the outermost --- compiler/rustc_mir_transform/src/add_retag.rs | 19 ++++++++----------- ...soundness.retags.DeadStoreElimination.diff | 2 +- .../inline/inline_retag.bar.Inline.after.mir | 4 ++-- ...e#0}.SimplifyCfg-elaborate-drops.after.mir | 2 +- ...-foo.SimplifyCfg-elaborate-drops.after.mir | 4 ++-- ..._shr.SimplifyCfg-elaborate-drops.after.mir | 4 ++-- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 9c5896c4e4aed..036b5589849a2 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -66,7 +66,6 @@ impl<'tcx> MirPass<'tcx> for AddRetag { // We need an `AllCallEdges` pass before we can do any work. super::add_call_guards::AllCallEdges.run_pass(tcx, body); - let (span, arg_count) = (body.span, body.arg_count); let basic_blocks = body.basic_blocks.as_mut(); let local_decls = &body.local_decls; let needs_retag = |place: &Place<'tcx>| { @@ -90,20 +89,18 @@ impl<'tcx> MirPass<'tcx> for AddRetag { // PART 1 // Retag arguments at the beginning of the start block. { - // FIXME: Consider using just the span covering the function - // argument declaration. - let source_info = SourceInfo::outermost(span); // Gather all arguments, skip return value. - let places = local_decls - .iter_enumerated() - .skip(1) - .take(arg_count) - .map(|(local, _)| Place::from(local)) - .filter(needs_retag); + let places = local_decls.iter_enumerated().skip(1).take(body.arg_count).filter_map( + |(local, decl)| { + let place = Place::from(local); + needs_retag(&place).then_some((place, decl.source_info)) + }, + ); + // Emit their retags. basic_blocks[START_BLOCK].statements.splice( 0..0, - places.map(|place| Statement { + places.map(|(place, source_info)| Statement { source_info, kind: StatementKind::Retag(RetagKind::FnEntry, Box::new(place)), }), diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff index 300f0d5dcaa98..b5f98233b3d7a 100644 --- a/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff +++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff @@ -6,7 +6,7 @@ let mut _0: (); // return place in scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:25 bb0: { - Retag([fn entry] _1); // scope 0 at $DIR/provenance_soundness.rs:+0:1: +0:27 + Retag([fn entry] _1); // scope 0 at $DIR/provenance_soundness.rs:+0:11: +0:13 _0 = const (); // scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:27 return; // scope 0 at $DIR/provenance_soundness.rs:+0:27: +0:27 } diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir index 989fe2785869c..d5410d3afd4a5 100644 --- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir @@ -52,8 +52,8 @@ fn bar() -> bool { Retag(_7); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14 _6 = &(*_7); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14 Retag(_6); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14 - Retag(_3); // scope 2 at $DIR/inline-retag.rs:16:1: 18:2 - Retag(_6); // scope 2 at $DIR/inline-retag.rs:16:1: 18:2 + Retag(_3); // scope 2 at $DIR/inline-retag.rs:16:8: 16:9 + Retag(_6); // scope 2 at $DIR/inline-retag.rs:16:17: 16:18 StorageLive(_11); // scope 2 at $DIR/inline-retag.rs:17:5: 17:7 _11 = (*_3); // scope 2 at $DIR/inline-retag.rs:17:5: 17:7 StorageLive(_12); // scope 2 at $DIR/inline-retag.rs:17:11: 17:13 diff --git a/src/test/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir index faaacc67ea81f..d254a95e06bea 100644 --- a/src/test/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir @@ -10,7 +10,7 @@ fn main::{closure#0}(_1: &[closure@main::{closure#0}], _2: &i32) -> &i32 { bb0: { Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:31: +0:48 - Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:31: +0:48 + Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:32: +0:33 StorageLive(_3); // scope 0 at $DIR/retag.rs:42:13: 42:15 _3 = _2; // scope 0 at $DIR/retag.rs:42:18: 42:19 Retag(_3); // scope 0 at $DIR/retag.rs:42:18: 42:19 diff --git a/src/test/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir index 25d400f0c9fb2..08fd655ae29bb 100644 --- a/src/test/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir @@ -7,8 +7,8 @@ fn ::foo(_1: &Test, _2: &mut i32) -> &mut i32 let mut _3: &mut i32; // in scope 0 at $DIR/retag.rs:+1:9: +1:10 bb0: { - Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:5: +2:6 - Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:5: +2:6 + Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:16: +0:21 + Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:23: +0:24 StorageLive(_3); // scope 0 at $DIR/retag.rs:+1:9: +1:10 _3 = &mut (*_2); // scope 0 at $DIR/retag.rs:+1:9: +1:10 Retag(_3); // scope 0 at $DIR/retag.rs:+1:9: +1:10 diff --git a/src/test/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir index 84ad8afc35760..f32a84e4c791b 100644 --- a/src/test/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir @@ -6,8 +6,8 @@ fn ::foo_shr(_1: &Test, _2: &i32) -> &i32 { let mut _0: &i32; // return place in scope 0 at $DIR/retag.rs:+0:42: +0:49 bb0: { - Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:5: +2:6 - Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:5: +2:6 + Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:20: +0:25 + Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:27: +0:28 _0 = _2; // scope 0 at $DIR/retag.rs:+1:9: +1:10 Retag(_0); // scope 0 at $DIR/retag.rs:+1:9: +1:10 return; // scope 0 at $DIR/retag.rs:+2:6: +2:6