]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/hashes/unary_and_binary_exprs.rs
Merge commit 'd3a2366ee877075c59b38bd8ced55f224fc7ef51' into sync_cg_clif-2022-07-26
[rust.git] / src / test / incremental / hashes / unary_and_binary_exprs.rs
1 // This test case tests the incremental compilation hash (ICH) implementation
2 // for unary and binary expressions.
3
4 // The general pattern followed here is: Change one thing between rev1 and rev2
5 // and make sure that the hash has changed, then change nothing between rev2 and
6 // rev3 and make sure that the hash has not changed.
7
8 // build-pass (FIXME(62277): could be check-pass?)
9 // revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
10 // compile-flags: -Z query-dep-graph -O
11 // [cfail1]compile-flags: -Zincremental-ignore-spans
12 // [cfail2]compile-flags: -Zincremental-ignore-spans
13 // [cfail3]compile-flags: -Zincremental-ignore-spans
14 // [cfail4]compile-flags: -Zincremental-relative-spans
15 // [cfail5]compile-flags: -Zincremental-relative-spans
16 // [cfail6]compile-flags: -Zincremental-relative-spans
17
18 #![allow(warnings)]
19 #![feature(rustc_attrs)]
20 #![crate_type="rlib"]
21
22
23 // Change constant operand of negation -----------------------------------------
24 #[cfg(any(cfail1,cfail4))]
25 pub fn const_negation() -> i32 {
26     -10
27 }
28
29 #[cfg(not(any(cfail1,cfail4)))]
30 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
31 #[rustc_clean(cfg="cfail3")]
32 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
33 #[rustc_clean(cfg="cfail6")]
34 pub fn const_negation() -> i32 {
35      -1
36 }
37
38
39
40 // Change constant operand of bitwise not --------------------------------------
41 #[cfg(any(cfail1,cfail4))]
42 pub fn const_bitwise_not() -> i32 {
43     !100
44 }
45
46 #[cfg(not(any(cfail1,cfail4)))]
47 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
48 #[rustc_clean(cfg="cfail3")]
49 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
50 #[rustc_clean(cfg="cfail6")]
51 pub fn const_bitwise_not() -> i32 {
52      !99
53 }
54
55
56
57 // Change variable operand of negation -----------------------------------------
58 #[cfg(any(cfail1,cfail4))]
59 pub fn var_negation(x: i32, y: i32) -> i32 {
60     -x
61 }
62
63 #[cfg(not(any(cfail1,cfail4)))]
64 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
65 #[rustc_clean(cfg="cfail3")]
66 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
67 #[rustc_clean(cfg="cfail6")]
68 pub fn var_negation(x: i32, y: i32) -> i32 {
69     -y
70 }
71
72
73
74 // Change variable operand of bitwise not --------------------------------------
75 #[cfg(any(cfail1,cfail4))]
76 pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
77     !x
78 }
79
80 #[cfg(not(any(cfail1,cfail4)))]
81 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
82 #[rustc_clean(cfg="cfail3")]
83 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
84 #[rustc_clean(cfg="cfail6")]
85 pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
86     !y
87 }
88
89
90
91 // Change variable operand of deref --------------------------------------------
92 #[cfg(any(cfail1,cfail4))]
93 pub fn var_deref(x: &i32, y: &i32) -> i32 {
94     *x
95 }
96
97 #[cfg(not(any(cfail1,cfail4)))]
98 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
99 #[rustc_clean(cfg="cfail3")]
100 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
101 #[rustc_clean(cfg="cfail6")]
102 pub fn var_deref(x: &i32, y: &i32) -> i32 {
103     *y
104 }
105
106
107
108 // Change first constant operand of addition -----------------------------------
109 #[cfg(any(cfail1,cfail4))]
110 pub fn first_const_add() -> i32 {
111     1 + 3
112 }
113
114 #[cfg(not(any(cfail1,cfail4)))]
115 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
116 #[rustc_clean(cfg="cfail3")]
117 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
118 #[rustc_clean(cfg="cfail6")]
119 pub fn first_const_add() -> i32 {
120     2 + 3
121 }
122
123
124
125 // Change second constant operand of addition -----------------------------------
126 #[cfg(any(cfail1,cfail4))]
127 pub fn second_const_add() -> i32 {
128     1 + 2
129 }
130
131 #[cfg(not(any(cfail1,cfail4)))]
132 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
133 #[rustc_clean(cfg="cfail3")]
134 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
135 #[rustc_clean(cfg="cfail6")]
136 pub fn second_const_add() -> i32 {
137     1 + 3
138 }
139
140
141
142 // Change first variable operand of addition -----------------------------------
143 #[cfg(any(cfail1,cfail4))]
144 pub fn first_var_add(a: i32, b: i32) -> i32 {
145     a + 2
146 }
147
148 #[cfg(not(any(cfail1,cfail4)))]
149 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
150 #[rustc_clean(cfg="cfail3")]
151 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
152 #[rustc_clean(cfg="cfail6")]
153 pub fn first_var_add(a: i32, b: i32) -> i32 {
154     b + 2
155 }
156
157
158
159 // Change second variable operand of addition ----------------------------------
160 #[cfg(any(cfail1,cfail4))]
161 pub fn second_var_add(a: i32, b: i32) -> i32 {
162     1 + a
163 }
164
165 #[cfg(not(any(cfail1,cfail4)))]
166 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
167 #[rustc_clean(cfg="cfail3")]
168 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
169 #[rustc_clean(cfg="cfail6")]
170 pub fn second_var_add(a: i32, b: i32) -> i32 {
171     1 + b
172 }
173
174
175
176 // Change operator from + to - -------------------------------------------------
177 #[cfg(any(cfail1,cfail4))]
178 pub fn plus_to_minus(a: i32) -> i32 {
179     1 + a
180 }
181
182 #[cfg(not(any(cfail1,cfail4)))]
183 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
184 #[rustc_clean(cfg="cfail3")]
185 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
186 #[rustc_clean(cfg="cfail6")]
187 pub fn plus_to_minus(a: i32) -> i32 {
188     1 - a
189 }
190
191
192
193 // Change operator from + to * -------------------------------------------------
194 #[cfg(any(cfail1,cfail4))]
195 pub fn plus_to_mult(a: i32) -> i32 {
196     1 + a
197 }
198
199 #[cfg(not(any(cfail1,cfail4)))]
200 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
201 #[rustc_clean(cfg="cfail3")]
202 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
203 #[rustc_clean(cfg="cfail6")]
204 pub fn plus_to_mult(a: i32) -> i32 {
205     1 * a
206 }
207
208
209
210 // Change operator from + to / -------------------------------------------------
211 #[cfg(any(cfail1,cfail4))]
212 pub fn plus_to_div(a: i32) -> i32 {
213     1 + a
214 }
215
216 #[cfg(not(any(cfail1,cfail4)))]
217 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
218 #[rustc_clean(cfg="cfail3")]
219 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
220 #[rustc_clean(cfg="cfail6")]
221 pub fn plus_to_div(a: i32) -> i32 {
222     1 / a
223 }
224
225
226
227 // Change operator from + to % -------------------------------------------------
228 #[cfg(any(cfail1,cfail4))]
229 pub fn plus_to_mod(a: i32) -> i32 {
230     1 + a
231 }
232
233 #[cfg(not(any(cfail1,cfail4)))]
234 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
235 #[rustc_clean(cfg="cfail3")]
236 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
237 #[rustc_clean(cfg="cfail6")]
238 pub fn plus_to_mod(a: i32) -> i32 {
239     1 % a
240 }
241
242
243
244 // Change operator from && to || -----------------------------------------------
245 #[cfg(any(cfail1,cfail4))]
246 pub fn and_to_or(a: bool, b: bool) -> bool {
247     a && b
248 }
249
250 #[cfg(not(any(cfail1,cfail4)))]
251 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
252 #[rustc_clean(cfg="cfail3")]
253 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
254 #[rustc_clean(cfg="cfail6")]
255 pub fn and_to_or(a: bool, b: bool) -> bool {
256     a || b
257 }
258
259
260
261 // Change operator from & to | -------------------------------------------------
262 #[cfg(any(cfail1,cfail4))]
263 pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
264     1 & a
265 }
266
267 #[cfg(not(any(cfail1,cfail4)))]
268 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
269 #[rustc_clean(cfg="cfail3")]
270 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
271 #[rustc_clean(cfg="cfail6")]
272 pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
273     1 | a
274 }
275
276
277
278 // Change operator from & to ^ -------------------------------------------------
279 #[cfg(any(cfail1,cfail4))]
280 pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
281     1 & a
282 }
283
284 #[cfg(not(any(cfail1,cfail4)))]
285 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
286 #[rustc_clean(cfg="cfail3")]
287 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
288 #[rustc_clean(cfg="cfail6")]
289 pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
290     1 ^ a
291 }
292
293
294
295 // Change operator from & to << ------------------------------------------------
296 #[cfg(any(cfail1,cfail4))]
297 pub fn bitwise_and_to_lshift(a: i32) -> i32 {
298     a  & 1
299 }
300
301 #[cfg(not(any(cfail1,cfail4)))]
302 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
303 #[rustc_clean(cfg="cfail3")]
304 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
305 #[rustc_clean(cfg="cfail6")]
306 pub fn bitwise_and_to_lshift(a: i32) -> i32 {
307     a << 1
308 }
309
310
311
312 // Change operator from & to >> ------------------------------------------------
313 #[cfg(any(cfail1,cfail4))]
314 pub fn bitwise_and_to_rshift(a: i32) -> i32 {
315     a  & 1
316 }
317
318 #[cfg(not(any(cfail1,cfail4)))]
319 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
320 #[rustc_clean(cfg="cfail3")]
321 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
322 #[rustc_clean(cfg="cfail6")]
323 pub fn bitwise_and_to_rshift(a: i32) -> i32 {
324     a >> 1
325 }
326
327
328
329 // Change operator from == to != -----------------------------------------------
330 #[cfg(any(cfail1,cfail4))]
331 pub fn eq_to_uneq(a: i32) -> bool {
332     a == 1
333 }
334
335 #[cfg(not(any(cfail1,cfail4)))]
336 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
337 #[rustc_clean(cfg="cfail3")]
338 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
339 #[rustc_clean(cfg="cfail6")]
340 pub fn eq_to_uneq(a: i32) -> bool {
341     a != 1
342 }
343
344
345
346 // Change operator from == to < ------------------------------------------------
347 #[cfg(any(cfail1,cfail4))]
348 pub fn eq_to_lt(a: i32) -> bool {
349     a == 1
350 }
351
352 #[cfg(not(any(cfail1,cfail4)))]
353 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
354 #[rustc_clean(cfg="cfail3")]
355 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
356 #[rustc_clean(cfg="cfail6")]
357 pub fn eq_to_lt(a: i32) -> bool {
358     a  < 1
359 }
360
361
362
363 // Change operator from == to > ------------------------------------------------
364 #[cfg(any(cfail1,cfail4))]
365 pub fn eq_to_gt(a: i32) -> bool {
366     a == 1
367 }
368
369 #[cfg(not(any(cfail1,cfail4)))]
370 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
371 #[rustc_clean(cfg="cfail3")]
372 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
373 #[rustc_clean(cfg="cfail6")]
374 pub fn eq_to_gt(a: i32) -> bool {
375     a  > 1
376 }
377
378
379
380 // Change operator from == to <= -----------------------------------------------
381 #[cfg(any(cfail1,cfail4))]
382 pub fn eq_to_le(a: i32) -> bool {
383     a == 1
384 }
385
386 #[cfg(not(any(cfail1,cfail4)))]
387 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
388 #[rustc_clean(cfg="cfail3")]
389 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
390 #[rustc_clean(cfg="cfail6")]
391 pub fn eq_to_le(a: i32) -> bool {
392     a <= 1
393 }
394
395
396
397 // Change operator from == to >= -----------------------------------------------
398 #[cfg(any(cfail1,cfail4))]
399 pub fn eq_to_ge(a: i32) -> bool {
400     a == 1
401 }
402
403 #[cfg(not(any(cfail1,cfail4)))]
404 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
405 #[rustc_clean(cfg="cfail3")]
406 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
407 #[rustc_clean(cfg="cfail6")]
408 pub fn eq_to_ge(a: i32) -> bool {
409     a >= 1
410 }
411
412
413
414 // Change type in cast expression ----------------------------------------------
415 #[cfg(any(cfail1,cfail4))]
416 pub fn type_cast(a: u8) -> u64 {
417     let b = a as i32;
418     let c = b as u64;
419     c
420 }
421
422 #[cfg(not(any(cfail1,cfail4)))]
423 #[rustc_clean(except="hir_owner_nodes,optimized_mir,typeck", cfg="cfail2")]
424 #[rustc_clean(cfg="cfail3")]
425 #[rustc_clean(except="hir_owner_nodes,optimized_mir,typeck", cfg="cfail5")]
426 #[rustc_clean(cfg="cfail6")]
427 pub fn type_cast(a: u8) -> u64 {
428     let b = a as u32;
429     let c = b as u64;
430     c
431 }
432
433
434
435 // Change value in cast expression ---------------------------------------------
436 #[cfg(any(cfail1,cfail4))]
437 pub fn value_cast(a: u32) -> i32 {
438     1 as i32
439 }
440
441 #[cfg(not(any(cfail1,cfail4)))]
442 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
443 #[rustc_clean(cfg="cfail3")]
444 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
445 #[rustc_clean(cfg="cfail6")]
446 pub fn value_cast(a: u32) -> i32 {
447     2 as i32
448 }
449
450
451
452 // Change place in assignment --------------------------------------------------
453 #[cfg(any(cfail1,cfail4))]
454 pub fn place() -> i32 {
455     let mut x = 10;
456     let mut y = 11;
457     x = 9;
458     x
459 }
460
461 #[cfg(not(any(cfail1,cfail4)))]
462 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
463 #[rustc_clean(cfg="cfail3")]
464 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
465 #[rustc_clean(cfg="cfail6")]
466 pub fn place() -> i32 {
467     let mut x = 10;
468     let mut y = 11;
469     y = 9;
470     x
471 }
472
473
474
475 // Change r-value in assignment ------------------------------------------------
476 #[cfg(any(cfail1,cfail4))]
477 pub fn rvalue() -> i32 {
478     let mut x = 10;
479     x = 9;
480     x
481 }
482
483 #[cfg(not(any(cfail1,cfail4)))]
484 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
485 #[rustc_clean(cfg="cfail3")]
486 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
487 #[rustc_clean(cfg="cfail6")]
488 pub fn rvalue() -> i32 {
489     let mut x = 10;
490     x = 8;
491     x
492 }
493
494
495
496 // Change index into slice -----------------------------------------------------
497 #[cfg(any(cfail1,cfail4))]
498 pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
499     s[i]
500 }
501
502 #[cfg(not(any(cfail1,cfail4)))]
503 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")]
504 #[rustc_clean(cfg="cfail3")]
505 #[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail5")]
506 #[rustc_clean(cfg="cfail6")]
507 pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
508     s[j]
509 }