20
20
#include < util/base_type.h>
21
21
#include < util/pointer_predicates.h>
22
22
#include < util/cprover_prefix.h>
23
+ #include < util/options.h>
23
24
24
25
#include " local_bitvector_analysis.h"
25
26
#include " goto_check.h"
@@ -39,6 +40,8 @@ class goto_checkt
39
40
enable_div_by_zero_check=_options.get_bool_option (" div-by-zero-check" );
40
41
enable_signed_overflow_check=_options.get_bool_option (" signed-overflow-check" );
41
42
enable_unsigned_overflow_check=_options.get_bool_option (" unsigned-overflow-check" );
43
+ enable_pointer_overflow_check=_options.get_bool_option (" pointer-overflow-check" );
44
+ enable_conversion_check=_options.get_bool_option (" conversion-check" );
42
45
enable_undefined_shift_check=_options.get_bool_option (" undefined-shift-check" );
43
46
enable_float_overflow_check=_options.get_bool_option (" float-overflow-check" );
44
47
enable_simplify=_options.get_bool_option (" simplify" );
@@ -72,6 +75,7 @@ class goto_checkt
72
75
void pointer_overflow_check (const exprt &expr, const guardt &guard);
73
76
void pointer_validity_check (const dereference_exprt &expr, const guardt &guard);
74
77
void integer_overflow_check (const exprt &expr, const guardt &guard);
78
+ void conversion_check (const exprt &expr, const guardt &guard);
75
79
void float_overflow_check (const exprt &expr, const guardt &guard);
76
80
void nan_check (const exprt &expr, const guardt &guard);
77
81
@@ -102,6 +106,8 @@ class goto_checkt
102
106
bool enable_div_by_zero_check;
103
107
bool enable_signed_overflow_check;
104
108
bool enable_unsigned_overflow_check;
109
+ bool enable_pointer_overflow_check;
110
+ bool enable_conversion_check;
105
111
bool enable_undefined_shift_check;
106
112
bool enable_float_overflow_check;
107
113
bool enable_simplify;
@@ -302,7 +308,7 @@ void goto_checkt::mod_by_zero_check(
302
308
303
309
/* ******************************************************************\
304
310
305
- Function: goto_checkt::integer_overflow_check
311
+ Function: goto_checkt::conversion_check
306
312
307
313
Inputs:
308
314
@@ -312,25 +318,20 @@ Function: goto_checkt::integer_overflow_check
312
318
313
319
\*******************************************************************/
314
320
315
- void goto_checkt::integer_overflow_check (
321
+ void goto_checkt::conversion_check (
316
322
const exprt &expr,
317
323
const guardt &guard)
318
324
{
319
- if (!enable_signed_overflow_check &&
320
- !enable_unsigned_overflow_check)
325
+ if (!enable_conversion_check)
321
326
return ;
322
327
323
328
// First, check type.
324
329
const typet &type=ns.follow (expr.type ());
325
330
326
- if (type.id ()==ID_signedbv && !enable_signed_overflow_check)
327
- return ;
328
-
329
- if (type.id ()==ID_unsignedbv && !enable_unsigned_overflow_check)
331
+ if (type.id ()!=ID_signedbv &&
332
+ type.id ()!=ID_unsignedbv)
330
333
return ;
331
334
332
- // add overflow subgoal
333
-
334
335
if (expr.id ()==ID_typecast)
335
336
{
336
337
// conversion to signed int may overflow
@@ -490,10 +491,41 @@ void goto_checkt::integer_overflow_check(
490
491
guard);
491
492
}
492
493
}
494
+ }
495
+ }
496
+
497
+ /* ******************************************************************\
498
+
499
+ Function: goto_checkt::integer_overflow_check
500
+
501
+ Inputs:
502
+
503
+ Outputs:
504
+
505
+ Purpose:
506
+
507
+ \*******************************************************************/
493
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)
494
515
return ;
495
- }
496
- 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)
497
529
{
498
530
assert (expr.operands ().size ()==2 );
499
531
@@ -898,7 +930,7 @@ void goto_checkt::pointer_overflow_check(
898
930
const exprt &expr,
899
931
const guardt &guard)
900
932
{
901
- if (!enable_pointer_check )
933
+ if (!enable_pointer_overflow_check )
902
934
return ;
903
935
904
936
if (expr.id ()==ID_plus ||
@@ -1429,8 +1461,7 @@ void goto_checkt::check_rec(
1429
1461
}
1430
1462
else if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
1431
1463
expr.id ()==ID_mult ||
1432
- expr.id ()==ID_unary_minus ||
1433
- expr.id ()==ID_typecast)
1464
+ expr.id ()==ID_unary_minus)
1434
1465
{
1435
1466
if (expr.type ().id ()==ID_signedbv ||
1436
1467
expr.type ().id ()==ID_unsignedbv)
@@ -1451,6 +1482,8 @@ void goto_checkt::check_rec(
1451
1482
pointer_overflow_check (expr, guard);
1452
1483
}
1453
1484
}
1485
+ else if (expr.id ()==ID_typecast)
1486
+ conversion_check (expr, guard);
1454
1487
else if (expr.id ()==ID_le || expr.id ()==ID_lt ||
1455
1488
expr.id ()==ID_ge || expr.id ()==ID_gt)
1456
1489
pointer_rel_check (expr, guard);
0 commit comments