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