Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot authored and RalfJung committed Nov 25, 2024
1 parent 7db7489 commit 2cc0ee6
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/mir-opt/pre-codegen/deref_nested_borrows.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 2cc0ee6

Please sign in to comment.