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