]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/lower_128bit_debug_test.rs
Rollup merge of #53545 - FelixMcFelix:fix-50865-beta, r=petrochenkov
[rust.git] / src / test / mir-opt / lower_128bit_debug_test.rs
1 // Copyright 2017 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 // asmjs can't even pass i128 as arguments or return values, so ignore it.
12 // this will hopefully be fixed by the LLVM 5 upgrade (#43370)
13 // ignore-asmjs
14 // ignore-emscripten
15
16 // compile-flags: -Z lower_128bit_ops=yes -C debug_assertions=yes
17
18 #![feature(const_fn)]
19
20 static TEST_SIGNED: i128 = const_signed(-222);
21 static TEST_UNSIGNED: u128 = const_unsigned(200);
22
23 const fn const_signed(mut x: i128) -> i128 {
24     ((((((x + 1) - 2) * 3) / 4) % 5) << 6) >> 7
25 }
26
27 const fn const_unsigned(mut x: u128) -> u128 {
28     ((((((x + 1) - 2) * 3) / 4) % 5) << 6) >> 7
29 }
30
31 fn test_signed(mut x: i128) -> i128 {
32     x += 1;
33     x -= 2;
34     x *= 3;
35     x /= 4;
36     x %= 5;
37     x <<= 6;
38     x >>= 7;
39     x
40 }
41
42 fn test_unsigned(mut x: u128) -> u128 {
43     x += 1;
44     x -= 2;
45     x *= 3;
46     x /= 4;
47     x %= 5;
48     x <<= 6;
49     x >>= 7;
50     x
51 }
52
53 fn check(x: i128, y: u128) {
54     assert_eq!(test_signed(x), -1);
55     assert_eq!(const_signed(x), -1);
56     assert_eq!(TEST_SIGNED, -1);
57     assert_eq!(test_unsigned(y), 2);
58     assert_eq!(const_unsigned(y), 2);
59     assert_eq!(TEST_UNSIGNED, 2);
60 }
61
62 fn main() {
63     check(-222, 200);
64 }
65
66 // END RUST SOURCE
67
68 // START rustc.const_signed.Lower128Bit.after.mir
69 //     _8 = _1;
70 //     _9 = const compiler_builtins::int::addsub::rust_i128_addo(move _8, const 1i128) -> bb10;
71 //     ...
72 //     _7 = move (_9.0: i128);
73 //     ...
74 //     _10 = const compiler_builtins::int::addsub::rust_i128_subo(move _7, const 2i128) -> bb11;
75 //     ...
76 //     _6 = move (_10.0: i128);
77 //     ...
78 //     _11 = const compiler_builtins::int::mul::rust_i128_mulo(move _6, const 3i128) -> bb12;
79 //     ...
80 //     _5 = move (_11.0: i128);
81 //     ...
82 //     _12 = Eq(const 4i128, const 0i128);
83 //     assert(!move _12, "attempt to divide by zero") -> bb4;
84 //     ...
85 //     _13 = Eq(const 4i128, const -1i128);
86 //     _14 = Eq(_5, const -170141183460469231731687303715884105728i128);
87 //     _15 = BitAnd(move _13, move _14);
88 //     assert(!move _15, "attempt to divide with overflow") -> bb5;
89 //     ...
90 //     _4 = const compiler_builtins::int::sdiv::rust_i128_div(move _5, const 4i128) -> bb13;
91 //     ...
92 //     _17 = Eq(const 5i128, const -1i128);
93 //     _18 = Eq(_4, const -170141183460469231731687303715884105728i128);
94 //     _19 = BitAnd(move _17, move _18);
95 //     assert(!move _19, "attempt to calculate the remainder with overflow") -> bb7;
96 //     ...
97 //     _3 = const compiler_builtins::int::sdiv::rust_i128_rem(move _4, const 5i128) -> bb15;
98 //     ...
99 //     _2 = move (_20.0: i128);
100 //     ...
101 //     _23 = const 7i32 as u128 (Misc);
102 //     _21 = const compiler_builtins::int::shift::rust_i128_shro(move _2, move _23) -> bb16;
103 //     ...
104 //     _0 = move (_21.0: i128);
105 //     ...
106 //     assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
107 //     ...
108 //     assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
109 //     ...
110 //     assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
111 //     ...
112 //     _16 = Eq(const 5i128, const 0i128);
113 //     assert(!move _16, "attempt to calculate the remainder with a divisor of zero") -> bb6;
114 //     ...
115 //     assert(!move (_20.1: bool), "attempt to shift left with overflow") -> bb8;
116 //     ...
117 //     _22 = const 6i32 as u128 (Misc);
118 //     _20 = const compiler_builtins::int::shift::rust_i128_shlo(move _3, move _22) -> bb14;
119 //     ...
120 //     assert(!move (_21.1: bool), "attempt to shift right with overflow") -> bb9;
121 // END rustc.const_signed.Lower128Bit.after.mir
122
123 // START rustc.const_unsigned.Lower128Bit.after.mir
124 //     _8 = _1;
125 //     _9 = const compiler_builtins::int::addsub::rust_u128_addo(move _8, const 1u128) -> bb8;
126 //     ...
127 //     _7 = move (_9.0: u128);
128 //     ...
129 //     _10 = const compiler_builtins::int::addsub::rust_u128_subo(move _7, const 2u128) -> bb9;
130 //     ...
131 //     _6 = move (_10.0: u128);
132 //     ...
133 //     _11 = const compiler_builtins::int::mul::rust_u128_mulo(move _6, const 3u128) -> bb10;
134 //     ...
135 //     _5 = move (_11.0: u128);
136 //     ...
137 //     _12 = Eq(const 4u128, const 0u128);
138 //     assert(!move _12, "attempt to divide by zero") -> bb4;
139 //     ...
140 //     _4 = const compiler_builtins::int::udiv::rust_u128_div(move _5, const 4u128) -> bb11;
141 //     ...
142 //     _3 = const compiler_builtins::int::udiv::rust_u128_rem(move _4, const 5u128) -> bb13;
143 //     ...
144 //     _2 = move (_14.0: u128);
145 //     ...
146 //     _17 = const 7i32 as u128 (Misc);
147 //     _15 = const compiler_builtins::int::shift::rust_u128_shro(move _2, move _17) -> bb14;
148 //     ...
149 //     _0 = move (_15.0: u128);
150 //     ...
151 //     assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
152 //     ...
153 //     assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
154 //     ...
155 //     assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
156 //     ...
157 //     _13 = Eq(const 5u128, const 0u128);
158 //     assert(!move _13, "attempt to calculate the remainder with a divisor of zero") -> bb5;
159 //     ...
160 //     assert(!move (_14.1: bool), "attempt to shift left with overflow") -> bb6;
161 //     ...
162 //     _16 = const 6i32 as u128 (Misc);
163 //     _14 = const compiler_builtins::int::shift::rust_u128_shlo(move _3, move _16) -> bb12;
164 //     ...
165 //     assert(!move (_15.1: bool), "attempt to shift right with overflow") -> bb7;
166 // END rustc.const_unsigned.Lower128Bit.after.mir
167
168 // START rustc.test_signed.Lower128Bit.after.mir
169 //     _2 = const compiler_builtins::int::addsub::rust_i128_addo(_1, const 1i128) -> bb10;
170 //     ...
171 //     _1 = move (_2.0: i128);
172 //     _3 = const compiler_builtins::int::addsub::rust_i128_subo(_1, const 2i128) -> bb11;
173 //     ...
174 //     _1 = move (_3.0: i128);
175 //     _4 = const compiler_builtins::int::mul::rust_i128_mulo(_1, const 3i128) -> bb12;
176 //     ...
177 //     _1 = move (_4.0: i128);
178 //     ...
179 //     _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb13;
180 //     ...
181 //     _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb15;
182 //     ...
183 //     _1 = move (_13.0: i128);
184 //     ...
185 //     _16 = const 7i32 as u128 (Misc);
186 //     _14 = const compiler_builtins::int::shift::rust_i128_shro(_1, move _16) -> bb16;
187 //     ...
188 //     _1 = move (_14.0: i128);
189 //     ...
190 //     assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
191 //     ...
192 //     assert(!move (_3.1: bool), "attempt to subtract with overflow") -> bb2;
193 //     ...
194 //     assert(!move (_4.1: bool), "attempt to multiply with overflow") -> bb3;
195 //     ...
196 //     assert(!move (_13.1: bool), "attempt to shift left with overflow") -> bb8;
197 //     ...
198 //     _15 = const 6i32 as u128 (Misc);
199 //     _13 = const compiler_builtins::int::shift::rust_i128_shlo(_1, move _15) -> bb14;
200 //     ...
201 //     assert(!move (_14.1: bool), "attempt to shift right with overflow") -> bb9;
202 // END rustc.test_signed.Lower128Bit.after.mir
203
204 // START rustc.test_unsigned.Lower128Bit.after.mir
205 //     _2 = const compiler_builtins::int::addsub::rust_u128_addo(_1, const 1u128) -> bb8;
206 //     ...
207 //     _1 = move (_2.0: u128);
208 //     _3 = const compiler_builtins::int::addsub::rust_u128_subo(_1, const 2u128) -> bb9;
209 //     ...
210 //     _1 = move (_3.0: u128);
211 //     _4 = const compiler_builtins::int::mul::rust_u128_mulo(_1, const 3u128) -> bb10;
212 //     ...
213 //     _1 = move (_4.0: u128);
214 //     ...
215 //     _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb11;
216 //     ...
217 //     _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb13;
218 //     ...
219 //     _1 = move (_7.0: u128);
220 //     ...
221 //     _10 = const 7i32 as u128 (Misc);
222 //     _8 = const compiler_builtins::int::shift::rust_u128_shro(_1, move _10) -> bb14;
223 //     ...
224 //     _1 = move (_8.0: u128);
225 //     ...
226 //     assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
227 //     ...
228 //     assert(!move (_3.1: bool), "attempt to subtract with overflow") -> bb2;
229 //     ...
230 //     assert(!move (_4.1: bool), "attempt to multiply with overflow") -> bb3;
231 //     ...
232 //     assert(!move (_7.1: bool), "attempt to shift left with overflow") -> bb6;
233 //     ...
234 //     _9 = const 6i32 as u128 (Misc);
235 //     _7 = const compiler_builtins::int::shift::rust_u128_shlo(_1, move _9) -> bb12;
236 //     ...
237 //     assert(!move (_8.1: bool), "attempt to shift right with overflow") -> bb7;
238 // END rustc.test_unsigned.Lower128Bit.after.mir