]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/retag.rs
test: Ignore ui/target-feature-gate on sparc and sparc64
[rust.git] / src / test / mir-opt / retag.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12 // compile-flags: -Z mir-emit-retag -Z mir-opt-level=0 -Z span_free_formats
13
14 #![allow(unused)]
15
16 struct Test(i32);
17
18 impl Test {
19     // Make sure we run the pass on a method, not just on bare functions.
20     fn foo<'x>(&self, x: &'x mut i32) -> &'x mut i32 { x }
21     fn foo_shr<'x>(&self, x: &'x i32) -> &'x i32 { x }
22 }
23
24 fn main() {
25     let mut x = 0;
26     {
27         let v = Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor
28         let w = { v }; // assignment
29         let w = w; // reborrow
30         // escape-to-raw (mut)
31         let _w = w as *mut _;
32     }
33
34     // Also test closures
35     let c: fn(&i32) -> &i32 = |x: &i32| -> &i32 { let _y = x; x };
36     let _w = c(&x);
37
38     // need to call `foo_shr` or it doesn't even get generated
39     Test(0).foo_shr(&0);
40
41     // escape-to-raw (shr)
42     let _w = _w as *const _;
43 }
44
45 // END RUST SOURCE
46 // START rustc.{{impl}}-foo.EraseRegions.after.mir
47 //     bb0: {
48 //         Retag([fn entry] _1);
49 //         Retag([fn entry] _2);
50 //         ...
51 //         _0 = &mut (*_3);
52 //         Retag(_0);
53 //         ...
54 //         return;
55 //     }
56 // END rustc.{{impl}}-foo.EraseRegions.after.mir
57 // START rustc.{{impl}}-foo_shr.EraseRegions.after.mir
58 //     bb0: {
59 //         Retag([fn entry] _1);
60 //         Retag([fn entry] _2);
61 //         ...
62 //         _0 = _2;
63 //         Retag(_0);
64 //         ...
65 //         return;
66 //     }
67 // END rustc.{{impl}}-foo_shr.EraseRegions.after.mir
68 // START rustc.main.EraseRegions.after.mir
69 // fn main() -> () {
70 //     ...
71 //     bb0: {
72 //         ...
73 //         _3 = const Test::foo(move _4, move _6) -> bb1;
74 //     }
75 //
76 //     bb1: {
77 //         Retag(_3);
78 //         ...
79 //         _9 = move _3;
80 //         Retag(_9);
81 //         _8 = &mut (*_9);
82 //         Retag(_8);
83 //         StorageDead(_9);
84 //         StorageLive(_10);
85 //         _10 = move _8;
86 //         Retag(_10);
87 //         ...
88 //         _14 = &mut (*_10);
89 //         Retag(_14);
90 //         EscapeToRaw(move _14);
91 //         _13 = move _14 as *mut i32 (Misc);
92 //         ...
93 //         _17 = move _18(move _19) -> bb2;
94 //     }
95 //
96 //     bb2: {
97 //         Retag(_17);
98 //         ...
99 //         _21 = const Test::foo_shr(move _22, move _24) -> bb3;
100 //     }
101 //
102 //     bb3: {
103 //         ...
104 //         return;
105 //     }
106 //
107 //     ...
108 // }
109 // END rustc.main.EraseRegions.after.mir
110 // START rustc.main-{{closure}}.EraseRegions.after.mir
111 // fn main::{{closure}}(_1: &[closure@NodeId(124)], _2: &i32) -> &i32 {
112 //     ...
113 //     bb0: {
114 //         Retag([fn entry] _1);
115 //         Retag([fn entry] _2);
116 //         StorageLive(_3);
117 //         _3 = _2;
118 //         Retag(_3);
119 //         _0 = _2;
120 //         Retag(_0);
121 //         StorageDead(_3);
122 //         return;
123 //     }
124 // }
125 // END rustc.main-{{closure}}.EraseRegions.after.mir