Skip to content

Commit 579f082

Browse files
authored
Rollup merge of #101111 - saethlin:better-fnentry-spans, r=RalfJung
Use the declaration's SourceInfo for FnEntry retags, not the outermost This addresses a long-standing `// FIXME` in the pass that adds retags. The changes to Miri's UI tests will look like this: ``` --> $DIR/aliasing_mut1.rs:LL:CC | LL | pub fn safe(_x: &mut i32, _y: &mut i32) {} < | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because incompatible item [Unique for <TAG>] is protected by call ID > | ^^ not granting access to tag <TAG> because incompatible item [Unique for <TAG>] is protected by call ID | ``` r? `@RalfJung`
2 parents b7b98e2 + cd1a42a commit 579f082

6 files changed

+16
-19
lines changed

compiler/rustc_mir_transform/src/add_retag.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
6666
// We need an `AllCallEdges` pass before we can do any work.
6767
super::add_call_guards::AllCallEdges.run_pass(tcx, body);
6868

69-
let (span, arg_count) = (body.span, body.arg_count);
7069
let basic_blocks = body.basic_blocks.as_mut();
7170
let local_decls = &body.local_decls;
7271
let needs_retag = |place: &Place<'tcx>| {
@@ -90,20 +89,18 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
9089
// PART 1
9190
// Retag arguments at the beginning of the start block.
9291
{
93-
// FIXME: Consider using just the span covering the function
94-
// argument declaration.
95-
let source_info = SourceInfo::outermost(span);
9692
// Gather all arguments, skip return value.
97-
let places = local_decls
98-
.iter_enumerated()
99-
.skip(1)
100-
.take(arg_count)
101-
.map(|(local, _)| Place::from(local))
102-
.filter(needs_retag);
93+
let places = local_decls.iter_enumerated().skip(1).take(body.arg_count).filter_map(
94+
|(local, decl)| {
95+
let place = Place::from(local);
96+
needs_retag(&place).then_some((place, decl.source_info))
97+
},
98+
);
99+
103100
// Emit their retags.
104101
basic_blocks[START_BLOCK].statements.splice(
105102
0..0,
106-
places.map(|place| Statement {
103+
places.map(|(place, source_info)| Statement {
107104
source_info,
108105
kind: StatementKind::Retag(RetagKind::FnEntry, Box::new(place)),
109106
}),

src/test/mir-opt/dead-store-elimination/provenance_soundness.retags.DeadStoreElimination.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let mut _0: (); // return place in scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:25
77

88
bb0: {
9-
Retag([fn entry] _1); // scope 0 at $DIR/provenance_soundness.rs:+0:1: +0:27
9+
Retag([fn entry] _1); // scope 0 at $DIR/provenance_soundness.rs:+0:11: +0:13
1010
_0 = const (); // scope 0 at $DIR/provenance_soundness.rs:+0:25: +0:27
1111
return; // scope 0 at $DIR/provenance_soundness.rs:+0:27: +0:27
1212
}

src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fn bar() -> bool {
5252
Retag(_7); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
5353
_6 = &(*_7); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
5454
Retag(_6); // scope 1 at $DIR/inline-retag.rs:+2:11: +2:14
55-
Retag(_3); // scope 2 at $DIR/inline-retag.rs:16:1: 18:2
56-
Retag(_6); // scope 2 at $DIR/inline-retag.rs:16:1: 18:2
55+
Retag(_3); // scope 2 at $DIR/inline-retag.rs:16:8: 16:9
56+
Retag(_6); // scope 2 at $DIR/inline-retag.rs:16:17: 16:18
5757
StorageLive(_11); // scope 2 at $DIR/inline-retag.rs:17:5: 17:7
5858
_11 = (*_3); // scope 2 at $DIR/inline-retag.rs:17:5: 17:7
5959
StorageLive(_12); // scope 2 at $DIR/inline-retag.rs:17:11: 17:13

src/test/mir-opt/retag.main-{closure#0}.SimplifyCfg-elaborate-drops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main::{closure#0}(_1: &[closure@main::{closure#0}], _2: &i32) -> &i32 {
1010

1111
bb0: {
1212
Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:31: +0:48
13-
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:31: +0:48
13+
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:32: +0:33
1414
StorageLive(_3); // scope 0 at $DIR/retag.rs:42:13: 42:15
1515
_3 = _2; // scope 0 at $DIR/retag.rs:42:18: 42:19
1616
Retag(_3); // scope 0 at $DIR/retag.rs:42:18: 42:19

src/test/mir-opt/retag.{impl#0}-foo.SimplifyCfg-elaborate-drops.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn <impl at $DIR/retag.rs:12:1: 12:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32
77
let mut _3: &mut i32; // in scope 0 at $DIR/retag.rs:+1:9: +1:10
88

99
bb0: {
10-
Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:5: +2:6
11-
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:5: +2:6
10+
Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:16: +0:21
11+
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:23: +0:24
1212
StorageLive(_3); // scope 0 at $DIR/retag.rs:+1:9: +1:10
1313
_3 = &mut (*_2); // scope 0 at $DIR/retag.rs:+1:9: +1:10
1414
Retag(_3); // scope 0 at $DIR/retag.rs:+1:9: +1:10

src/test/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-elaborate-drops.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ fn <impl at $DIR/retag.rs:12:1: 12:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
66
let mut _0: &i32; // return place in scope 0 at $DIR/retag.rs:+0:42: +0:49
77

88
bb0: {
9-
Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:5: +2:6
10-
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:5: +2:6
9+
Retag([fn entry] _1); // scope 0 at $DIR/retag.rs:+0:20: +0:25
10+
Retag([fn entry] _2); // scope 0 at $DIR/retag.rs:+0:27: +0:28
1111
_0 = _2; // scope 0 at $DIR/retag.rs:+1:9: +1:10
1212
Retag(_0); // scope 0 at $DIR/retag.rs:+1:9: +1:10
1313
return; // scope 0 at $DIR/retag.rs:+2:6: +2:6

0 commit comments

Comments
 (0)