Skip to content

Commit

Permalink
Rollup merge of rust-lang#101111 - saethlin:better-fnentry-spans, r=R…
Browse files Browse the repository at this point in the history
…alfJung

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``
  • Loading branch information
matthiaskrgr authored Aug 28, 2022
2 parents 4bca52c + cd1a42a commit 619d967
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
19 changes: 8 additions & 11 deletions compiler/rustc_mir_transform/src/add_retag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>| {
Expand All @@ -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)),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fn <impl at $DIR/retag.rs:12:1: 12:10>::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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ fn <impl at $DIR/retag.rs:12:1: 12:10>::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
Expand Down

0 comments on commit 619d967

Please sign in to comment.