@@ -88,11 +88,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
88
88
this. cfg . push_assign ( block, scope_id, expr_span, & is_min,
89
89
Rvalue :: BinaryOp ( BinOp :: Eq , arg. clone ( ) , minval) ) ;
90
90
91
- block = this. with_cond (
92
- block, expr_span, Operand :: Consume ( is_min) , |this, block| {
93
- this. panic ( block, "attempted to negate with overflow" , expr_span) ;
94
- block
95
- } ) ;
91
+ let ( of_block, ok_block) = this. build_cond_br ( block, expr_span,
92
+ Operand :: Consume ( is_min) ) ;
93
+ this. panic ( of_block, "attempted to negate with overflow" , expr_span) ;
94
+ block = ok_block;
96
95
}
97
96
block. and ( Rvalue :: UnaryOp ( op, arg) )
98
97
}
@@ -246,7 +245,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
246
245
}
247
246
}
248
247
249
- pub fn build_binary_op ( & mut self , mut block : BasicBlock , op : BinOp , span : Span , ty : ty:: Ty < ' tcx > ,
248
+ pub fn build_binary_op ( & mut self , mut block : BasicBlock ,
249
+ op : BinOp , span : Span , ty : ty:: Ty < ' tcx > ,
250
250
lhs : Operand < ' tcx > , rhs : Operand < ' tcx > ) -> BlockAnd < Rvalue < ' tcx > > {
251
251
let scope_id = self . innermost_scope_id ( ) ;
252
252
let bool_ty = self . hir . bool_ty ( ) ;
@@ -270,12 +270,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
270
270
"arithmetic operation overflowed"
271
271
} ;
272
272
273
- block = self . with_cond ( block, span, Operand :: Consume ( of) , |this, block| {
274
- this. panic ( block, msg, span) ;
275
- block
276
- } ) ;
273
+ let ( of_block, ok_block) = self . build_cond_br ( block, span, Operand :: Consume ( of) ) ;
274
+ self . panic ( of_block, msg, span) ;
277
275
278
- block . and ( Rvalue :: Use ( Operand :: Consume ( val) ) )
276
+ ok_block . and ( Rvalue :: Use ( Operand :: Consume ( val) ) )
279
277
} else {
280
278
if ty. is_integral ( ) && ( op == BinOp :: Div || op == BinOp :: Rem ) {
281
279
// Checking division and remainder is more complex, since we 1. always check
@@ -295,10 +293,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
295
293
self . cfg . push_assign ( block, scope_id, span, & is_zero,
296
294
Rvalue :: BinaryOp ( BinOp :: Eq , rhs. clone ( ) , zero) ) ;
297
295
298
- block = self . with_cond ( block, span, Operand :: Consume ( is_zero) , |this, block| {
299
- this. panic ( block, zero_msg, span) ;
300
- block
301
- } ) ;
296
+ let ( zero_block, ok_block) = self . build_cond_br ( block, span,
297
+ Operand :: Consume ( is_zero) ) ;
298
+ self . panic ( zero_block, zero_msg, span) ;
299
+
300
+ block = ok_block;
302
301
303
302
// We only need to check for the overflow in one case:
304
303
// MIN / -1, and only for signed values.
@@ -322,10 +321,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
322
321
self . cfg . push_assign ( block, scope_id, span, & of,
323
322
Rvalue :: BinaryOp ( BinOp :: BitAnd , is_neg_1, is_min) ) ;
324
323
325
- block = self . with_cond ( block, span, Operand :: Consume ( of) , |this, block| {
326
- this. panic ( block, overflow_msg, span) ;
327
- block
328
- } ) ;
324
+ let ( of_block, ok_block) = self . build_cond_br ( block, span,
325
+ Operand :: Consume ( of) ) ;
326
+ self . panic ( of_block, overflow_msg, span) ;
327
+
328
+ block = ok_block;
329
329
}
330
330
}
331
331
0 commit comments