8
8
9
9
#include " simplify_expr.h"
10
10
11
- #include < cassert>
12
11
#include < algorithm>
13
12
14
13
#include " arith_tools.h"
19
18
#include " endianness_map.h"
20
19
#include " expr_util.h"
21
20
#include " fixedbv.h"
21
+ #include " invariant.h"
22
22
#include " namespace.h"
23
23
#include " pointer_offset_size.h"
24
24
#include " rational.h"
@@ -225,7 +225,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
225
225
inequality.add_source_location ()=expr.source_location ();
226
226
inequality.lhs ()=expr.op0 ();
227
227
inequality.rhs ()=from_integer (0 , op_type);
228
- assert (inequality.rhs ().is_not_nil ());
228
+ CHECK_RETURN (inequality.rhs ().is_not_nil ());
229
229
simplify_node (inequality);
230
230
expr.swap (inequality);
231
231
return false ;
@@ -260,7 +260,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
260
260
inequality.add_source_location ()=expr.source_location ();
261
261
inequality.lhs ()=expr.op0 ();
262
262
inequality.rhs ()=from_integer (0 , op_type);
263
- assert (inequality.rhs ().is_not_nil ());
263
+ CHECK_RETURN (inequality.rhs ().is_not_nil ());
264
264
simplify_node (inequality);
265
265
expr.op0 ()=inequality;
266
266
simplify_typecast (expr); // recursive call
@@ -488,13 +488,13 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
488
488
if (operand.is_true ())
489
489
{
490
490
expr=from_integer (1 , expr_type);
491
- assert (expr.is_not_nil ());
491
+ CHECK_RETURN (expr.is_not_nil ());
492
492
return false ;
493
493
}
494
494
else if (operand.is_false ())
495
495
{
496
496
expr=from_integer (0 , expr_type);
497
- assert (expr.is_not_nil ());
497
+ CHECK_RETURN (expr.is_not_nil ());
498
498
return false ;
499
499
}
500
500
}
@@ -1365,17 +1365,13 @@ bool simplify_exprt::simplify_update(exprt &expr)
1365
1365
{
1366
1366
const irep_idt &component_name=
1367
1367
e.get (ID_component_name);
1368
-
1369
- if (! to_struct_type (value_ptr_type).
1370
- has_component (component_name))
1368
+ const struct_typet &value_ptr_struct_type =
1369
+ to_struct_type (value_ptr_type);
1370
+ if (!value_ptr_struct_type. has_component (component_name))
1371
1371
return true ;
1372
-
1373
- std::size_t number=to_struct_type (value_ptr_type).
1374
- component_number (component_name);
1375
-
1376
- assert (number<value_ptr->operands ().size ());
1377
-
1378
- value_ptr=&value_ptr->operands ()[number];
1372
+ auto &designator_as_struct_expr = to_struct_expr (*value_ptr);
1373
+ value_ptr = &designator_as_struct_expr.component (component_name, ns);
1374
+ CHECK_RETURN (value_ptr->is_not_nil ());
1379
1375
}
1380
1376
else
1381
1377
return true ; // give up, unknown designator
@@ -1407,16 +1403,13 @@ bool simplify_exprt::simplify_object(exprt &expr)
1407
1403
}
1408
1404
else if (expr.id ()==ID_typecast)
1409
1405
{
1410
- const typet &op_type=ns.follow (expr.op0 ().type ());
1411
-
1412
- assert (expr.operands ().size ()==1 );
1406
+ auto const &typecast_expr = to_typecast_expr (expr);
1407
+ const typet &op_type = ns.follow (typecast_expr.op ().type ());
1413
1408
1414
1409
if (op_type.id ()==ID_pointer)
1415
1410
{
1416
1411
// cast from pointer to pointer
1417
- exprt tmp;
1418
- tmp.swap (expr.op0 ());
1419
- expr.swap (tmp);
1412
+ expr = typecast_expr.op ();
1420
1413
simplify_object (expr);
1421
1414
return false ;
1422
1415
}
@@ -1427,10 +1420,12 @@ bool simplify_exprt::simplify_object(exprt &expr)
1427
1420
// We do a bit of special treatment for (TYPE *)(a+(int)&o) and
1428
1421
// (TYPE *)(a+(int)((T*)&o+x)), which are re-written to '&o'.
1429
1422
1430
- exprt tmp=expr. op0 ();
1431
- if (tmp .id ()== ID_plus && tmp .operands ().size ()== 2 )
1423
+ const exprt &casted_expr = typecast_expr. op ();
1424
+ if (casted_expr .id () == ID_plus && casted_expr .operands ().size () == 2 )
1432
1425
{
1433
- exprt cand=tmp.op0 ().id ()==ID_typecast?tmp.op0 ():tmp.op1 ();
1426
+ const exprt &cand = casted_expr.op0 ().id () == ID_typecast ? casted_expr
1427
+ .op0 ()
1428
+ : casted_expr.op1 ();
1434
1429
1435
1430
if (cand.id ()==ID_typecast &&
1436
1431
cand.operands ().size ()==1 &&
@@ -1545,7 +1540,7 @@ exprt simplify_exprt::bits2expr(
1545
1540
for (const auto &component : components)
1546
1541
{
1547
1542
mp_integer m_size=pointer_offset_bits (component.type (), ns);
1548
- assert (m_size>= 0 );
1543
+ CHECK_RETURN (m_size >= 0 );
1549
1544
1550
1545
std::string comp_bits=
1551
1546
std::string (
@@ -1573,7 +1568,7 @@ exprt simplify_exprt::bits2expr(
1573
1568
1574
1569
std::size_t el_size=
1575
1570
integer2size_t (pointer_offset_bits (type.subtype (), ns));
1576
- assert (el_size> 0 );
1571
+ CHECK_RETURN (el_size > 0 );
1577
1572
1578
1573
array_exprt result (array_type);
1579
1574
result.reserve_operands (n_el);
@@ -1829,10 +1824,10 @@ bool simplify_exprt::simplify_byte_extract(byte_extract_exprt &expr)
1829
1824
op_type_ptr->id ()==ID_array;
1830
1825
op_type_ptr=&(ns.follow (*op_type_ptr).subtype ()))
1831
1826
{
1832
- // no arrays of zero-sized objects
1833
- assert (el_size> 0 );
1834
- // no arrays of non-byte sized objects
1835
- assert (el_size% 8 == 0 );
1827
+ DATA_INVARIANT (el_size > 0 , " arrays must not have zero-sized objects" );
1828
+ DATA_INVARIANT (
1829
+ el_size % 8 == 0 ,
1830
+ " array elements have a size in bits which is a multiple of bytes " );
1836
1831
mp_integer el_bytes=el_size/8 ;
1837
1832
1838
1833
if (base_type_eq (expr.type (), op_type_ptr->subtype (), ns) ||
0 commit comments