@@ -88,18 +88,11 @@ 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
- let of_block = this. cfg . start_new_block ( ) ;
92
- let ok_block = this. cfg . start_new_block ( ) ;
93
-
94
- this. cfg . terminate ( block, scope_id, expr_span,
95
- TerminatorKind :: If {
96
- cond : Operand :: Consume ( is_min) ,
97
- targets : ( of_block, ok_block)
98
- } ) ;
99
-
100
- this. panic ( of_block, "attempted to negate with overflow" , expr_span) ;
101
-
102
- block = ok_block;
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
+ } ) ;
103
96
}
104
97
block. and ( Rvalue :: UnaryOp ( op, arg) )
105
98
}
@@ -271,21 +264,18 @@ impl<'a,'tcx> Builder<'a,'tcx> {
271
264
let val = result_value. clone ( ) . field ( val_fld, ty) ;
272
265
let of = result_value. field ( of_fld, bool_ty) ;
273
266
274
- let success = self . cfg . start_new_block ( ) ;
275
- let failure = self . cfg . start_new_block ( ) ;
276
-
277
- self . cfg . terminate ( block, scope_id, span,
278
- TerminatorKind :: If {
279
- cond : Operand :: Consume ( of) ,
280
- targets : ( failure, success)
281
- } ) ;
282
267
let msg = if op == BinOp :: Shl || op == BinOp :: Shr {
283
268
"shift operation overflowed"
284
269
} else {
285
270
"arithmetic operation overflowed"
286
271
} ;
287
- self . panic ( failure, msg, span) ;
288
- success. and ( Rvalue :: Use ( Operand :: Consume ( val) ) )
272
+
273
+ block = self . with_cond ( block, span, Operand :: Consume ( of) , |this, block| {
274
+ this. panic ( block, msg, span) ;
275
+ block
276
+ } ) ;
277
+
278
+ block. and ( Rvalue :: Use ( Operand :: Consume ( val) ) )
289
279
} else {
290
280
if ty. is_integral ( ) && ( op == BinOp :: Div || op == BinOp :: Rem ) {
291
281
// Checking division and remainder is more complex, since we 1. always check
@@ -305,17 +295,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
305
295
self . cfg . push_assign ( block, scope_id, span, & is_zero,
306
296
Rvalue :: BinaryOp ( BinOp :: Eq , rhs. clone ( ) , zero) ) ;
307
297
308
- let zero_block = self . cfg . start_new_block ( ) ;
309
- let ok_block = self . cfg . start_new_block ( ) ;
310
-
311
- self . cfg . terminate ( block, scope_id, span,
312
- TerminatorKind :: If {
313
- cond : Operand :: Consume ( is_zero) ,
314
- targets : ( zero_block, ok_block)
315
- } ) ;
316
-
317
- self . panic ( zero_block, zero_msg, span) ;
318
- block = ok_block;
298
+ block = self . with_cond ( block, span, Operand :: Consume ( is_zero) , |this, block| {
299
+ this. panic ( block, zero_msg, span) ;
300
+ block
301
+ } ) ;
319
302
320
303
// We only need to check for the overflow in one case:
321
304
// MIN / -1, and only for signed values.
@@ -339,18 +322,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
339
322
self . cfg . push_assign ( block, scope_id, span, & of,
340
323
Rvalue :: BinaryOp ( BinOp :: BitAnd , is_neg_1, is_min) ) ;
341
324
342
- let of_block = self . cfg . start_new_block ( ) ;
343
- let ok_block = self . cfg . start_new_block ( ) ;
344
-
345
- self . cfg . terminate ( block, scope_id, span,
346
- TerminatorKind :: If {
347
- cond : Operand :: Consume ( of) ,
348
- targets : ( of_block, ok_block)
349
- } ) ;
350
-
351
- self . panic ( of_block, overflow_msg, span) ;
352
-
353
- block = ok_block;
325
+ block = self . with_cond ( block, span, Operand :: Consume ( of) , |this, block| {
326
+ this. panic ( block, overflow_msg, span) ;
327
+ block
328
+ } ) ;
354
329
}
355
330
}
356
331
0 commit comments