From 4abe9687577128c1980788183a3463932ffdfd6a Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 29 Dec 2025 16:18:36 +0800 Subject: [PATCH 1/4] Add FileCheck annotations to retag mir-opt test Part of #116971. --- tests/mir-opt/retag.rs | 9 ++++++++- ...o.SimplifyCfg-pre-optimizations.after.panic-abort.mir | 4 ++-- ....SimplifyCfg-pre-optimizations.after.panic-unwind.mir | 4 ++-- ...r.SimplifyCfg-pre-optimizations.after.panic-abort.mir | 4 ++-- ....SimplifyCfg-pre-optimizations.after.panic-unwind.mir | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index 001c559913839..ef33347f257e7 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -1,4 +1,3 @@ -// skip-filecheck //@ test-mir-pass: AddRetag // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // ignore-tidy-linelength @@ -12,9 +11,15 @@ 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: Retag([fn entry] _2); + // CHECK: _0 = &mut (*_{{[0-9]+}}); fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 { x } + // CHECK-LABEL: fn {{.*}}::foo_shr( + // CHECK: Retag([fn entry] _2); + // CHECK: Retag(_0); fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 { x } @@ -29,6 +34,8 @@ 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]+}}); 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 diff --git a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir index b656656919e1f..484db137c1cf2 100644 --- a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,6 +1,6 @@ -// MIR for `::foo` after SimplifyCfg-pre-optimizations +// MIR for `::foo` after SimplifyCfg-pre-optimizations -fn ::foo(_1: &Test, _2: &mut i32) -> &mut i32 { +fn ::foo(_1: &Test, _2: &mut i32) -> &mut i32 { debug self => _1; debug x => _2; let mut _0: &mut i32; diff --git a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index b656656919e1f..484db137c1cf2 100644 --- a/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/retag.{impl#0}-foo.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,6 +1,6 @@ -// MIR for `::foo` after SimplifyCfg-pre-optimizations +// MIR for `::foo` after SimplifyCfg-pre-optimizations -fn ::foo(_1: &Test, _2: &mut i32) -> &mut i32 { +fn ::foo(_1: &Test, _2: &mut i32) -> &mut i32 { debug self => _1; debug x => _2; let mut _0: &mut i32; diff --git a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir index b873c5aabbfc3..33f60d9b09db5 100644 --- a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir +++ b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-abort.mir @@ -1,6 +1,6 @@ -// MIR for `::foo_shr` after SimplifyCfg-pre-optimizations +// MIR for `::foo_shr` after SimplifyCfg-pre-optimizations -fn ::foo_shr(_1: &Test, _2: &i32) -> &i32 { +fn ::foo_shr(_1: &Test, _2: &i32) -> &i32 { debug self => _1; debug x => _2; let mut _0: &i32; diff --git a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir index b873c5aabbfc3..33f60d9b09db5 100644 --- a/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir +++ b/tests/mir-opt/retag.{impl#0}-foo_shr.SimplifyCfg-pre-optimizations.after.panic-unwind.mir @@ -1,6 +1,6 @@ -// MIR for `::foo_shr` after SimplifyCfg-pre-optimizations +// MIR for `::foo_shr` after SimplifyCfg-pre-optimizations -fn ::foo_shr(_1: &Test, _2: &i32) -> &i32 { +fn ::foo_shr(_1: &Test, _2: &i32) -> &i32 { debug self => _1; debug x => _2; let mut _0: &i32; From d2a8d46733133100a21d51b56b1bc0094ea5f578 Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 29 Dec 2025 16:50:04 +0800 Subject: [PATCH 2/4] Improve FileCheck coverage for retag mir-opt test - Add CHECK for closure (main::{closure#0}) - Use CHECK-NEXT to verify Retag statements order after bb0 - Verify Retag for both self (_1) and reference parameters (_2) --- tests/mir-opt/retag.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index ef33347f257e7..edeeaa1ab71b7 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -12,13 +12,16 @@ struct Test(i32); impl Test { // Make sure we run the pass on a method, not just on bare functions. // CHECK-LABEL: fn {{.*}}::foo( - // CHECK: Retag([fn entry] _2); - // CHECK: _0 = &mut (*_{{[0-9]+}}); + // 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: Retag([fn entry] _2); + // CHECK: bb0: { + // CHECK-NEXT: Retag([fn entry] _1); + // CHECK-NEXT: Retag([fn entry] _2); // CHECK: Retag(_0); fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 { x @@ -36,6 +39,11 @@ impl Drop for Test { pub fn main() { // CHECK-LABEL: fn main( // CHECK: Retag(_{{[0-9]+}}); + // + // CHECK-LABEL: fn main::{closure#0}( + // CHECK: bb0: { + // CHECK-NEXT: Retag([fn entry] _1); + // CHECK-NEXT: Retag([fn entry] _2); 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 From 2ed1943170f60beb547a6c668ad0b01908dd122f Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 29 Dec 2025 16:55:48 +0800 Subject: [PATCH 3/4] Add CHECK for array_casts function --- tests/mir-opt/retag.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index edeeaa1ab71b7..786b8631be395 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -71,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( fn array_casts() { let mut x: [usize; 2] = [0, 0]; let p = &mut x as *mut usize; From 9732b7694b0ea59844356c89fa957e478b8dc09d Mon Sep 17 00:00:00 2001 From: AprilNEA Date: Mon, 29 Dec 2025 16:59:08 +0800 Subject: [PATCH 4/4] Add CHECK for box_to_raw_mut function with [raw] retag --- tests/mir-opt/retag.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/mir-opt/retag.rs b/tests/mir-opt/retag.rs index 786b8631be395..ce08352938491 100644 --- a/tests/mir-opt/retag.rs +++ b/tests/mir-opt/retag.rs @@ -86,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) -> *mut i32 { std::ptr::addr_of_mut!(**x) }