@@ -1347,7 +1347,7 @@ void goto_checkt::bounds_check_index(
13471347 const index_exprt &expr,
13481348 const guardt &guard)
13491349{
1350- typet array_type = expr.array ().type ();
1350+ const typet & array_type = expr.array ().type ();
13511351
13521352 if (array_type.id ()==ID_pointer)
13531353 throw " index got pointer as array type" ;
@@ -1382,9 +1382,10 @@ void goto_checkt::bounds_check_index(
13821382 {
13831383 exprt p_offset=pointer_offset (
13841384 to_dereference_expr (ode.root_object ()).pointer ());
1385- assert (p_offset.type ()==effective_offset.type ());
13861385
1387- effective_offset=plus_exprt (p_offset, effective_offset);
1386+ effective_offset = plus_exprt{p_offset,
1387+ typecast_exprt::conditional_cast (
1388+ effective_offset, p_offset.type ())};
13881389 }
13891390
13901391 exprt zero=from_integer (0 , ode.offset ().type ());
@@ -1404,26 +1405,21 @@ void goto_checkt::bounds_check_index(
14041405 }
14051406 }
14061407
1407- exprt type_matches_size=true_exprt ();
1408-
14091408 if (ode.root_object ().id ()==ID_dereference)
14101409 {
14111410 const exprt &pointer=
14121411 to_dereference_expr (ode.root_object ()).pointer ();
14131412
1414- const if_exprt size (
1415- dynamic_object (pointer),
1416- typecast_exprt (dynamic_size (ns), object_size (pointer).type ()),
1417- object_size (pointer));
1418-
1419- const plus_exprt effective_offset (ode.offset (), pointer_offset (pointer));
1420-
1421- assert (effective_offset.op0 ().type ()==effective_offset.op1 ().type ());
1422-
1423- const auto size_casted =
1424- typecast_exprt::conditional_cast (size, effective_offset.type ());
1413+ const plus_exprt effective_offset{
1414+ ode.offset (),
1415+ typecast_exprt::conditional_cast (
1416+ pointer_offset (pointer), ode.offset ().type ())};
14251417
1426- binary_relation_exprt inequality (effective_offset, ID_lt, size_casted);
1418+ binary_relation_exprt inequality{
1419+ effective_offset,
1420+ ID_lt,
1421+ typecast_exprt::conditional_cast (
1422+ object_size (pointer), effective_offset.type ())};
14271423
14281424 exprt in_bounds_of_some_explicit_allocation =
14291425 is_in_bounds_of_some_explicit_allocation (
@@ -1432,7 +1428,6 @@ void goto_checkt::bounds_check_index(
14321428
14331429 or_exprt precond (
14341430 std::move (in_bounds_of_some_explicit_allocation),
1435- and_exprt (dynamic_object (pointer), not_exprt (malloc_object (pointer, ns))),
14361431 inequality);
14371432
14381433 add_guarded_property (
@@ -1443,25 +1438,7 @@ void goto_checkt::bounds_check_index(
14431438 expr,
14441439 guard);
14451440
1446- auto type_size_opt = size_of_expr (ode.root_object ().type (), ns);
1447-
1448- if (type_size_opt.has_value ())
1449- {
1450- // Build a predicate that evaluates to true iff the size reported by
1451- // sizeof (i.e., compile-time size) matches the actual run-time size. The
1452- // run-time size for a dynamic (i.e., heap-allocated) object is determined
1453- // by the dynamic_size(ns) expression, which can only be used when
1454- // malloc_object(pointer, ns) evaluates to true for a given pointer.
1455- type_matches_size = if_exprt{
1456- dynamic_object (pointer),
1457- and_exprt{malloc_object (pointer, ns),
1458- equal_exprt{typecast_exprt::conditional_cast (
1459- dynamic_size (ns), type_size_opt->type ()),
1460- *type_size_opt}},
1461- equal_exprt{typecast_exprt::conditional_cast (
1462- object_size (pointer), type_size_opt->type ()),
1463- *type_size_opt}};
1464- }
1441+ return ;
14651442 }
14661443
14671444 const exprt &size=array_type.id ()==ID_array ?
@@ -1497,7 +1474,7 @@ void goto_checkt::bounds_check_index(
14971474 type_size_opt.value ());
14981475
14991476 add_guarded_property (
1500- implies_exprt (type_matches_size, inequality) ,
1477+ inequality,
15011478 name + " upper bound" ,
15021479 " array bounds" ,
15031480 expr.find_source_location (),
@@ -1506,14 +1483,11 @@ void goto_checkt::bounds_check_index(
15061483 }
15071484 else
15081485 {
1509- binary_relation_exprt inequality (index, ID_lt, size);
1510-
1511- // typecast size
1512- inequality.op1 () = typecast_exprt::conditional_cast (
1513- inequality.op1 (), inequality.op0 ().type ());
1486+ binary_relation_exprt inequality{
1487+ typecast_exprt::conditional_cast (index, size.type ()), ID_lt, size};
15141488
15151489 add_guarded_property (
1516- implies_exprt (type_matches_size, inequality) ,
1490+ inequality,
15171491 name + " upper bound" ,
15181492 " array bounds" ,
15191493 expr.find_source_location (),
0 commit comments