Skip to content

Commit c3e5ba8

Browse files
authored
Merge pull request #8325 from diffblue/bool-is-mathematical
`__CPROVER_bool` should not have a memory layout
2 parents 17cff12 + 4bef423 commit c3e5ba8

File tree

8 files changed

+25
-115
lines changed

8 files changed

+25
-115
lines changed

regression/ansi-c/cprover_bool1/main.c

Lines changed: 0 additions & 50 deletions
This file was deleted.

regression/ansi-c/cprover_bool1/test.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.

regression/cpp/cprover_bool1/main.cpp

Lines changed: 0 additions & 12 deletions
This file was deleted.

regression/cpp/cprover_bool1/test.desc

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/ansi-c/library/cprover_contracts.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ __CPROVER_size_t __VERIFIER_nondet_size(void);
2424
typedef struct
2525
{
2626
/// \brief True iff __CPROVER_w_ok(lb, size) holds at creation
27-
__CPROVER_bool is_writable;
27+
unsigned char is_writable;
2828
/// \brief Size of the range in bytes
2929
__CPROVER_size_t size;
3030
/// \brief Lower bound address of the range
@@ -56,9 +56,9 @@ typedef struct
5656
/// \brief Number of elements currently in the elems array
5757
__CPROVER_size_t nof_elems;
5858
/// \brief True iff nof_elems is 0
59-
__CPROVER_bool is_empty;
59+
unsigned char is_empty;
6060
/// \brief True iff elems is indexed by the object id of the pointers
61-
__CPROVER_bool indexed_by_object_id;
61+
unsigned char indexed_by_object_id;
6262
/// \brief Array of void *pointers, indexed by their object ID
6363
/// or some other order
6464
void **elems;
@@ -90,17 +90,17 @@ typedef struct
9090
/// \brief Object set recording the deallocations (used by was_freed)
9191
__CPROVER_contracts_obj_set_ptr_t linked_deallocated;
9292
/// \brief True iff the write set checks requires clauses in an assumption ctx
93-
__CPROVER_bool assume_requires_ctx;
93+
unsigned char assume_requires_ctx;
9494
/// \brief True iff the write set checks requires clauses in an assertion ctx
95-
__CPROVER_bool assert_requires_ctx;
95+
unsigned char assert_requires_ctx;
9696
/// \brief True iff the write set checks ensures clauses in an assumption ctx
97-
__CPROVER_bool assume_ensures_ctx;
97+
unsigned char assume_ensures_ctx;
9898
/// \brief True iff this write set checks ensures clauses in an assertion ctx
99-
__CPROVER_bool assert_ensures_ctx;
99+
unsigned char assert_ensures_ctx;
100100
/// \brief True iff dynamic allocation is allowed (default: true)
101-
__CPROVER_bool allow_allocate;
101+
unsigned char allow_allocate;
102102
/// \brief True iff dynamic deallocation is allowed (default: true)
103-
__CPROVER_bool allow_deallocate;
103+
unsigned char allow_deallocate;
104104
} __CPROVER_contracts_write_set_t;
105105

106106
/// \brief Type of pointers to \ref __CPROVER_contracts_write_set_t.

src/util/pointer_expr.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ static void build_object_descriptor_rec(
3939
build_object_descriptor_rec(ns, index.array(), dest);
4040

4141
auto sub_size = size_of_expr(expr.type(), ns);
42-
CHECK_RETURN(sub_size.has_value());
4342

44-
dest.offset() = plus_exprt(
45-
dest.offset(),
46-
mult_exprt(
47-
typecast_exprt::conditional_cast(index.index(), c_index_type()),
48-
typecast_exprt::conditional_cast(sub_size.value(), c_index_type())));
43+
if(sub_size.has_value())
44+
{
45+
dest.offset() = plus_exprt(
46+
dest.offset(),
47+
mult_exprt(
48+
typecast_exprt::conditional_cast(index.index(), c_index_type()),
49+
typecast_exprt::conditional_cast(sub_size.value(), c_index_type())));
50+
}
51+
else
52+
{
53+
dest.offset() = exprt(ID_unknown);
54+
}
4955
}
5056
else if(expr.id() == ID_member)
5157
{

src/util/pointer_offset_size.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,6 @@ std::optional<exprt> size_of_expr(const typet &type, const namespacet &ns)
290290
{
291291
const auto &array_type = to_array_type(type);
292292

293-
// special-case arrays of bits
294-
if(array_type.element_type().id() == ID_bool)
295-
{
296-
auto bits = pointer_offset_bits(array_type, ns);
297-
298-
if(bits.has_value())
299-
return from_integer(
300-
(*bits + config.ansi_c.char_width - 1) / config.ansi_c.char_width,
301-
size_type());
302-
}
303-
304293
auto sub = size_of_expr(array_type.element_type(), ns);
305294
if(!sub.has_value())
306295
return {};
@@ -371,14 +360,6 @@ std::optional<exprt> size_of_expr(const typet &type, const namespacet &ns)
371360
if(bytes > 0)
372361
result = plus_exprt(result, from_integer(bytes, result.type()));
373362
}
374-
else if(c.is_boolean())
375-
{
376-
++bit_field_bits;
377-
const std::size_t bytes = bit_field_bits / config.ansi_c.char_width;
378-
bit_field_bits %= config.ansi_c.char_width;
379-
if(bytes > 0)
380-
result = plus_exprt(result, from_integer(bytes, result.type()));
381-
}
382363
else if(c.type().get_bool(ID_C_flexible_array_member))
383364
{
384365
// flexible array members do not change the sizeof result
@@ -476,7 +457,8 @@ std::optional<exprt> size_of_expr(const typet &type, const namespacet &ns)
476457
}
477458
else if(type.id()==ID_bool)
478459
{
479-
return from_integer(1, size_type());
460+
// bool is a mathematical type, and has no memory layout
461+
return {};
480462
}
481463
else if(type.id()==ID_pointer)
482464
{

unit/solvers/smt2_incremental/object_tracking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ TEST_CASE("Tracking dynamic object status.", "[core][smt2_incremental]")
220220
std::pair<decltype(base_object), decltype(expected_dynamic_status)>;
221221
std::tie(base_object, expected_dynamic_status) = GENERATE_REF(
222222
rowt{from_integer(0, unsignedbv_typet{(8)}), false},
223-
rowt{symbol_exprt{"foo", bool_typet{}}, false},
224-
rowt{symbol_exprt{SYMEX_DYNAMIC_PREFIX "bar", bool_typet{}}, true},
223+
rowt{symbol_exprt{"foo", unsignedbv_typet{8}}, false},
224+
rowt{symbol_exprt{SYMEX_DYNAMIC_PREFIX "bar", unsignedbv_typet{8}}, true},
225225
rowt{from_integer(42, make_type_dynamic(signedbv_typet{16})), true});
226226
INFO("base_object is - " + base_object.pretty(1, 0));
227227
track_expression_objects(address_of_exprt{base_object}, ns, object_map);

0 commit comments

Comments
 (0)