@@ -105,8 +105,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
105
105
| "overflowing_add"
106
106
| "overflowing_sub"
107
107
| "overflowing_mul"
108
- | "unchecked_shl"
109
- | "unchecked_shr"
110
108
| "add_with_overflow"
111
109
| "sub_with_overflow"
112
110
| "mul_with_overflow" => {
@@ -116,8 +114,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
116
114
"overflowing_add" => ( BinOp :: Add , true ) ,
117
115
"overflowing_sub" => ( BinOp :: Sub , true ) ,
118
116
"overflowing_mul" => ( BinOp :: Mul , true ) ,
119
- "unchecked_shl" => ( BinOp :: Shl , true ) ,
120
- "unchecked_shr" => ( BinOp :: Shr , true ) ,
121
117
"add_with_overflow" => ( BinOp :: Add , false ) ,
122
118
"sub_with_overflow" => ( BinOp :: Sub , false ) ,
123
119
"mul_with_overflow" => ( BinOp :: Mul , false ) ,
@@ -129,6 +125,34 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
129
125
self . binop_with_overflow ( bin_op, lhs, rhs, dest) ?;
130
126
}
131
127
}
128
+ "unchecked_shl" | "unchecked_shr" => {
129
+ let bits = dest. layout . size . bytes ( ) as u128 * 8 ;
130
+ let l = self . read_value ( args[ 0 ] ) ?;
131
+ let r = self . read_value ( args[ 1 ] ) ?;
132
+ let r_ty = substs. type_at ( 0 ) ;
133
+ let r_layout_of = self . layout_of ( r_ty) ?;
134
+ let r_val = r. to_scalar ( ) ?. to_bits ( r_layout_of. size ) ?;
135
+ let bin_op = match intrinsic_name {
136
+ "unchecked_shl" => {
137
+ if r_val >= bits {
138
+ return err ! ( Intrinsic (
139
+ format!( "Overflowing shift by {} in unchecked_shl" , r_val) ,
140
+ ) ) ;
141
+ }
142
+ BinOp :: Shl
143
+ } ,
144
+ "unchecked_shr" => {
145
+ if r_val >= bits {
146
+ return err ! ( Intrinsic (
147
+ format!( "Overflowing shift by {} in unchecked_shr" , r_val) ,
148
+ ) ) ;
149
+ }
150
+ BinOp :: Shr
151
+ } ,
152
+ _ => bug ! ( "Already checked for int ops" )
153
+ } ;
154
+ self . binop_ignore_overflow ( bin_op, l, r, dest) ?;
155
+ }
132
156
"transmute" => {
133
157
// Go through an allocation, to make sure the completely different layouts
134
158
// do not pose a problem. (When the user transmutes through a union,
0 commit comments