Skip to content

Commit dc4157e

Browse files
committed
Re-enable array theory as default for array size above threshold
Previously, the command line permitted setting uninterpreted functions to "never" or "always", where "never" actually was the default. The "automatic" mode could not be enabled in any way. We previously attempted to do this in in diffblue#6194 (inspired by diffblue#2108, but not picking up all its changes), but then reverted the gist of the change in diffblue#6232 as `array-bug-6230/main.c` demonstrated lingering issues. This PR now addresses the flaw in the array theory back-end. We may still run into performance regressions as the threshold of 1000 bits of total size of the array object is possibly lower than where the cost of bit-blasting exceeds the cost of constraints produced by our current array theory implementation. Two of our existing regression tests already demonstrate this problem, hence those now use `--arrays-uf-never`.
1 parent d2b4455 commit dc4157e

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

regression/cbmc/array-bug-6230/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
struct inner
55
{
6-
uint32_t exts[32]; // 32 is the minimum to crash
6+
// 32 is the minimum to crash as it will produce an array wider than 1000 bits
7+
// (the default value of MAX_FLATTENED_ARRAY_SIZE)
8+
uint32_t exts[32];
79
};
810

911
struct outer

regression/cbmc/bounds_check1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE thorough-smt-backend no-new-smt
22
main.c
3-
--no-malloc-may-fail
3+
--no-malloc-may-fail --arrays-uf-never
44
^EXIT=10$
55
^SIGNAL=0$
66
\[\(.*\)i2\]: FAILURE

regression/cbmc/union/union_large_array.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE thorough-smt-backend no-new-smt
22
union_large_array.c
3-
3+
--arrays-uf-never
44
^EXIT=10$
55
^SIGNAL=0$
66
^\[main\.assertion\.1\] line \d+ should fail: FAILURE$

src/solvers/flattening/arrays.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,24 @@ void arrayst::collect_arrays(const exprt &a)
196196
}
197197
else if(a.id()==ID_member)
198198
{
199-
const auto &struct_op = to_member_expr(a).struct_op();
199+
const exprt *struct_op_ptr = &to_member_expr(a).struct_op();
200+
while(struct_op_ptr->id() == ID_member)
201+
struct_op_ptr = &to_member_expr(*struct_op_ptr).struct_op();
200202

201-
DATA_INVARIANT(
202-
struct_op.id() == ID_symbol || struct_op.id() == ID_nondet_symbol,
203-
"unexpected array expression: member with '" + struct_op.id_string() +
204-
"'");
203+
if(struct_op_ptr->id() == ID_index)
204+
{
205+
const auto &array_op = to_index_expr(*struct_op_ptr).array();
206+
arrays.make_union(a, array_op);
207+
collect_arrays(array_op);
208+
}
209+
else
210+
{
211+
DATA_INVARIANT(
212+
struct_op_ptr->id() == ID_struct || struct_op_ptr->id() == ID_symbol ||
213+
struct_op_ptr->id() == ID_nondet_symbol,
214+
"unexpected array expression: member with '" +
215+
struct_op_ptr->id_string() + "'");
216+
}
205217
}
206218
else if(a.is_constant() || a.id() == ID_array || a.id() == ID_string_constant)
207219
{
@@ -497,10 +509,7 @@ void arrayst::add_array_constraints(
497509
expr.id() == ID_string_constant)
498510
{
499511
}
500-
else if(
501-
expr.id() == ID_member &&
502-
(to_member_expr(expr).struct_op().id() == ID_symbol ||
503-
to_member_expr(expr).struct_op().id() == ID_nondet_symbol))
512+
else if(expr.id() == ID_member)
504513
{
505514
}
506515
else if(expr.id()==ID_byte_update_little_endian ||

src/solvers/flattening/boolbv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class boolbvt:public arrayst
5151
message_handlert &message_handler,
5252
bool get_array_constraints = false)
5353
: arrayst(_ns, _prop, message_handler, get_array_constraints),
54-
unbounded_array(unbounded_arrayt::U_NONE),
54+
unbounded_array(unbounded_arrayt::U_AUTO),
5555
bv_width(_ns),
5656
bv_utils(_prop),
5757
functions(*this),

0 commit comments

Comments
 (0)