@@ -1347,7 +1347,7 @@ void goto_checkt::bounds_check_index(
1347
1347
const index_exprt &expr,
1348
1348
const guardt &guard)
1349
1349
{
1350
- typet array_type = expr.array ().type ();
1350
+ const typet & array_type = expr.array ().type ();
1351
1351
1352
1352
if (array_type.id ()==ID_pointer)
1353
1353
throw " index got pointer as array type" ;
@@ -1382,9 +1382,10 @@ void goto_checkt::bounds_check_index(
1382
1382
{
1383
1383
exprt p_offset=pointer_offset (
1384
1384
to_dereference_expr (ode.root_object ()).pointer ());
1385
- assert (p_offset.type ()==effective_offset.type ());
1386
1385
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 ())};
1388
1389
}
1389
1390
1390
1391
exprt zero=from_integer (0 , ode.offset ().type ());
@@ -1404,26 +1405,21 @@ void goto_checkt::bounds_check_index(
1404
1405
}
1405
1406
}
1406
1407
1407
- exprt type_matches_size=true_exprt ();
1408
-
1409
1408
if (ode.root_object ().id ()==ID_dereference)
1410
1409
{
1411
1410
const exprt &pointer=
1412
1411
to_dereference_expr (ode.root_object ()).pointer ();
1413
1412
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 ())};
1425
1417
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 ())};
1427
1423
1428
1424
exprt in_bounds_of_some_explicit_allocation =
1429
1425
is_in_bounds_of_some_explicit_allocation (
@@ -1432,7 +1428,6 @@ void goto_checkt::bounds_check_index(
1432
1428
1433
1429
or_exprt precond (
1434
1430
std::move (in_bounds_of_some_explicit_allocation),
1435
- and_exprt (dynamic_object (pointer), not_exprt (malloc_object (pointer, ns))),
1436
1431
inequality);
1437
1432
1438
1433
add_guarded_property (
@@ -1443,25 +1438,7 @@ void goto_checkt::bounds_check_index(
1443
1438
expr,
1444
1439
guard);
1445
1440
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 ;
1465
1442
}
1466
1443
1467
1444
const exprt &size=array_type.id ()==ID_array ?
@@ -1497,7 +1474,7 @@ void goto_checkt::bounds_check_index(
1497
1474
type_size_opt.value ());
1498
1475
1499
1476
add_guarded_property (
1500
- implies_exprt (type_matches_size, inequality) ,
1477
+ inequality,
1501
1478
name + " upper bound" ,
1502
1479
" array bounds" ,
1503
1480
expr.find_source_location (),
@@ -1506,14 +1483,11 @@ void goto_checkt::bounds_check_index(
1506
1483
}
1507
1484
else
1508
1485
{
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};
1514
1488
1515
1489
add_guarded_property (
1516
- implies_exprt (type_matches_size, inequality) ,
1490
+ inequality,
1517
1491
name + " upper bound" ,
1518
1492
" array bounds" ,
1519
1493
expr.find_source_location (),
0 commit comments