]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/hashes/panic_exprs.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / incremental / hashes / panic_exprs.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 // This test case tests the incremental compilation hash (ICH) implementation
12 // for exprs that can panic at runtime (e.g. because of bounds checking). For
13 // these expressions an error message containing their source location is
14 // generated, so their hash must always depend on their location in the source
15 // code, not just when debuginfo is enabled.
16
17 // The general pattern followed here is: Change one thing between rev1 and rev2
18 // and make sure that the hash has changed, then change nothing between rev2 and
19 // rev3 and make sure that the hash has not changed.
20
21 // must-compile-successfully
22 // revisions: cfail1 cfail2 cfail3
23 // compile-flags: -Z query-dep-graph -C debug-assertions
24
25 #![allow(warnings)]
26 #![feature(rustc_attrs)]
27 #![crate_type="rlib"]
28
29
30 // Indexing expression ---------------------------------------------------------
31 #[cfg(cfail1)]
32 pub fn indexing(slice: &[u8]) -> u8 {
33 slice[100]
34 }
35
36 #[cfg(not(cfail1))]
37 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
38 #[rustc_clean(cfg="cfail3")]
39 #[rustc_metadata_clean(cfg="cfail2")]
40 #[rustc_metadata_clean(cfg="cfail3")]
41 pub fn indexing(slice: &[u8]) -> u8 {
42 slice[100]
43 }
44
45
46 // Arithmetic overflow plus ----------------------------------------------------
47 #[cfg(cfail1)]
48 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
49 val + 1
50 }
51
52 #[cfg(not(cfail1))]
53 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
54 #[rustc_clean(cfg="cfail3")]
55 #[rustc_metadata_clean(cfg="cfail2")]
56 #[rustc_metadata_clean(cfg="cfail3")]
57 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
58 val + 1
59 }
60
61
62 // Arithmetic overflow minus ----------------------------------------------------
63 #[cfg(cfail1)]
64 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
65 val - 1
66 }
67
68 #[cfg(not(cfail1))]
69 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
70 #[rustc_clean(cfg="cfail3")]
71 #[rustc_metadata_clean(cfg="cfail2")]
72 #[rustc_metadata_clean(cfg="cfail3")]
73 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
74 val - 1
75 }
76
77
78 // Arithmetic overflow mult ----------------------------------------------------
79 #[cfg(cfail1)]
80 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
81 val * 2
82 }
83
84 #[cfg(not(cfail1))]
85 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
86 #[rustc_clean(cfg="cfail3")]
87 #[rustc_metadata_clean(cfg="cfail2")]
88 #[rustc_metadata_clean(cfg="cfail3")]
89 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
90 val * 2
91 }
92
93
94 // Arithmetic overflow negation ------------------------------------------------
95 #[cfg(cfail1)]
96 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
97 -val
98 }
99
100 #[cfg(not(cfail1))]
101 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
102 #[rustc_clean(cfg="cfail3")]
103 #[rustc_metadata_clean(cfg="cfail2")]
104 #[rustc_metadata_clean(cfg="cfail3")]
105 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
106 -val
107 }
108
109
110 // Division by zero ------------------------------------------------------------
111 #[cfg(cfail1)]
112 pub fn division_by_zero(val: i32) -> i32 {
113 2 / val
114 }
115
116 #[cfg(not(cfail1))]
117 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
118 #[rustc_clean(cfg="cfail3")]
119 #[rustc_metadata_clean(cfg="cfail2")]
120 #[rustc_metadata_clean(cfg="cfail3")]
121 pub fn division_by_zero(val: i32) -> i32 {
122 2 / val
123 }
124
125 // Division by zero ------------------------------------------------------------
126 #[cfg(cfail1)]
127 pub fn mod_by_zero(val: i32) -> i32 {
128 2 % val
129 }
130
131 #[cfg(not(cfail1))]
132 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
133 #[rustc_clean(cfg="cfail3")]
134 #[rustc_metadata_clean(cfg="cfail2")]
135 #[rustc_metadata_clean(cfg="cfail3")]
136 pub fn mod_by_zero(val: i32) -> i32 {
137 2 % val
138 }
139
140
141 // shift left ------------------------------------------------------------------
142 #[cfg(cfail1)]
143 pub fn shift_left(val: i32, shift: usize) -> i32 {
144 val << shift
145 }
146
147 #[cfg(not(cfail1))]
148 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
149 #[rustc_clean(cfg="cfail3")]
150 #[rustc_metadata_clean(cfg="cfail2")]
151 #[rustc_metadata_clean(cfg="cfail3")]
152 pub fn shift_left(val: i32, shift: usize) -> i32 {
153 val << shift
154 }
155
156
157 // shift right ------------------------------------------------------------------
158 #[cfg(cfail1)]
159 pub fn shift_right(val: i32, shift: usize) -> i32 {
160 val >> shift
161 }
162
163 #[cfg(not(cfail1))]
164 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
165 #[rustc_clean(cfg="cfail3")]
166 #[rustc_metadata_clean(cfg="cfail2")]
167 #[rustc_metadata_clean(cfg="cfail3")]
168 pub fn shift_right(val: i32, shift: usize) -> i32 {
169 val >> shift
170 }
171
172
173 // THE FOLLOWING ITEMS SHOULD NOT BE INFLUENCED BY THEIR SOURCE LOCATION
174
175 // bitwise ---------------------------------------------------------------------
176 #[cfg(cfail1)]
177 pub fn bitwise(val: i32) -> i32 {
178 !val & 0x101010101 | 0x45689 ^ 0x2372382
179 }
180
181 #[cfg(not(cfail1))]
182 #[rustc_clean(cfg="cfail2")]
183 #[rustc_clean(cfg="cfail3")]
184 #[rustc_metadata_clean(cfg="cfail2")]
185 #[rustc_metadata_clean(cfg="cfail3")]
186 pub fn bitwise(val: i32) -> i32 {
187 !val & 0x101010101 | 0x45689 ^ 0x2372382
188 }
189
190
191 // logical ---------------------------------------------------------------------
192 #[cfg(cfail1)]
193 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {
194 val1 && val2 || val3
195 }
196
197 #[cfg(not(cfail1))]
198 #[rustc_clean(cfg="cfail2")]
199 #[rustc_clean(cfg="cfail3")]
200 #[rustc_metadata_clean(cfg="cfail2")]
201 #[rustc_metadata_clean(cfg="cfail3")]
202 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {
203 val1 && val2 || val3
204 }