|
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 | }
|
@@ -1373,7 +1373,7 @@ bool simplify_exprt::simplify_update(exprt &expr)
|
1373 | 1373 | std::size_t number=to_struct_type(value_ptr_type).
|
1374 | 1374 | component_number(component_name);
|
1375 | 1375 |
|
1376 |
| - assert(number<value_ptr->operands().size()); |
| 1376 | + CHECK_RETURN(number < value_ptr->operands().size()); |
1377 | 1377 |
|
1378 | 1378 | value_ptr=&value_ptr->operands()[number];
|
1379 | 1379 | }
|
@@ -1409,7 +1409,9 @@ bool simplify_exprt::simplify_object(exprt &expr)
|
1409 | 1409 | {
|
1410 | 1410 | const typet &op_type=ns.follow(expr.op0().type());
|
1411 | 1411 |
|
1412 |
| - assert(expr.operands().size()==1); |
| 1412 | + DATA_INVARIANT( |
| 1413 | + expr.operands().size() == 1, |
| 1414 | + "typecasts must have exactly one argument"); |
1413 | 1415 |
|
1414 | 1416 | if(op_type.id()==ID_pointer)
|
1415 | 1417 | {
|
@@ -1545,7 +1547,7 @@ exprt simplify_exprt::bits2expr(
|
1545 | 1547 | for(const auto &component : components)
|
1546 | 1548 | {
|
1547 | 1549 | mp_integer m_size=pointer_offset_bits(component.type(), ns);
|
1548 |
| - assert(m_size>=0); |
| 1550 | + CHECK_RETURN(m_size >= 0); |
1549 | 1551 |
|
1550 | 1552 | std::string comp_bits=
|
1551 | 1553 | std::string(
|
@@ -1573,7 +1575,7 @@ exprt simplify_exprt::bits2expr(
|
1573 | 1575 |
|
1574 | 1576 | std::size_t el_size=
|
1575 | 1577 | integer2size_t(pointer_offset_bits(type.subtype(), ns));
|
1576 |
| - assert(el_size>0); |
| 1578 | + CHECK_RETURN(el_size > 0); |
1577 | 1579 |
|
1578 | 1580 | array_exprt result(array_type);
|
1579 | 1581 | result.reserve_operands(n_el);
|
@@ -1829,10 +1831,10 @@ bool simplify_exprt::simplify_byte_extract(byte_extract_exprt &expr)
|
1829 | 1831 | op_type_ptr->id()==ID_array;
|
1830 | 1832 | op_type_ptr=&(ns.follow(*op_type_ptr).subtype()))
|
1831 | 1833 | {
|
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); |
| 1834 | + DATA_INVARIANT(el_size > 0, "arrays must not have zero-sized objects"); |
| 1835 | + DATA_INVARIANT( |
| 1836 | + el_size % 8 == 0, |
| 1837 | + "array elements have a size in bits which is a multiple of bytes"); |
1836 | 1838 | mp_integer el_bytes=el_size/8;
|
1837 | 1839 |
|
1838 | 1840 | if(base_type_eq(expr.type(), op_type_ptr->subtype(), ns) ||
|
|
0 commit comments