-
Notifications
You must be signed in to change notification settings - Fork 32
/
overflowing-consts.rs
288 lines (192 loc) · 15.3 KB
/
overflowing-consts.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Tests that overflowing or bound-exceeding operations
// for compile-time consts raise errors
//@ revisions: noopt opt opt_with_overflow_checks
//@ [noopt]compile-flags: -C opt-level=0
//@ [opt]compile-flags: -O
//@ [opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
//@ ignore-pass (test tests codegen-time behaviour)
//@ normalize-stderr-test "shift left by `(64|32)_usize`, which" -> "shift left by `%BITS%`, which"
//@ normalize-stderr-test "shift right by `(64|32)_usize`, which" -> "shift right by `%BITS%`, which"
#[cfg(target_pointer_width = "32")]
const BITS: usize = 32;
#[cfg(target_pointer_width = "64")]
const BITS: usize = 64;
// Shift left
const _NI8_SHL: i8 = 1i8 << 8; //~ ERROR: evaluation of constant value failed
const _NI8_SHL_P: &i8 = &(1i8 << 8); //~ ERROR: evaluation of constant value failed
const _NI16_SHL: i16 = 1i16 << 16; //~ ERROR: evaluation of constant value failed
const _NI16_SHL_P: &i16 = &(1i16 << 16); //~ ERROR: evaluation of constant value failed
const _NI32_SHL: i32 = 1i32 << 32; //~ ERROR: evaluation of constant value failed
const _NI32_SHL_P: &i32 = &(1i32 << 32); //~ ERROR: evaluation of constant value failed
const _NI64_SHL: i64 = 1i64 << 64; //~ ERROR: evaluation of constant value failed
const _NI64_SHL_P: &i64 = &(1i64 << 64); //~ ERROR: evaluation of constant value failed
const _NI128_SHL: i128 = 1i128 << 128; //~ ERROR: evaluation of constant value failed
const _NI128_SHL_P: &i128 = &(1i128 << 128); //~ ERROR: evaluation of constant value failed
const _NU8_SHL: u8 = 1u8 << 8; //~ ERROR: evaluation of constant value failed
const _NU8_SHL_P: &u8 = &(1u8 << 8); //~ ERROR: evaluation of constant value failed
const _NU16_SHL: u16 = 1u16 << 16; //~ ERROR: evaluation of constant value failed
const _NU16_SHL_P: &u16 = &(1u16 << 16); //~ ERROR: evaluation of constant value failed
const _NU32_SHL: u32 = 1u32 << 32; //~ ERROR: evaluation of constant value failed
const _NU32_SHL_P: &u32 = &(1u32 << 32); //~ ERROR: evaluation of constant value failed
const _NU64_SHL: u64 = 1u64 << 64; //~ ERROR: evaluation of constant value failed
const _NU64_SHL_P: &u64 = &(1u64 << 64); //~ ERROR: evaluation of constant value failed
const _NU128_SHL: u128 = 1u128 << 128; //~ ERROR: evaluation of constant value failed
const _NU128_SHL_P: &u128 = &(1u128 << 128); //~ ERROR: evaluation of constant value failed
const _NISIZE_SHL: isize = 1isize << BITS; //~ ERROR: evaluation of constant value failed
const _NISIZE_SHL_P: &isize = &(1isize << BITS); //~ ERROR: evaluation of constant value failed
const _NUSIZE_SHL: usize = 1usize << BITS; //~ ERROR: evaluation of constant value failed
const _NUSIZE_SHL_P: &usize = &(1usize << BITS); //~ ERROR: evaluation of constant value failed
// Shift right
const _NI8_SHR: i8 = 1i8 >> 8; //~ ERROR: evaluation of constant value failed
const _NI8_SHR_P: &i8 = &(1i8 >> 8); //~ ERROR: evaluation of constant value failed
const _NI16_SHR: i16 = 1i16 >> 16; //~ ERROR: evaluation of constant value failed
const _NI16_SHR_P: &i16 = &(1i16 >> 16); //~ ERROR: evaluation of constant value failed
const _NI32_SHR: i32 = 1i32 >> 32; //~ ERROR: evaluation of constant value failed
const _NI32_SHR_P: &i32 = &(1i32 >> 32); //~ ERROR: evaluation of constant value failed
const _NI64_SHR: i64 = 1i64 >> 64; //~ ERROR: evaluation of constant value failed
const _NI64_SHR_P: &i64 = &(1i64 >> 64); //~ ERROR: evaluation of constant value failed
const _NI128_SHR: i128 = 1i128 >> 128; //~ ERROR: evaluation of constant value failed
const _NI128_SHR_P: &i128 = &(1i128 >> 128); //~ ERROR: evaluation of constant value failed
const _NU8_SHR: u8 = 1u8 >> 8; //~ ERROR: evaluation of constant value failed
const _NU8_SHR_P: &u8 = &(1u8 >> 8); //~ ERROR: evaluation of constant value failed
const _NU16_SHR: u16 = 1u16 >> 16; //~ ERROR: evaluation of constant value failed
const _NU16_SHR_P: &u16 = &(1u16 >> 16); //~ ERROR: evaluation of constant value failed
const _NU32_SHR: u32 = 1u32 >> 32; //~ ERROR: evaluation of constant value failed
const _NU32_SHR_P: &u32 = &(1u32 >> 32); //~ ERROR: evaluation of constant value failed
const _NU64_SHR: u64 = 1u64 >> 64; //~ ERROR: evaluation of constant value failed
const _NU64_SHR_P: &u64 = &(1u64 >> 64); //~ ERROR: evaluation of constant value failed
const _NU128_SHR: u128 = 1u128 >> 128; //~ ERROR: evaluation of constant value failed
const _NU128_SHR_P: &u128 = &(1u128 >> 128); //~ ERROR: evaluation of constant value failed
const _NISIZE_SHR: isize = 1isize >> BITS; //~ ERROR: evaluation of constant value failed
const _NISIZE_SHR_P: &isize = &(1isize >> BITS); //~ ERROR: evaluation of constant value failed
const _NUSIZE_SHR: usize = 1usize >> BITS; //~ ERROR: evaluation of constant value failed
const _NUSIZE_SHR_P: &usize = &(1usize >> BITS); //~ ERROR: evaluation of constant value failed
// Addition
const _NI8_ADD: i8 = 1i8 + i8::MAX; //~ ERROR: evaluation of constant value failed
const _NI8_ADD_P: &i8 = &(1i8 + i8::MAX); //~ ERROR: evaluation of constant value failed
const _NI16_ADD: i16 = 1i16 + i16::MAX; //~ ERROR: evaluation of constant value failed
const _NI16_ADD_P: &i16 = &(1i16 + i16::MAX); //~ ERROR: evaluation of constant value failed
const _NI32_ADD: i32 = 1i32 + i32::MAX; //~ ERROR: evaluation of constant value failed
const _NI32_ADD_P: &i32 = &(1i32 + i32::MAX); //~ ERROR: evaluation of constant value failed
const _NI64_ADD: i64 = 1i64 + i64::MAX; //~ ERROR: evaluation of constant value failed
const _NI64_ADD_P: &i64 = &(1i64 + i64::MAX); //~ ERROR: evaluation of constant value failed
const _NI128_ADD: i128 = 1i128 + i128::MAX; //~ ERROR: evaluation of constant value failed
const _NI128_ADD_P: &i128 = &(1i128 + i128::MAX); //~ ERROR: evaluation of constant value failed
const _NU8_ADD: u8 = 1u8 + u8::MAX; //~ ERROR: evaluation of constant value failed
const _NU8_ADD_P: &u8 = &(1u8 + u8::MAX); //~ ERROR: evaluation of constant value failed
const _NU16_ADD: u16 = 1u16 + u16::MAX; //~ ERROR: evaluation of constant value failed
const _NU16_ADD_P: &u16 = &(1u16 + u16::MAX); //~ ERROR: evaluation of constant value failed
const _NU32_ADD: u32 = 1u32 + u32::MAX; //~ ERROR: evaluation of constant value failed
const _NU32_ADD_P: &u32 = &(1u32 + u32::MAX); //~ ERROR: evaluation of constant value failed
const _NU64_ADD: u64 = 1u64 + u64::MAX; //~ ERROR: evaluation of constant value failed
const _NU64_ADD_P: &u64 = &(1u64 + u64::MAX); //~ ERROR: evaluation of constant value failed
const _NU128_ADD: u128 = 1u128 + u128::MAX; //~ ERROR: evaluation of constant value failed
const _NU128_ADD_P: &u128 = &(1u128 + u128::MAX); //~ ERROR: evaluation of constant value failed
const _NISIZE_ADD: isize = 1isize + isize::MAX; //~ ERROR: evaluation of constant value failed
const _NISIZE_ADD_P: &isize = &(1isize + isize::MAX); //~ ERROR: evaluation of constant value failed
const _NUSIZE_ADD: usize = 1usize + usize::MAX; //~ ERROR: evaluation of constant value failed
const _NUSIZE_ADD_P: &usize = &(1usize + usize::MAX); //~ ERROR: evaluation of constant value failed
// Subtraction
const _NI8_SUB: i8 = -5i8 - i8::MAX; //~ ERROR: evaluation of constant value failed
const _NI8_SUB_P: &i8 = &(-5i8 - i8::MAX); //~ ERROR: evaluation of constant value failed
const _NI16_SUB: i16 = -5i16 - i16::MAX; //~ ERROR: evaluation of constant value failed
const _NI16_SUB_P: &i16 = &(-5i16 - i16::MAX); //~ ERROR: evaluation of constant value failed
const _NI32_SUB: i32 = -5i32 - i32::MAX; //~ ERROR: evaluation of constant value failed
const _NI32_SUB_P: &i32 = &(-5i32 - i32::MAX); //~ ERROR: evaluation of constant value failed
const _NI64_SUB: i64 = -5i64 - i64::MAX; //~ ERROR: evaluation of constant value failed
const _NI64_SUB_P: &i64 = &(-5i64 - i64::MAX); //~ ERROR: evaluation of constant value failed
const _NI128_SUB: i128 = -5i128 - i128::MAX; //~ ERROR: evaluation of constant value failed
const _NI128_SUB_P: &i128 = &(-5i128 - i128::MAX); //~ ERROR: evaluation of constant value failed
const _NU8_SUB: u8 = 1u8 - 5; //~ ERROR: evaluation of constant value failed
const _NU8_SUB_P: &u8 = &(1u8 - 5); //~ ERROR: evaluation of constant value failed
const _NU16_SUB: u16 = 1u16 - 5; //~ ERROR: evaluation of constant value failed
const _NU16_SUB_P: &u16 = &(1u16 - 5); //~ ERROR: evaluation of constant value failed
const _NU32_SUB: u32 = 1u32 - 5; //~ ERROR: evaluation of constant value failed
const _NU32_SUB_P: &u32 = &(1u32 - 5); //~ ERROR: evaluation of constant value failed
const _NU64_SUB: u64 = 1u64 - 5; //~ ERROR: evaluation of constant value failed
const _NU64_SUB_P: &u64 = &(1u64 - 5); //~ ERROR: evaluation of constant value failed
const _NU128_SUB: u128 = 1u128 - 5; //~ ERROR: evaluation of constant value failed
const _NU128_SUB_P: &u128 = &(1u128 - 5); //~ ERROR: evaluation of constant value failed
const _NISIZE_SUB: isize = -5isize - isize::MAX; //~ ERROR: evaluation of constant value failed
const _NISIZE_SUB_P: &isize = &(-5isize - isize::MAX); //~ ERROR: evaluation of constant value failed
const _NUSIZE_SUB: usize = 1usize - 5 ; //~ ERROR: evaluation of constant value failed
const _NUSIZE_SUB_P: &usize = &(1usize - 5 ); //~ ERROR: evaluation of constant value failed
// Multiplication
const _NI8_MUL: i8 = i8::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NI8_MUL_P: &i8 = &(i8::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NI16_MUL: i16 = i16::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NI16_MUL_P: &i16 = &(i16::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NI32_MUL: i32 = i32::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NI32_MUL_P: &i32 = &(i32::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NI64_MUL: i64 = i64::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NI64_MUL_P: &i64 = &(i64::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NI128_MUL: i128 = i128::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NI128_MUL_P: &i128 = &(i128::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NU8_MUL: u8 = u8::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NU8_MUL_P: &u8 = &(u8::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NU16_MUL: u16 = u16::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NU16_MUL_P: &u16 = &(u16::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NU32_MUL: u32 = u32::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NU32_MUL_P: &u32 = &(u32::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NU64_MUL: u64 = u64::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NU64_MUL_P: &u64 = &(u64::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NU128_MUL: u128 = u128::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NU128_MUL_P: &u128 = &(u128::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NISIZE_MUL: isize = isize::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NISIZE_MUL_P: &isize = &(isize::MAX * 5); //~ ERROR: evaluation of constant value failed
const _NUSIZE_MUL: usize = usize::MAX * 5; //~ ERROR: evaluation of constant value failed
const _NUSIZE_MUL_P: &usize = &(usize::MAX * 5); //~ ERROR: evaluation of constant value failed
// Division
const _NI8_DIV: i8 = 1i8 / 0; //~ ERROR: evaluation of constant value failed
const _NI8_DIV_P: &i8 = &(1i8 / 0); //~ ERROR: evaluation of constant value failed
const _NI16_DIV: i16 = 1i16 / 0; //~ ERROR: evaluation of constant value failed
const _NI16_DIV_P: &i16 = &(1i16 / 0); //~ ERROR: evaluation of constant value failed
const _NI32_DIV: i32 = 1i32 / 0; //~ ERROR: evaluation of constant value failed
const _NI32_DIV_P: &i32 = &(1i32 / 0); //~ ERROR: evaluation of constant value failed
const _NI64_DIV: i64 = 1i64 / 0; //~ ERROR: evaluation of constant value failed
const _NI64_DIV_P: &i64 = &(1i64 / 0); //~ ERROR: evaluation of constant value failed
const _NI128_DIV: i128 = 1i128 / 0; //~ ERROR: evaluation of constant value failed
const _NI128_DIV_P: &i128 = &(1i128 / 0); //~ ERROR: evaluation of constant value failed
const _NU8_DIV: u8 = 1u8 / 0; //~ ERROR: evaluation of constant value failed
const _NU8_DIV_P: &u8 = &(1u8 / 0); //~ ERROR: evaluation of constant value failed
const _NU16_DIV: u16 = 1u16 / 0; //~ ERROR: evaluation of constant value failed
const _NU16_DIV_P: &u16 = &(1u16 / 0); //~ ERROR: evaluation of constant value failed
const _NU32_DIV: u32 = 1u32 / 0; //~ ERROR: evaluation of constant value failed
const _NU32_DIV_P: &u32 = &(1u32 / 0); //~ ERROR: evaluation of constant value failed
const _NU64_DIV: u64 = 1u64 / 0; //~ ERROR: evaluation of constant value failed
const _NU64_DIV_P: &u64 = &(1u64 / 0); //~ ERROR: evaluation of constant value failed
const _NU128_DIV: u128 = 1u128 / 0; //~ ERROR: evaluation of constant value failed
const _NU128_DIV_P: &u128 = &(1u128 / 0); //~ ERROR: evaluation of constant value failed
const _NISIZE_DIV: isize = 1isize / 0; //~ ERROR: evaluation of constant value failed
const _NISIZE_DIV_P: &isize = &(1isize / 0); //~ ERROR: evaluation of constant value failed
const _NUSIZE_DIV: usize = 1usize / 0; //~ ERROR: evaluation of constant value failed
const _NUSIZE_DIV_P: &usize = &(1usize / 0); //~ ERROR: evaluation of constant value failed
// Modulus
const _NI8_MOD: i8 = 1i8 % 0; //~ ERROR: evaluation of constant value failed
const _NI8_MOD_P: &i8 = &(1i8 % 0); //~ ERROR: evaluation of constant value failed
const _NI16_MOD: i16 = 1i16 % 0; //~ ERROR: evaluation of constant value failed
const _NI16_MOD_P: &i16 = &(1i16 % 0); //~ ERROR: evaluation of constant value failed
const _NI32_MOD: i32 = 1i32 % 0; //~ ERROR: evaluation of constant value failed
const _NI32_MOD_P: &i32 = &(1i32 % 0); //~ ERROR: evaluation of constant value failed
const _NI64_MOD: i64 = 1i64 % 0; //~ ERROR: evaluation of constant value failed
const _NI64_MOD_P: &i64 = &(1i64 % 0); //~ ERROR: evaluation of constant value failed
const _NI128_MOD: i128 = 1i128 % 0; //~ ERROR: evaluation of constant value failed
const _NI128_MOD_P: &i128 = &(1i128 % 0); //~ ERROR: evaluation of constant value failed
const _NU8_MOD: u8 = 1u8 % 0; //~ ERROR: evaluation of constant value failed
const _NU8_MOD_P: &u8 = &(1u8 % 0); //~ ERROR: evaluation of constant value failed
const _NU16_MOD: u16 = 1u16 % 0; //~ ERROR: evaluation of constant value failed
const _NU16_MOD_P: &u16 = &(1u16 % 0); //~ ERROR: evaluation of constant value failed
const _NU32_MOD: u32 = 1u32 % 0; //~ ERROR: evaluation of constant value failed
const _NU32_MOD_P: &u32 = &(1u32 % 0); //~ ERROR: evaluation of constant value failed
const _NU64_MOD: u64 = 1u64 % 0; //~ ERROR: evaluation of constant value failed
const _NU64_MOD_P: &u64 = &(1u64 % 0); //~ ERROR: evaluation of constant value failed
const _NU128_MOD: u128 = 1u128 % 0; //~ ERROR: evaluation of constant value failed
const _NU128_MOD_P: &u128 = &(1u128 % 0); //~ ERROR: evaluation of constant value failed
const _NISIZE_MOD: isize = 1isize % 0; //~ ERROR: evaluation of constant value failed
const _NISIZE_MOD_P: &isize = &(1isize % 0); //~ ERROR: evaluation of constant value failed
const _NUSIZE_MOD: usize = 1usize % 0; //~ ERROR: evaluation of constant value failed
const _NUSIZE_MOD_P: &usize = &(1usize % 0); //~ ERROR: evaluation of constant value failed
// Out of bounds access
const _NI32_OOB: i32 = [1, 2, 3][4]; //~ ERROR: evaluation of constant value failed
const _NI32_OOB_P: &i32 = &([1, 2, 3][4]); //~ ERROR: evaluation of constant value failed
pub fn main() {}