@@ -69,6 +69,7 @@ class goto_checkt
69
69
void mod_by_zero_check (const mod_exprt &expr, const guardt &guard);
70
70
void undefined_shift_check (const shift_exprt &expr, const guardt &guard);
71
71
void pointer_rel_check (const exprt &expr, const guardt &guard);
72
+ void pointer_overflow_check (const exprt &expr, const guardt &guard);
72
73
void pointer_validity_check (const dereference_exprt &expr, const guardt &guard);
73
74
void integer_overflow_check (const exprt &expr, const guardt &guard);
74
75
void float_overflow_check (const exprt &expr, const guardt &guard);
@@ -855,8 +856,11 @@ void goto_checkt::pointer_rel_check(
855
856
const exprt &expr,
856
857
const guardt &guard)
857
858
{
859
+ if (!enable_pointer_check)
860
+ return ;
861
+
858
862
if (expr.operands ().size ()!=2 )
859
- throw expr.id_string ()+" takes one argument " ;
863
+ throw expr.id_string ()+" takes two arguments " ;
860
864
861
865
if (expr.op0 ().type ().id ()==ID_pointer &&
862
866
expr.op1 ().type ().id ()==ID_pointer)
@@ -880,6 +884,44 @@ void goto_checkt::pointer_rel_check(
880
884
881
885
/* ******************************************************************\
882
886
887
+ Function: goto_checkt::pointer_overflow_check
888
+
889
+ Inputs:
890
+
891
+ Outputs:
892
+
893
+ Purpose:
894
+
895
+ \*******************************************************************/
896
+
897
+ void goto_checkt::pointer_overflow_check (
898
+ const exprt &expr,
899
+ const guardt &guard)
900
+ {
901
+ if (!enable_pointer_check)
902
+ return ;
903
+
904
+ if (expr.id ()==ID_plus ||
905
+ expr.id ()==ID_minus)
906
+ {
907
+ if (expr.operands ().size ()==2 )
908
+ {
909
+ exprt overflow (" overflow-" +expr.id_string (), bool_typet ());
910
+ overflow.operands ()=expr.operands ();
911
+
912
+ add_guarded_claim (
913
+ not_exprt (overflow),
914
+ " pointer arithmetic overflow on " +expr.id_string (),
915
+ " overflow" ,
916
+ expr.find_source_location (),
917
+ expr,
918
+ guard);
919
+ }
920
+ }
921
+ }
922
+
923
+ /* ******************************************************************\
924
+
883
925
Function: goto_checkt::pointer_validity_check
884
926
885
927
Inputs:
@@ -1393,13 +1435,21 @@ void goto_checkt::check_rec(
1393
1435
if (expr.type ().id ()==ID_signedbv ||
1394
1436
expr.type ().id ()==ID_unsignedbv)
1395
1437
{
1396
- integer_overflow_check (expr, guard);
1438
+ if (expr.operands ().size ()==2 &&
1439
+ expr.op0 ().type ().id ()==ID_pointer)
1440
+ pointer_overflow_check (expr, guard);
1441
+ else
1442
+ integer_overflow_check (expr, guard);
1397
1443
}
1398
1444
else if (expr.type ().id ()==ID_floatbv)
1399
1445
{
1400
1446
nan_check (expr, guard);
1401
1447
float_overflow_check (expr, guard);
1402
1448
}
1449
+ else if (expr.type ().id ()==ID_pointer)
1450
+ {
1451
+ pointer_overflow_check (expr, guard);
1452
+ }
1403
1453
}
1404
1454
else if (expr.id ()==ID_le || expr.id ()==ID_lt ||
1405
1455
expr.id ()==ID_ge || expr.id ()==ID_gt)
0 commit comments