]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/retag.rs
Rollup merge of #68767 - kubo39:patch-macos, r=shepmaster
[rust.git] / src / test / mir-opt / retag.rs
1 // ignore-wasm32-bare compiled with panic=abort by default
2 // ignore-tidy-linelength
3 // compile-flags: -Z mir-emit-retag -Z mir-opt-level=0 -Z span_free_formats
4
5 #![allow(unused)]
6
7 struct Test(i32);
8
9 impl Test {
10     // Make sure we run the pass on a method, not just on bare functions.
11     fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 { x }
12     fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 { x }
13 }
14
15 impl Drop for Test {
16     fn drop(&mut self) {}
17 }
18
19 fn main() {
20     let mut x = 0;
21     {
22         let v = Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor
23         let w = { v }; // assignment
24         let w = w; // reborrow
25         // escape-to-raw (mut)
26         let _w = w as *mut _;
27     }
28
29     // Also test closures
30     let c: fn(&i32) -> &i32 = |x: &i32| -> &i32 { let _y = x; x };
31     let _w = c(&x);
32
33     // need to call `foo_shr` or it doesn't even get generated
34     Test(0).foo_shr(&0);
35
36     // escape-to-raw (shr)
37     let _w = _w as *const _;
38 }
39
40 // END RUST SOURCE
41 // START rustc.{{impl}}-foo.EraseRegions.after.mir
42 //     bb0: {
43 //         Retag([fn entry] _1);
44 //         Retag([fn entry] _2);
45 //         ...
46 //         _0 = &mut (*_3);
47 //         Retag(_0);
48 //         ...
49 //         return;
50 //     }
51 // END rustc.{{impl}}-foo.EraseRegions.after.mir
52 // START rustc.{{impl}}-foo_shr.EraseRegions.after.mir
53 //     bb0: {
54 //         Retag([fn entry] _1);
55 //         Retag([fn entry] _2);
56 //         ...
57 //         _0 = _2;
58 //         Retag(_0);
59 //         ...
60 //         return;
61 //     }
62 // END rustc.{{impl}}-foo_shr.EraseRegions.after.mir
63 // START rustc.main.EraseRegions.after.mir
64 // fn main() -> () {
65 //     ...
66 //     bb0: {
67 //         ...
68 //         _3 = const Test::foo(move _4, move _6) -> [return: bb2, unwind: bb3];
69 //     }
70 //
71 //     ...
72 //
73 //     bb2: {
74 //         Retag(_3);
75 //         ...
76 //         _9 = move _3;
77 //         Retag(_9);
78 //         _8 = &mut (*_9);
79 //         Retag(_8);
80 //         StorageDead(_9);
81 //         StorageLive(_10);
82 //         _10 = move _8;
83 //         Retag(_10);
84 //         ...
85 //         _12 = &raw mut (*_10);
86 //         Retag([raw] _12);
87 //         ...
88 //         _15 = move _16(move _17) -> bb5;
89 //     }
90 //
91 //     bb5: {
92 //         Retag(_15);
93 //         ...
94 //         _19 = const Test::foo_shr(move _20, move _22) -> [return: bb6, unwind: bb7];
95 //     }
96 //
97 //     ...
98 // }
99 // END rustc.main.EraseRegions.after.mir
100 // START rustc.main-{{closure}}.EraseRegions.after.mir
101 // fn main::{{closure}}#0(_1: &[closure@main::{{closure}}#0], _2: &i32) -> &i32 {
102 //     ...
103 //     bb0: {
104 //         Retag([fn entry] _1);
105 //         Retag([fn entry] _2);
106 //         StorageLive(_3);
107 //         _3 = _2;
108 //         Retag(_3);
109 //         _0 = _2;
110 //         Retag(_0);
111 //         StorageDead(_3);
112 //         return;
113 //     }
114 // }
115 // END rustc.main-{{closure}}.EraseRegions.after.mir
116 // START rustc.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
117 // fn  std::intrinsics::drop_in_place(_1: *mut Test) -> () {
118 //     ...
119 //     bb0: {
120 //         Retag([raw] _1);
121 //         _2 = &mut (*_1);
122 //         _3 = const <Test as std::ops::Drop>::drop(move _2) -> bb1;
123 //     }
124 //
125 //     bb1: {
126 //         return;
127 //     }
128 // }
129 // END rustc.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir