1
Fork 0

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````
This commit is contained in:
Matthias Krüger 2022-08-29 06:34:48 +02:00 committed by GitHub
commit 3e5be57de8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 19 deletions

View file

@ -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)),
}),