Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/mir-opt/retag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
//@ test-mir-pass: AddRetag
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// ignore-tidy-linelength
Expand All @@ -12,9 +11,18 @@ struct Test(i32);
// EMIT_MIR retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.mir
impl Test {
// Make sure we run the pass on a method, not just on bare functions.
// CHECK-LABEL: fn {{.*}}::foo(
// CHECK: bb0: {
// CHECK-NEXT: Retag([fn entry] _1);
// CHECK-NEXT: Retag([fn entry] _2);
fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 {
x
}
// CHECK-LABEL: fn {{.*}}::foo_shr(
// CHECK: bb0: {
// CHECK-NEXT: Retag([fn entry] _1);
// CHECK-NEXT: Retag([fn entry] _2);
// CHECK: Retag(_0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are checking that we retag just after assigning to _0.

Suggested change
// CHECK: Retag(_0);
// CHECK: _0 = {{.*}};
// CHECK-NEXT: Retag(_0);

fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 {
x
}
Expand All @@ -29,6 +37,13 @@ impl Drop for Test {
// EMIT_MIR retag.main.SimplifyCfg-pre-optimizations.after.mir
// EMIT_MIR retag.main-{closure#0}.SimplifyCfg-pre-optimizations.after.mir
pub fn main() {
// CHECK-LABEL: fn main(
// CHECK: Retag(_{{[0-9]+}});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate a bit? There should be 7 retags in this function.

//
// CHECK-LABEL: fn main::{closure#0}(
// CHECK: bb0: {
// CHECK-NEXT: Retag([fn entry] _1);
// CHECK-NEXT: Retag([fn entry] _2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the Retag(_3)?

let mut x = 0;
{
let v = Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor
Expand Down Expand Up @@ -56,6 +71,8 @@ pub fn main() {

/// Casting directly to an array should also go through `&raw` and thus add appropriate retags.
// EMIT_MIR retag.array_casts.SimplifyCfg-pre-optimizations.after.mir
// CHECK-LABEL: fn array_casts(
// CHECK: Retag(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate? There are 4 retags in this function.

fn array_casts() {
let mut x: [usize; 2] = [0, 0];
let p = &mut x as *mut usize;
Expand All @@ -69,6 +86,10 @@ fn array_casts() {
}

// EMIT_MIR retag.box_to_raw_mut.SimplifyCfg-pre-optimizations.after.mir
// CHECK-LABEL: fn box_to_raw_mut(
// CHECK: bb0: {
// CHECK-NEXT: Retag([fn entry] _1);
// CHECK: Retag([raw] _0);
fn box_to_raw_mut(x: &mut Box<i32>) -> *mut i32 {
std::ptr::addr_of_mut!(**x)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations
// MIR for `<impl at $DIR/retag.rs:12:1: 12:10>::foo` after SimplifyCfg-pre-optimizations

fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
fn <impl at $DIR/retag.rs:12:1: 12:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
debug self => _1;
debug x => _2;
let mut _0: &mut i32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo` after SimplifyCfg-pre-optimizations
// MIR for `<impl at $DIR/retag.rs:12:1: 12:10>::foo` after SimplifyCfg-pre-optimizations

fn <impl at $DIR/retag.rs:13:1: 13:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
fn <impl at $DIR/retag.rs:12:1: 12:10>::foo(_1: &Test, _2: &mut i32) -> &mut i32 {
debug self => _1;
debug x => _2;
let mut _0: &mut i32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations
// MIR for `<impl at $DIR/retag.rs:12:1: 12:10>::foo_shr` after SimplifyCfg-pre-optimizations

fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
fn <impl at $DIR/retag.rs:12:1: 12:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
debug self => _1;
debug x => _2;
let mut _0: &i32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `<impl at $DIR/retag.rs:13:1: 13:10>::foo_shr` after SimplifyCfg-pre-optimizations
// MIR for `<impl at $DIR/retag.rs:12:1: 12:10>::foo_shr` after SimplifyCfg-pre-optimizations

fn <impl at $DIR/retag.rs:13:1: 13:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
fn <impl at $DIR/retag.rs:12:1: 12:10>::foo_shr(_1: &Test, _2: &i32) -> &i32 {
debug self => _1;
debug x => _2;
let mut _0: &i32;
Expand Down
Loading