]>
Commit | Line | Data |
---|---|---|
c30ab7b3 | 1 | // This test case tests the incremental compilation hash (ICH) implementation |
0731742a | 2 | // for exprs that can panic at runtime (e.g., because of bounds checking). For |
c30ab7b3 SL |
3 | // these expressions an error message containing their source location is |
4 | // generated, so their hash must always depend on their location in the source | |
5 | // code, not just when debuginfo is enabled. | |
6 | ||
7 | // The general pattern followed here is: Change one thing between rev1 and rev2 | |
8 | // and make sure that the hash has changed, then change nothing between rev2 and | |
9 | // rev3 and make sure that the hash has not changed. | |
10 | ||
83c7162d | 11 | // compile-pass |
c30ab7b3 SL |
12 | // revisions: cfail1 cfail2 cfail3 |
13 | // compile-flags: -Z query-dep-graph -C debug-assertions | |
14 | ||
15 | #![allow(warnings)] | |
16 | #![feature(rustc_attrs)] | |
17 | #![crate_type="rlib"] | |
18 | ||
19 | ||
20 | // Indexing expression --------------------------------------------------------- | |
532ac7d7 | 21 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 22 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 23 | pub fn indexing(slice: &[u8]) -> u8 { |
ff7c6d11 XL |
24 | #[cfg(cfail1)] |
25 | { | |
26 | slice[100] | |
27 | } | |
28 | #[cfg(not(cfail1))] | |
29 | { | |
30 | slice[100] | |
31 | } | |
c30ab7b3 SL |
32 | } |
33 | ||
34 | ||
35 | // Arithmetic overflow plus ---------------------------------------------------- | |
532ac7d7 | 36 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 37 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 38 | pub fn arithmetic_overflow_plus(val: i32) -> i32 { |
ff7c6d11 XL |
39 | #[cfg(cfail1)] |
40 | { | |
41 | val + 1 | |
42 | } | |
43 | #[cfg(not(cfail1))] | |
44 | { | |
45 | val + 1 | |
46 | } | |
c30ab7b3 SL |
47 | } |
48 | ||
49 | ||
50 | // Arithmetic overflow minus ---------------------------------------------------- | |
532ac7d7 | 51 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 52 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 53 | pub fn arithmetic_overflow_minus(val: i32) -> i32 { |
ff7c6d11 XL |
54 | #[cfg(cfail1)] |
55 | { | |
56 | val - 1 | |
57 | } | |
58 | #[cfg(not(cfail1))] | |
59 | { | |
60 | val - 1 | |
61 | } | |
c30ab7b3 SL |
62 | } |
63 | ||
64 | ||
65 | // Arithmetic overflow mult ---------------------------------------------------- | |
532ac7d7 | 66 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 67 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 68 | pub fn arithmetic_overflow_mult(val: i32) -> i32 { |
ff7c6d11 XL |
69 | #[cfg(cfail1)] |
70 | { | |
71 | val * 2 | |
72 | } | |
73 | #[cfg(not(cfail1))] | |
74 | { | |
75 | val * 2 | |
76 | } | |
c30ab7b3 SL |
77 | } |
78 | ||
79 | ||
80 | // Arithmetic overflow negation ------------------------------------------------ | |
532ac7d7 | 81 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 82 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 83 | pub fn arithmetic_overflow_negation(val: i32) -> i32 { |
ff7c6d11 XL |
84 | #[cfg(cfail1)] |
85 | { | |
86 | -val | |
87 | } | |
88 | #[cfg(not(cfail1))] | |
89 | { | |
90 | -val | |
91 | } | |
c30ab7b3 SL |
92 | } |
93 | ||
94 | ||
95 | // Division by zero ------------------------------------------------------------ | |
532ac7d7 | 96 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 97 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 98 | pub fn division_by_zero(val: i32) -> i32 { |
ff7c6d11 XL |
99 | #[cfg(cfail1)] |
100 | { | |
101 | 2 / val | |
102 | } | |
103 | #[cfg(not(cfail1))] | |
104 | { | |
105 | 2 / val | |
106 | } | |
c30ab7b3 SL |
107 | } |
108 | ||
109 | // Division by zero ------------------------------------------------------------ | |
532ac7d7 | 110 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 111 | #[rustc_clean(cfg="cfail3")] |
c30ab7b3 | 112 | pub fn mod_by_zero(val: i32) -> i32 { |
ff7c6d11 XL |
113 | #[cfg(cfail1)] |
114 | { | |
115 | 2 % val | |
116 | } | |
117 | #[cfg(not(cfail1))] | |
118 | { | |
119 | 2 % val | |
120 | } | |
c30ab7b3 SL |
121 | } |
122 | ||
123 | ||
abe05a73 | 124 | // shift left ------------------------------------------------------------------ |
532ac7d7 | 125 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 126 | #[rustc_clean(cfg="cfail3")] |
abe05a73 | 127 | pub fn shift_left(val: i32, shift: usize) -> i32 { |
ff7c6d11 XL |
128 | #[cfg(cfail1)] |
129 | { | |
130 | val << shift | |
131 | } | |
132 | #[cfg(not(cfail1))] | |
133 | { | |
134 | val << shift | |
135 | } | |
abe05a73 XL |
136 | } |
137 | ||
138 | ||
139 | // shift right ------------------------------------------------------------------ | |
532ac7d7 | 140 | #[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")] |
abe05a73 | 141 | #[rustc_clean(cfg="cfail3")] |
abe05a73 | 142 | pub fn shift_right(val: i32, shift: usize) -> i32 { |
ff7c6d11 XL |
143 | #[cfg(cfail1)] |
144 | { | |
145 | val >> shift | |
146 | } | |
147 | #[cfg(not(cfail1))] | |
148 | { | |
149 | val >> shift | |
150 | } | |
c30ab7b3 | 151 | } |