]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/lower_128bit_debug_test.rs
82d081555479994d4a24bc15ec565d38d40c168d
[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(i128_type)]
19
20 fn test_signed(mut x: i128) -> i128 {
21     x += 1;
22     x -= 2;
23     x *= 3;
24     x /= 4;
25     x %= 5;
26     x <<= 6;
27     x >>= 7;
28     x
29 }
30
31 fn test_unsigned(mut x: u128) -> u128 {
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 main() {
43     assert_eq!(test_signed(-222), -1);
44     assert_eq!(test_unsigned(200), 2);
45 }
46
47 // END RUST SOURCE
48
49 // START rustc.test_signed.Lower128Bit.after.mir
50 //     _2 = const compiler_builtins::int::addsub::rust_i128_addo(_1, const 1i128) -> bb10;
51 //     ...
52 //     _1 = move (_2.0: i128);
53 //     _3 = const compiler_builtins::int::addsub::rust_i128_subo(_1, const 2i128) -> bb11;
54 //     ...
55 //     _1 = move (_3.0: i128);
56 //     _4 = const compiler_builtins::int::mul::rust_i128_mulo(_1, const 3i128) -> bb12;
57 //     ...
58 //     _1 = move (_4.0: i128);
59 //     ...
60 //     _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb13;
61 //     ...
62 //     _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb15;
63 //     ...
64 //     _1 = move (_13.0: i128);
65 //     ...
66 //     _17 = const 7i32 as u128 (Misc);
67 //     _14 = const compiler_builtins::int::shift::rust_i128_shro(_1, move _17) -> bb16;
68 //     ...
69 //     _1 = move (_14.0: i128);
70 //     ...
71 //     assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
72 //     ...
73 //     assert(!move (_3.1: bool), "attempt to subtract with overflow") -> bb2;
74 //     ...
75 //     assert(!move (_4.1: bool), "attempt to multiply with overflow") -> bb3;
76 //     ...
77 //     assert(!move (_13.1: bool), "attempt to shift left with overflow") -> bb8;
78 //     ...
79 //     _16 = const 6i32 as u128 (Misc);
80 //     _13 = const compiler_builtins::int::shift::rust_i128_shlo(_1, move _16) -> bb14;
81 //     ...
82 //     assert(!move (_14.1: bool), "attempt to shift right with overflow") -> bb9;
83 // END rustc.test_signed.Lower128Bit.after.mir
84
85 // START rustc.test_unsigned.Lower128Bit.after.mir
86 //     _2 = const compiler_builtins::int::addsub::rust_u128_addo(_1, const 1u128) -> bb8;
87 //     ...
88 //     _1 = move (_2.0: u128);
89 //     _3 = const compiler_builtins::int::addsub::rust_u128_subo(_1, const 2u128) -> bb9;
90 //     ...
91 //     _1 = move (_3.0: u128);
92 //     _4 = const compiler_builtins::int::mul::rust_u128_mulo(_1, const 3u128) -> bb10;
93 //     ...
94 //     _1 = move (_4.0: u128);
95 //     ...
96 //     _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb11;
97 //     ...
98 //     _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb13;
99 //     ...
100 //     _1 = move (_7.0: u128);
101 //     ...
102 //     _11 = const 7i32 as u128 (Misc);
103 //     _8 = const compiler_builtins::int::shift::rust_u128_shro(_1, move _11) -> bb14;
104 //     ...
105 //     _1 = move (_8.0: u128);
106 //     ...
107 //     assert(!move (_2.1: bool), "attempt to add with overflow") -> bb1;
108 //     ...
109 //     assert(!move (_3.1: bool), "attempt to subtract with overflow") -> bb2;
110 //     ...
111 //     assert(!move (_4.1: bool), "attempt to multiply with overflow") -> bb3;
112 //     ...
113 //     assert(!move (_7.1: bool), "attempt to shift left with overflow") -> bb6;
114 //     ...
115 //     _10 = const 6i32 as u128 (Misc);
116 //     _7 = const compiler_builtins::int::shift::rust_u128_shlo(_1, move _10) -> bb12;
117 //     ...
118 //     assert(!move (_8.1: bool), "attempt to shift right with overflow") -> bb7;
119 // END rustc.test_unsigned.Lower128Bit.after.mir