From 2cc0ee65d9c00eb717fe3d75a83c673e5c03dac2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 1 Nov 2024 14:38:19 +0000 Subject: [PATCH] Add test. --- .../pre-codegen/deref_nested_borrows.rs | 22 ++++++++++ ...ef_nested_borrows.src.GVN.panic-abort.diff | 43 +++++++++++++++++++ ...f_nested_borrows.src.GVN.panic-unwind.diff | 43 +++++++++++++++++++ ...rrows.src.PreCodegen.after.panic-abort.mir | 23 ++++++++++ ...rows.src.PreCodegen.after.panic-unwind.mir | 23 ++++++++++ 5 files changed, 154 insertions(+) create mode 100644 tests/mir-opt/pre-codegen/deref_nested_borrows.rs create mode 100644 tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff create mode 100644 tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir create mode 100644 tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.rs b/tests/mir-opt/pre-codegen/deref_nested_borrows.rs new file mode 100644 index 00000000000..ba23d5d2b25 --- /dev/null +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.rs @@ -0,0 +1,22 @@ +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY + +fn src(x: &&u8) -> bool { + // CHECK-LABEL: fn src( + // CHECK: _0 = const true; + let y = **x; + unsafe { unknown() }; + **x == y +} + +#[inline(never)] +unsafe fn unknown() { + // CHECK-LABEL: fn unknown( +} + +fn main() { + // CHECK-LABEL: fn main( + src(&&0); +} + +// EMIT_MIR deref_nested_borrows.src.GVN.diff +// EMIT_MIR deref_nested_borrows.src.PreCodegen.after.mir diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff new file mode 100644 index 00000000000..838f5e6839f --- /dev/null +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff @@ -0,0 +1,43 @@ +- // MIR for `src` before GVN ++ // MIR for `src` after GVN + + fn src(_1: &&u8) -> bool { + debug x => _1; + let mut _0: bool; + let _2: u8; + let _3: (); + let mut _4: u8; + let mut _5: u8; + let mut _6: &u8; + let mut _7: &u8; + scope 1 { + debug y => _2; + } + + bb0: { +- StorageLive(_2); +- _6 = deref_copy (*_1); ++ nop; ++ _6 = copy (*_1); + _2 = copy (*_6); + _3 = unknown() -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageLive(_4); +- _7 = deref_copy (*_1); +- _4 = copy (*_7); ++ _7 = copy _6; ++ _4 = copy _2; + StorageLive(_5); + _5 = copy _2; +- _0 = Eq(move _4, move _5); ++ _0 = const true; + StorageDead(_5); + StorageDead(_4); +- StorageDead(_2); ++ nop; + return; + } + } + diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff new file mode 100644 index 00000000000..25445a9a47e --- /dev/null +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff @@ -0,0 +1,43 @@ +- // MIR for `src` before GVN ++ // MIR for `src` after GVN + + fn src(_1: &&u8) -> bool { + debug x => _1; + let mut _0: bool; + let _2: u8; + let _3: (); + let mut _4: u8; + let mut _5: u8; + let mut _6: &u8; + let mut _7: &u8; + scope 1 { + debug y => _2; + } + + bb0: { +- StorageLive(_2); +- _6 = deref_copy (*_1); ++ nop; ++ _6 = copy (*_1); + _2 = copy (*_6); + _3 = unknown() -> [return: bb1, unwind continue]; + } + + bb1: { + StorageLive(_4); +- _7 = deref_copy (*_1); +- _4 = copy (*_7); ++ _7 = copy _6; ++ _4 = copy _2; + StorageLive(_5); + _5 = copy _2; +- _0 = Eq(move _4, move _5); ++ _0 = const true; + StorageDead(_5); + StorageDead(_4); +- StorageDead(_2); ++ nop; + return; + } + } + diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir new file mode 100644 index 00000000000..13f2eb9874b --- /dev/null +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir @@ -0,0 +1,23 @@ +// MIR for `src` after PreCodegen + +fn src(_1: &&u8) -> bool { + debug x => _1; + let mut _0: bool; + let mut _2: &u8; + let _3: u8; + let _4: (); + scope 1 { + debug y => _3; + } + + bb0: { + _2 = copy (*_1); + _3 = copy (*_2); + _4 = unknown() -> [return: bb1, unwind unreachable]; + } + + bb1: { + _0 = const true; + return; + } +} diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir new file mode 100644 index 00000000000..7fab6e5511f --- /dev/null +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir @@ -0,0 +1,23 @@ +// MIR for `src` after PreCodegen + +fn src(_1: &&u8) -> bool { + debug x => _1; + let mut _0: bool; + let mut _2: &u8; + let _3: u8; + let _4: (); + scope 1 { + debug y => _3; + } + + bb0: { + _2 = copy (*_1); + _3 = copy (*_2); + _4 = unknown() -> [return: bb1, unwind continue]; + } + + bb1: { + _0 = const true; + return; + } +}