@@ -41,6 +41,7 @@ class goto_checkt
41
41
enable_signed_overflow_check=_options.get_bool_option (" signed-overflow-check" );
42
42
enable_unsigned_overflow_check=_options.get_bool_option (" unsigned-overflow-check" );
43
43
enable_pointer_overflow_check=_options.get_bool_option (" pointer-overflow-check" );
44
+ enable_conversion_check=_options.get_bool_option (" conversion-check" );
44
45
enable_undefined_shift_check=_options.get_bool_option (" undefined-shift-check" );
45
46
enable_float_overflow_check=_options.get_bool_option (" float-overflow-check" );
46
47
enable_simplify=_options.get_bool_option (" simplify" );
@@ -74,6 +75,7 @@ class goto_checkt
74
75
void pointer_overflow_check (const exprt &expr, const guardt &guard);
75
76
void pointer_validity_check (const dereference_exprt &expr, const guardt &guard);
76
77
void integer_overflow_check (const exprt &expr, const guardt &guard);
78
+ void conversion_check (const exprt &expr, const guardt &guard);
77
79
void float_overflow_check (const exprt &expr, const guardt &guard);
78
80
void nan_check (const exprt &expr, const guardt &guard);
79
81
@@ -105,6 +107,7 @@ class goto_checkt
105
107
bool enable_signed_overflow_check;
106
108
bool enable_unsigned_overflow_check;
107
109
bool enable_pointer_overflow_check;
110
+ bool enable_conversion_check;
108
111
bool enable_undefined_shift_check;
109
112
bool enable_float_overflow_check;
110
113
bool enable_simplify;
@@ -305,7 +308,7 @@ void goto_checkt::mod_by_zero_check(
305
308
306
309
/* ******************************************************************\
307
310
308
- Function: goto_checkt::integer_overflow_check
311
+ Function: goto_checkt::conversion_check
309
312
310
313
Inputs:
311
314
@@ -315,25 +318,20 @@ Function: goto_checkt::integer_overflow_check
315
318
316
319
\*******************************************************************/
317
320
318
- void goto_checkt::integer_overflow_check (
321
+ void goto_checkt::conversion_check (
319
322
const exprt &expr,
320
323
const guardt &guard)
321
324
{
322
- if (!enable_signed_overflow_check &&
323
- !enable_unsigned_overflow_check)
325
+ if (!enable_conversion_check)
324
326
return ;
325
327
326
328
// First, check type.
327
329
const typet &type=ns.follow (expr.type ());
328
330
329
- if (type.id ()==ID_signedbv && !enable_signed_overflow_check)
330
- return ;
331
-
332
- if (type.id ()==ID_unsignedbv && !enable_unsigned_overflow_check)
331
+ if (type.id ()!=ID_signedbv &&
332
+ type.id ()!=ID_unsignedbv)
333
333
return ;
334
334
335
- // add overflow subgoal
336
-
337
335
if (expr.id ()==ID_typecast)
338
336
{
339
337
// conversion to signed int may overflow
@@ -493,10 +491,41 @@ void goto_checkt::integer_overflow_check(
493
491
guard);
494
492
}
495
493
}
494
+ }
495
+ }
496
496
497
+ /* ******************************************************************\
498
+
499
+ Function: goto_checkt::integer_overflow_check
500
+
501
+ Inputs:
502
+
503
+ Outputs:
504
+
505
+ Purpose:
506
+
507
+ \*******************************************************************/
508
+
509
+ void goto_checkt::integer_overflow_check (
510
+ const exprt &expr,
511
+ const guardt &guard)
512
+ {
513
+ if (!enable_signed_overflow_check &&
514
+ !enable_unsigned_overflow_check)
497
515
return ;
498
- }
499
- else if (expr.id ()==ID_div)
516
+
517
+ // First, check type.
518
+ const typet &type=ns.follow (expr.type ());
519
+
520
+ if (type.id ()==ID_signedbv && !enable_signed_overflow_check)
521
+ return ;
522
+
523
+ if (type.id ()==ID_unsignedbv && !enable_unsigned_overflow_check)
524
+ return ;
525
+
526
+ // add overflow subgoal
527
+
528
+ if (expr.id ()==ID_div)
500
529
{
501
530
assert (expr.operands ().size ()==2 );
502
531
@@ -1432,8 +1461,7 @@ void goto_checkt::check_rec(
1432
1461
}
1433
1462
else if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
1434
1463
expr.id ()==ID_mult ||
1435
- expr.id ()==ID_unary_minus ||
1436
- expr.id ()==ID_typecast)
1464
+ expr.id ()==ID_unary_minus)
1437
1465
{
1438
1466
if (expr.type ().id ()==ID_signedbv ||
1439
1467
expr.type ().id ()==ID_unsignedbv)
@@ -1454,6 +1482,8 @@ void goto_checkt::check_rec(
1454
1482
pointer_overflow_check (expr, guard);
1455
1483
}
1456
1484
}
1485
+ else if (expr.id ()==ID_typecast)
1486
+ conversion_check (expr, guard);
1457
1487
else if (expr.id ()==ID_le || expr.id ()==ID_lt ||
1458
1488
expr.id ()==ID_ge || expr.id ()==ID_gt)
1459
1489
pointer_rel_check (expr, guard);
0 commit comments