]> git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/retag.rs
New upstream version 1.39.0+dfsg1
[rustc.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 // _13 = &mut (*_10);
86 // Retag(_13);
87 // _12 = move _13 as *mut i32 (Misc);
88 // Retag([raw] _12);
89 // ...
90 // _16 = move _17(move _18) -> bb5;
91 // }
92 //
93 // bb5: {
94 // Retag(_16);
95 // ...
96 // _20 = const Test::foo_shr(move _21, move _23) -> [return: bb6, unwind: bb7];
97 // }
98 //
99 // ...
100 // }
101 // END rustc.main.EraseRegions.after.mir
102 // START rustc.main-{{closure}}.EraseRegions.after.mir
103 // fn main::{{closure}}#0(_1: &[closure@HirId { owner: DefIndex(22), local_id: 72 }], _2: &i32) -> &i32 {
104 // ...
105 // bb0: {
106 // Retag([fn entry] _1);
107 // Retag([fn entry] _2);
108 // StorageLive(_3);
109 // _3 = _2;
110 // Retag(_3);
111 // _0 = _2;
112 // Retag(_0);
113 // StorageDead(_3);
114 // return;
115 // }
116 // }
117 // END rustc.main-{{closure}}.EraseRegions.after.mir
118 // START rustc.ptr-real_drop_in_place.Test.SimplifyCfg-make_shim.after.mir
119 // fn std::ptr::real_drop_in_place(_1: &mut Test) -> () {
120 // ...
121 // bb0: {
122 // Retag([raw] _1);
123 // _2 = &mut (*_1);
124 // _3 = const <Test as std::ops::Drop>::drop(move _2) -> bb1;
125 // }
126 //
127 // bb1: {
128 // return;
129 // }
130 // }
131 // END rustc.ptr-real_drop_in_place.Test.SimplifyCfg-make_shim.after.mir