]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/inline_asm.rs
Rollup merge of #49858 - dmizuk:unique-doc-hidden, r=steveklabnik
[rust.git] / src / test / incremental / hashes / inline_asm.rs
1 // Copyright 2016 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
12 // This test case tests the incremental compilation hash (ICH) implementation
13 // for inline asm.
14
15 // The general pattern followed here is: Change one thing between rev1 and rev2
16 // and make sure that the hash has changed, then change nothing between rev2 and
17 // rev3 and make sure that the hash has not changed.
18
19 // compile-pass
20 // revisions: cfail1 cfail2 cfail3
21 // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
22
23 #![allow(warnings)]
24 #![feature(rustc_attrs)]
25 #![feature(asm)]
26 #![crate_type="rlib"]
27
28
29
30 // Change template -------------------------------------------------------------
31 #[cfg(cfail1)]
32 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
33 pub fn change_template(a: i32) -> i32 {
34     let c: i32;
35     unsafe {
36         asm!("add 1, $0"
37              : "=r"(c)
38              : "0"(a)
39              :
40              :
41              );
42     }
43     c
44 }
45
46 #[cfg(not(cfail1))]
47 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
48 #[rustc_clean(cfg="cfail3")]
49 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
50 pub fn change_template(a: i32) -> i32 {
51     let c: i32;
52     unsafe {
53         asm!("add 2, $0"
54              : "=r"(c)
55              : "0"(a)
56              :
57              :
58              );
59     }
60     c
61 }
62
63
64
65 // Change output -------------------------------------------------------------
66 #[cfg(cfail1)]
67 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
68 pub fn change_output(a: i32) -> i32 {
69     let mut _out1: i32 = 0;
70     let mut _out2: i32 = 0;
71     unsafe {
72         asm!("add 1, $0"
73              : "=r"(_out1)
74              : "0"(a)
75              :
76              :
77              );
78     }
79     _out1
80 }
81
82 #[cfg(not(cfail1))]
83 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
84 #[rustc_clean(cfg="cfail3")]
85 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
86 pub fn change_output(a: i32) -> i32 {
87     let mut _out1: i32 = 0;
88     let mut _out2: i32 = 0;
89     unsafe {
90         asm!("add 1, $0"
91              : "=r"(_out2)
92              : "0"(a)
93              :
94              :
95              );
96     }
97     _out1
98 }
99
100
101
102 // Change input -------------------------------------------------------------
103 #[cfg(cfail1)]
104 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
105 pub fn change_input(_a: i32, _b: i32) -> i32 {
106     let _out;
107     unsafe {
108         asm!("add 1, $0"
109              : "=r"(_out)
110              : "0"(_a)
111              :
112              :
113              );
114     }
115     _out
116 }
117
118 #[cfg(not(cfail1))]
119 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
120 #[rustc_clean(cfg="cfail3")]
121 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
122 pub fn change_input(_a: i32, _b: i32) -> i32 {
123     let _out;
124     unsafe {
125         asm!("add 1, $0"
126              : "=r"(_out)
127              : "0"(_b)
128              :
129              :
130              );
131     }
132     _out
133 }
134
135
136
137 // Change input constraint -----------------------------------------------------
138 #[cfg(cfail1)]
139 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
140 pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
141     let _out;
142     unsafe {
143         asm!("add 1, $0"
144              : "=r"(_out)
145              : "0"(_a), "r"(_b)
146              :
147              :
148              );
149     }
150     _out
151 }
152
153 #[cfg(not(cfail1))]
154 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
155 #[rustc_clean(cfg="cfail3")]
156 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
157 pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
158     let _out;
159     unsafe {
160         asm!("add 1, $0"
161              : "=r"(_out)
162              : "r"(_a), "0"(_b)
163              :
164              :
165              );
166     }
167     _out
168 }
169
170
171
172 // Change clobber --------------------------------------------------------------
173 #[cfg(cfail1)]
174 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
175 pub fn change_clobber(_a: i32) -> i32 {
176     let _out;
177     unsafe {
178         asm!("add 1, $0"
179              : "=r"(_out)
180              : "0"(_a)
181              :
182              :
183              );
184     }
185     _out
186 }
187
188 #[cfg(not(cfail1))]
189 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
190 #[rustc_clean(cfg="cfail3")]
191 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
192 pub fn change_clobber(_a: i32) -> i32 {
193     let _out;
194     unsafe {
195         asm!("add 1, $0"
196              : "=r"(_out)
197              : "0"(_a)
198              : "eax"
199              :
200              );
201     }
202     _out
203 }
204
205
206
207 // Change options --------------------------------------------------------------
208 #[cfg(cfail1)]
209 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
210 pub fn change_options(_a: i32) -> i32 {
211     let _out;
212     unsafe {
213         asm!("add 1, $0"
214              : "=r"(_out)
215              : "0"(_a)
216              :
217              :
218              );
219     }
220     _out
221 }
222
223 #[cfg(not(cfail1))]
224 #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
225 #[rustc_clean(cfg="cfail3")]
226 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
227 pub fn change_options(_a: i32) -> i32 {
228     let _out;
229     unsafe {
230         asm!("add 1, $0"
231              : "=r"(_out)
232              : "0"(_a)
233              :
234              : "volatile"
235              );
236     }
237     _out
238 }