Skip to content

Commit d8cffda

Browse files
committed
FileCheck casts.
1 parent 68c409f commit d8cffda

File tree

6 files changed

+53
-50
lines changed

6 files changed

+53
-50
lines changed

tests/mir-opt/casts.redundant.PreCodegen.after.mir

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/mir-opt/casts.roundtrip.PreCodegen.after.mir

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/mir-opt/casts.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/mir-opt/casts.redundant.InstSimplify.diff renamed to tests/mir-opt/instsimplify/casts.redundant.InstSimplify.diff

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
let mut _2: *const &u8;
88
let mut _3: *const &u8;
99
scope 1 (inlined generic_cast::<&u8, &u8>) {
10-
debug x => _1;
10+
debug x => _3;
11+
let mut _4: *const &u8;
1112
}
1213

1314
bb0: {
1415
StorageLive(_2);
1516
StorageLive(_3);
1617
_3 = _1;
17-
- _2 = _3 as *const &u8 (PtrToPtr);
18-
+ _2 = _3;
18+
StorageLive(_4);
19+
_4 = _3;
20+
- _2 = move _4 as *const &u8 (PtrToPtr);
21+
+ _2 = move _4;
22+
StorageDead(_4);
1923
StorageDead(_3);
2024
_0 = _2;
2125
StorageDead(_2);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- // MIR for `roundtrip` before InstSimplify
2+
+ // MIR for `roundtrip` after InstSimplify
3+
4+
fn roundtrip(_1: *const u8) -> *const u8 {
5+
debug x => _1;
6+
let mut _0: *const u8;
7+
let mut _2: *mut u8;
8+
let mut _3: *const u8;
9+
10+
bb0: {
11+
StorageLive(_2);
12+
StorageLive(_3);
13+
_3 = _1;
14+
_2 = move _3 as *mut u8 (PtrToPtr);
15+
_0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
16+
StorageDead(_3);
17+
StorageDead(_2);
18+
return;
19+
}
20+
}
21+

tests/mir-opt/instsimplify/casts.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// unit-test: InstSimplify
2+
// compile-flags: -Zinline-mir
3+
#![crate_type = "lib"]
4+
5+
#[inline(always)]
6+
fn generic_cast<T, U>(x: *const T) -> *const U {
7+
x as *const U
8+
}
9+
10+
// EMIT_MIR casts.redundant.InstSimplify.diff
11+
pub fn redundant<'a, 'b: 'a>(x: *const &'a u8) -> *const &'a u8 {
12+
// CHECK-LABEL: fn redundant(
13+
// CHECK: inlined generic_cast
14+
// CHECK-NOT: as
15+
generic_cast::<&'a u8, &'b u8>(x) as *const &'a u8
16+
}
17+
18+
// EMIT_MIR casts.roundtrip.InstSimplify.diff
19+
pub fn roundtrip(x: *const u8) -> *const u8 {
20+
// CHECK-LABEL: fn roundtrip(
21+
// CHECK: _3 = _1;
22+
// CHECK: _2 = move _3 as *mut u8 (PtrToPtr);
23+
// CHECK: _0 = move _2 as *const u8 (PointerCoercion(MutToConstPointer));
24+
x as *mut u8 as *const u8
25+
}

0 commit comments

Comments
 (0)