1616// compile-flags: -Z lower_128bit_ops=yes -C debug_assertions=yes
1717
1818#![ feature( i128_type) ]
19+ #![ feature( const_fn) ]
20+
21+ static TEST_SIGNED : i128 = const_signed ( -222 ) ;
22+ static TEST_UNSIGNED : u128 = const_unsigned ( 200 ) ;
23+
24+ const fn const_signed ( mut x : i128 ) -> i128 {
25+ ( ( ( ( ( ( x + 1 ) - 2 ) * 3 ) / 4 ) % 5 ) << 6 ) >> 7
26+ }
27+
28+ const fn const_unsigned ( mut x : u128 ) -> u128 {
29+ ( ( ( ( ( ( x + 1 ) - 2 ) * 3 ) / 4 ) % 5 ) << 6 ) >> 7
30+ }
1931
2032fn test_signed ( mut x : i128 ) -> i128 {
2133 x += 1 ;
@@ -39,13 +51,121 @@ fn test_unsigned(mut x: u128) -> u128 {
3951 x
4052}
4153
54+ fn check ( x : i128 , y : u128 ) {
55+ assert_eq ! ( test_signed( x) , -1 ) ;
56+ assert_eq ! ( const_signed( x) , -1 ) ;
57+ assert_eq ! ( TEST_SIGNED , -1 ) ;
58+ assert_eq ! ( test_unsigned( y) , 2 ) ;
59+ assert_eq ! ( const_unsigned( y) , 2 ) ;
60+ assert_eq ! ( TEST_UNSIGNED , 2 ) ;
61+ }
62+
4263fn main ( ) {
43- assert_eq ! ( test_signed( -222 ) , -1 ) ;
44- assert_eq ! ( test_unsigned( 200 ) , 2 ) ;
64+ check ( -222 , 200 ) ;
4565}
4666
4767// END RUST SOURCE
4868
69+ // START rustc.const_signed.Lower128Bit.after.mir
70+ // _8 = _1;
71+ // _9 = const compiler_builtins::int::addsub::rust_i128_addo(move _8, const 1i128) -> bb10;
72+ // ...
73+ // _7 = move (_9.0: i128);
74+ // ...
75+ // _10 = const compiler_builtins::int::addsub::rust_i128_subo(move _7, const 2i128) -> bb11;
76+ // ...
77+ // _6 = move (_10.0: i128);
78+ // ...
79+ // _11 = const compiler_builtins::int::mul::rust_i128_mulo(move _6, const 3i128) -> bb12;
80+ // ...
81+ // _5 = move (_11.0: i128);
82+ // ...
83+ // _12 = Eq(const 4i128, const 0i128);
84+ // assert(!move _12, "attempt to divide by zero") -> bb4;
85+ // ...
86+ // _13 = Eq(const 4i128, const -1i128);
87+ // _14 = Eq(_5, const -170141183460469231731687303715884105728i128);
88+ // _15 = BitAnd(move _13, move _14);
89+ // assert(!move _15, "attempt to divide with overflow") -> bb5;
90+ // ...
91+ // _4 = const compiler_builtins::int::sdiv::rust_i128_div(move _5, const 4i128) -> bb13;
92+ // ...
93+ // _17 = Eq(const 5i128, const -1i128);
94+ // _18 = Eq(_4, const -170141183460469231731687303715884105728i128);
95+ // _19 = BitAnd(move _17, move _18);
96+ // assert(!move _19, "attempt to calculate the remainder with overflow") -> bb7;
97+ // ...
98+ // _3 = const compiler_builtins::int::sdiv::rust_i128_rem(move _4, const 5i128) -> bb15;
99+ // ...
100+ // _2 = move (_20.0: i128);
101+ // ...
102+ // _23 = const 7i32 as u128 (Misc);
103+ // _21 = const compiler_builtins::int::shift::rust_i128_shro(move _2, move _23) -> bb16;
104+ // ...
105+ // _0 = move (_21.0: i128);
106+ // ...
107+ // assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
108+ // ...
109+ // assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
110+ // ...
111+ // assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
112+ // ...
113+ // _16 = Eq(const 5i128, const 0i128);
114+ // assert(!move _16, "attempt to calculate the remainder with a divisor of zero") -> bb6;
115+ // ...
116+ // assert(!move (_20.1: bool), "attempt to shift left with overflow") -> bb8;
117+ // ...
118+ // _22 = const 6i32 as u128 (Misc);
119+ // _20 = const compiler_builtins::int::shift::rust_i128_shlo(move _3, move _22) -> bb14;
120+ // ...
121+ // assert(!move (_21.1: bool), "attempt to shift right with overflow") -> bb9;
122+ // END rustc.const_signed.Lower128Bit.after.mir
123+
124+ // START rustc.const_unsigned.Lower128Bit.after.mir
125+ // _8 = _1;
126+ // _9 = const compiler_builtins::int::addsub::rust_u128_addo(move _8, const 1u128) -> bb8;
127+ // ...
128+ // _7 = move (_9.0: u128);
129+ // ...
130+ // _10 = const compiler_builtins::int::addsub::rust_u128_subo(move _7, const 2u128) -> bb9;
131+ // ...
132+ // _6 = move (_10.0: u128);
133+ // ...
134+ // _11 = const compiler_builtins::int::mul::rust_u128_mulo(move _6, const 3u128) -> bb10;
135+ // ...
136+ // _5 = move (_11.0: u128);
137+ // ...
138+ // _12 = Eq(const 4u128, const 0u128);
139+ // assert(!move _12, "attempt to divide by zero") -> bb4;
140+ // ...
141+ // _4 = const compiler_builtins::int::udiv::rust_u128_div(move _5, const 4u128) -> bb11;
142+ // ...
143+ // _3 = const compiler_builtins::int::udiv::rust_u128_rem(move _4, const 5u128) -> bb13;
144+ // ...
145+ // _2 = move (_14.0: u128);
146+ // ...
147+ // _17 = const 7i32 as u128 (Misc);
148+ // _15 = const compiler_builtins::int::shift::rust_u128_shro(move _2, move _17) -> bb14;
149+ // ...
150+ // _0 = move (_15.0: u128);
151+ // ...
152+ // assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
153+ // ...
154+ // assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
155+ // ...
156+ // assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
157+ // ...
158+ // _13 = Eq(const 5u128, const 0u128);
159+ // assert(!move _13, "attempt to calculate the remainder with a divisor of zero") -> bb5;
160+ // ...
161+ // assert(!move (_14.1: bool), "attempt to shift left with overflow") -> bb6;
162+ // ...
163+ // _16 = const 6i32 as u128 (Misc);
164+ // _14 = const compiler_builtins::int::shift::rust_u128_shlo(move _3, move _16) -> bb12;
165+ // ...
166+ // assert(!move (_15.1: bool), "attempt to shift right with overflow") -> bb7;
167+ // END rustc.const_unsigned.Lower128Bit.after.mir
168+
49169// START rustc.test_signed.Lower128Bit.after.mir
50170// _2 = const compiler_builtins::int::addsub::rust_i128_addo(_1, const 1i128) -> bb10;
51171// ...
0 commit comments