2020#include < util/base_type.h>
2121#include < util/pointer_predicates.h>
2222#include < util/cprover_prefix.h>
23+ #include < util/options.h>
2324
2425#include " local_bitvector_analysis.h"
2526#include " goto_check.h"
@@ -39,6 +40,8 @@ class goto_checkt
3940 enable_div_by_zero_check=_options.get_bool_option (" div-by-zero-check" );
4041 enable_signed_overflow_check=_options.get_bool_option (" signed-overflow-check" );
4142 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" );
4245 enable_undefined_shift_check=_options.get_bool_option (" undefined-shift-check" );
4346 enable_float_overflow_check=_options.get_bool_option (" float-overflow-check" );
4447 enable_simplify=_options.get_bool_option (" simplify" );
@@ -72,6 +75,7 @@ class goto_checkt
7275 void pointer_overflow_check (const exprt &expr, const guardt &guard);
7376 void pointer_validity_check (const dereference_exprt &expr, const guardt &guard);
7477 void integer_overflow_check (const exprt &expr, const guardt &guard);
78+ void conversion_check (const exprt &expr, const guardt &guard);
7579 void float_overflow_check (const exprt &expr, const guardt &guard);
7680 void nan_check (const exprt &expr, const guardt &guard);
7781
@@ -102,6 +106,8 @@ class goto_checkt
102106 bool enable_div_by_zero_check;
103107 bool enable_signed_overflow_check;
104108 bool enable_unsigned_overflow_check;
109+ bool enable_pointer_overflow_check;
110+ bool enable_conversion_check;
105111 bool enable_undefined_shift_check;
106112 bool enable_float_overflow_check;
107113 bool enable_simplify;
@@ -302,7 +308,7 @@ void goto_checkt::mod_by_zero_check(
302308
303309/* ******************************************************************\
304310
305- Function: goto_checkt::integer_overflow_check
311+ Function: goto_checkt::conversion_check
306312
307313 Inputs:
308314
@@ -312,25 +318,20 @@ Function: goto_checkt::integer_overflow_check
312318
313319\*******************************************************************/
314320
315- void goto_checkt::integer_overflow_check (
321+ void goto_checkt::conversion_check (
316322 const exprt &expr,
317323 const guardt &guard)
318324{
319- if (!enable_signed_overflow_check &&
320- !enable_unsigned_overflow_check)
325+ if (!enable_conversion_check)
321326 return ;
322327
323328 // First, check type.
324329 const typet &type=ns.follow (expr.type ());
325330
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)
330333 return ;
331334
332- // add overflow subgoal
333-
334335 if (expr.id ()==ID_typecast)
335336 {
336337 // conversion to signed int may overflow
@@ -490,10 +491,41 @@ void goto_checkt::integer_overflow_check(
490491 guard);
491492 }
492493 }
494+ }
495+ }
496+
497+ /* ******************************************************************\
498+
499+ Function: goto_checkt::integer_overflow_check
500+
501+ Inputs:
502+
503+ Outputs:
504+
505+ Purpose:
506+
507+ \*******************************************************************/
493508
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)
494515 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)
497529 {
498530 assert (expr.operands ().size ()==2 );
499531
@@ -898,7 +930,7 @@ void goto_checkt::pointer_overflow_check(
898930 const exprt &expr,
899931 const guardt &guard)
900932{
901- if (!enable_pointer_check )
933+ if (!enable_pointer_overflow_check )
902934 return ;
903935
904936 if (expr.id ()==ID_plus ||
@@ -1429,8 +1461,7 @@ void goto_checkt::check_rec(
14291461 }
14301462 else if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
14311463 expr.id ()==ID_mult ||
1432- expr.id ()==ID_unary_minus ||
1433- expr.id ()==ID_typecast)
1464+ expr.id ()==ID_unary_minus)
14341465 {
14351466 if (expr.type ().id ()==ID_signedbv ||
14361467 expr.type ().id ()==ID_unsignedbv)
@@ -1451,6 +1482,8 @@ void goto_checkt::check_rec(
14511482 pointer_overflow_check (expr, guard);
14521483 }
14531484 }
1485+ else if (expr.id ()==ID_typecast)
1486+ conversion_check (expr, guard);
14541487 else if (expr.id ()==ID_le || expr.id ()==ID_lt ||
14551488 expr.id ()==ID_ge || expr.id ()==ID_gt)
14561489 pointer_rel_check (expr, guard);
0 commit comments