Skip to content

Commit 670ce23

Browse files
committed
Add a mir-opt pre-codegen test for dropping a Box<[impl Copy]>
1 parent 733dab5 commit 670ce23

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// MIR for `generic_in_place` after PreCodegen
2+
3+
fn generic_in_place(_1: *mut Box<[T]>) -> () {
4+
debug ptr => _1;
5+
let mut _0: ();
6+
scope 1 (inlined drop_in_place::<Box<[T]>> - shim(Some(Box<[T]>))) {
7+
scope 2 (inlined <Box<[T]> as Drop>::drop) {
8+
let _2: std::ptr::NonNull<[T]>;
9+
let mut _3: *mut [T];
10+
let mut _4: *const [T];
11+
let _12: ();
12+
scope 3 {
13+
scope 4 {
14+
scope 12 (inlined Layout::size) {
15+
}
16+
scope 13 (inlined Unique::<[T]>::cast::<u8>) {
17+
scope 14 (inlined NonNull::<[T]>::cast::<u8>) {
18+
scope 15 (inlined NonNull::<[T]>::as_ptr) {
19+
}
20+
}
21+
}
22+
scope 16 (inlined <NonNull<u8> as From<Unique<u8>>>::from) {
23+
scope 17 (inlined Unique::<u8>::as_non_null_ptr) {
24+
}
25+
}
26+
scope 18 (inlined <std::alloc::Global as Allocator>::deallocate) {
27+
let mut _8: *mut u8;
28+
scope 19 (inlined Layout::size) {
29+
}
30+
scope 20 (inlined NonNull::<u8>::as_ptr) {
31+
}
32+
scope 21 (inlined std::alloc::dealloc) {
33+
let mut _11: usize;
34+
scope 22 (inlined Layout::size) {
35+
}
36+
scope 23 (inlined Layout::align) {
37+
scope 24 (inlined std::ptr::Alignment::as_usize) {
38+
let _9: std::ptr::alignment::AlignmentEnum;
39+
let mut _10: u32;
40+
}
41+
}
42+
}
43+
}
44+
}
45+
scope 5 (inlined Unique::<[T]>::as_ptr) {
46+
scope 6 (inlined NonNull::<[T]>::as_ptr) {
47+
}
48+
}
49+
scope 7 (inlined Layout::for_value_raw::<[T]>) {
50+
let mut _5: usize;
51+
let mut _6: usize;
52+
scope 8 {
53+
scope 11 (inlined #[track_caller] Layout::from_size_align_unchecked) {
54+
let mut _7: std::ptr::Alignment;
55+
}
56+
}
57+
scope 9 (inlined size_of_val_raw::<[T]>) {
58+
}
59+
scope 10 (inlined align_of_val_raw::<[T]>) {
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
bb0: {
67+
StorageLive(_2);
68+
_2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>);
69+
StorageLive(_4);
70+
_3 = copy _2 as *mut [T] (Transmute);
71+
_4 = copy _2 as *const [T] (Transmute);
72+
StorageLive(_6);
73+
_5 = std::intrinsics::size_of_val::<[T]>(copy _4) -> [return: bb1, unwind unreachable];
74+
}
75+
76+
bb1: {
77+
_6 = std::intrinsics::align_of_val::<[T]>(move _4) -> [return: bb2, unwind unreachable];
78+
}
79+
80+
bb2: {
81+
_7 = copy _6 as std::ptr::Alignment (Transmute);
82+
StorageDead(_6);
83+
StorageDead(_4);
84+
switchInt(copy _5) -> [0: bb5, otherwise: bb3];
85+
}
86+
87+
bb3: {
88+
StorageLive(_8);
89+
_8 = copy _3 as *mut u8 (PtrToPtr);
90+
StorageLive(_11);
91+
StorageLive(_10);
92+
StorageLive(_9);
93+
_9 = copy (_7.0: std::ptr::alignment::AlignmentEnum);
94+
_10 = discriminant(_9);
95+
_11 = move _10 as usize (IntToInt);
96+
StorageDead(_9);
97+
StorageDead(_10);
98+
_12 = alloc::alloc::__rust_dealloc(move _8, move _5, move _11) -> [return: bb4, unwind unreachable];
99+
}
100+
101+
bb4: {
102+
StorageDead(_11);
103+
StorageDead(_8);
104+
goto -> bb5;
105+
}
106+
107+
bb5: {
108+
StorageDead(_2);
109+
return;
110+
}
111+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// MIR for `generic_in_place` after PreCodegen
2+
3+
fn generic_in_place(_1: *mut Box<[T]>) -> () {
4+
debug ptr => _1;
5+
let mut _0: ();
6+
scope 1 (inlined drop_in_place::<Box<[T]>> - shim(Some(Box<[T]>))) {
7+
scope 2 (inlined <Box<[T]> as Drop>::drop) {
8+
let _2: std::ptr::NonNull<[T]>;
9+
let mut _3: *mut [T];
10+
let mut _4: *const [T];
11+
let _12: ();
12+
scope 3 {
13+
scope 4 {
14+
scope 12 (inlined Layout::size) {
15+
}
16+
scope 13 (inlined Unique::<[T]>::cast::<u8>) {
17+
scope 14 (inlined NonNull::<[T]>::cast::<u8>) {
18+
scope 15 (inlined NonNull::<[T]>::as_ptr) {
19+
}
20+
}
21+
}
22+
scope 16 (inlined <NonNull<u8> as From<Unique<u8>>>::from) {
23+
scope 17 (inlined Unique::<u8>::as_non_null_ptr) {
24+
}
25+
}
26+
scope 18 (inlined <std::alloc::Global as Allocator>::deallocate) {
27+
let mut _8: *mut u8;
28+
scope 19 (inlined Layout::size) {
29+
}
30+
scope 20 (inlined NonNull::<u8>::as_ptr) {
31+
}
32+
scope 21 (inlined std::alloc::dealloc) {
33+
let mut _11: usize;
34+
scope 22 (inlined Layout::size) {
35+
}
36+
scope 23 (inlined Layout::align) {
37+
scope 24 (inlined std::ptr::Alignment::as_usize) {
38+
let _9: std::ptr::alignment::AlignmentEnum;
39+
let mut _10: u32;
40+
}
41+
}
42+
}
43+
}
44+
}
45+
scope 5 (inlined Unique::<[T]>::as_ptr) {
46+
scope 6 (inlined NonNull::<[T]>::as_ptr) {
47+
}
48+
}
49+
scope 7 (inlined Layout::for_value_raw::<[T]>) {
50+
let mut _5: usize;
51+
let mut _6: usize;
52+
scope 8 {
53+
scope 11 (inlined #[track_caller] Layout::from_size_align_unchecked) {
54+
let mut _7: std::ptr::Alignment;
55+
}
56+
}
57+
scope 9 (inlined size_of_val_raw::<[T]>) {
58+
}
59+
scope 10 (inlined align_of_val_raw::<[T]>) {
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
bb0: {
67+
StorageLive(_2);
68+
_2 = copy (((*_1).0: std::ptr::Unique<[T]>).0: std::ptr::NonNull<[T]>);
69+
StorageLive(_4);
70+
_3 = copy _2 as *mut [T] (Transmute);
71+
_4 = copy _2 as *const [T] (Transmute);
72+
StorageLive(_6);
73+
_5 = std::intrinsics::size_of_val::<[T]>(copy _4) -> [return: bb1, unwind unreachable];
74+
}
75+
76+
bb1: {
77+
_6 = std::intrinsics::align_of_val::<[T]>(move _4) -> [return: bb2, unwind unreachable];
78+
}
79+
80+
bb2: {
81+
_7 = copy _6 as std::ptr::Alignment (Transmute);
82+
StorageDead(_6);
83+
StorageDead(_4);
84+
switchInt(copy _5) -> [0: bb5, otherwise: bb3];
85+
}
86+
87+
bb3: {
88+
StorageLive(_8);
89+
_8 = copy _3 as *mut u8 (PtrToPtr);
90+
StorageLive(_11);
91+
StorageLive(_10);
92+
StorageLive(_9);
93+
_9 = copy (_7.0: std::ptr::alignment::AlignmentEnum);
94+
_10 = discriminant(_9);
95+
_11 = move _10 as usize (IntToInt);
96+
StorageDead(_9);
97+
StorageDead(_10);
98+
_12 = alloc::alloc::__rust_dealloc(move _8, move _5, move _11) -> [return: bb4, unwind unreachable];
99+
}
100+
101+
bb4: {
102+
StorageDead(_11);
103+
StorageDead(_8);
104+
goto -> bb5;
105+
}
106+
107+
bb5: {
108+
StorageDead(_2);
109+
return;
110+
}
111+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ compile-flags: -O -Zmir-opt-level=2
2+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3+
4+
#![crate_type = "lib"]
5+
#![feature(step_trait)]
6+
7+
// EMIT_MIR drop_boxed_slice.generic_in_place.PreCodegen.after.mir
8+
pub unsafe fn generic_in_place<T: Copy>(ptr: *mut Box<[T]>) {
9+
// CHECK-LABEL: fn generic_in_place(_1: *mut Box<[T]>)
10+
// CHECK: (inlined <Box<[T]> as Drop>::drop)
11+
// CHECK: _7 = copy _6 as std::ptr::Alignment (Transmute);
12+
// CHECK: _9 = copy (_7.0: std::ptr::alignment::AlignmentEnum);
13+
// CHECK: _10 = discriminant(_9);
14+
// CHECK: _11 = move _10 as usize (IntToInt);
15+
// CHECK: = alloc::alloc::__rust_dealloc(move _8, move _5, move _11) ->
16+
std::ptr::drop_in_place(ptr)
17+
}

0 commit comments

Comments
 (0)