Skip to content

Commit

Permalink
Re-enable array theory as default for array size above threshold
Browse files Browse the repository at this point in the history
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 #6194 (inspired by #2108, but
not picking up all its changes), but then reverted the gist of the
change in #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`.
  • Loading branch information
tautschnig committed Sep 24, 2024
1 parent d2b4455 commit dc4157e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion regression/cbmc/array-bug-6230/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

struct inner
{
uint32_t exts[32]; // 32 is the minimum to crash
// 32 is the minimum to crash as it will produce an array wider than 1000 bits
// (the default value of MAX_FLATTENED_ARRAY_SIZE)
uint32_t exts[32];
};

struct outer
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/bounds_check1/test.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE thorough-smt-backend no-new-smt
main.c
--no-malloc-may-fail
--no-malloc-may-fail --arrays-uf-never
^EXIT=10$
^SIGNAL=0$
\[\(.*\)i2\]: FAILURE
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/union/union_large_array.desc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CORE thorough-smt-backend no-new-smt
union_large_array.c

--arrays-uf-never
^EXIT=10$
^SIGNAL=0$
^\[main\.assertion\.1\] line \d+ should fail: FAILURE$
Expand Down
27 changes: 18 additions & 9 deletions src/solvers/flattening/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,24 @@ void arrayst::collect_arrays(const exprt &a)
}
else if(a.id()==ID_member)
{
const auto &struct_op = to_member_expr(a).struct_op();
const exprt *struct_op_ptr = &to_member_expr(a).struct_op();
while(struct_op_ptr->id() == ID_member)
struct_op_ptr = &to_member_expr(*struct_op_ptr).struct_op();

DATA_INVARIANT(
struct_op.id() == ID_symbol || struct_op.id() == ID_nondet_symbol,
"unexpected array expression: member with '" + struct_op.id_string() +
"'");
if(struct_op_ptr->id() == ID_index)
{
const auto &array_op = to_index_expr(*struct_op_ptr).array();
arrays.make_union(a, array_op);
collect_arrays(array_op);

Check warning on line 207 in src/solvers/flattening/arrays.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/arrays.cpp#L205-L207

Added lines #L205 - L207 were not covered by tests
}
else

Check warning on line 209 in src/solvers/flattening/arrays.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/arrays.cpp#L209

Added line #L209 was not covered by tests
{
DATA_INVARIANT(
struct_op_ptr->id() == ID_struct || struct_op_ptr->id() == ID_symbol ||
struct_op_ptr->id() == ID_nondet_symbol,

Check warning on line 213 in src/solvers/flattening/arrays.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/arrays.cpp#L212-L213

Added lines #L212 - L213 were not covered by tests
"unexpected array expression: member with '" +
struct_op_ptr->id_string() + "'");

Check warning on line 215 in src/solvers/flattening/arrays.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/flattening/arrays.cpp#L215

Added line #L215 was not covered by tests
}
}
else if(a.is_constant() || a.id() == ID_array || a.id() == ID_string_constant)
{
Expand Down Expand Up @@ -497,10 +509,7 @@ void arrayst::add_array_constraints(
expr.id() == ID_string_constant)
{
}
else if(
expr.id() == ID_member &&
(to_member_expr(expr).struct_op().id() == ID_symbol ||
to_member_expr(expr).struct_op().id() == ID_nondet_symbol))
else if(expr.id() == ID_member)
{
}
else if(expr.id()==ID_byte_update_little_endian ||
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/flattening/boolbv.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class boolbvt:public arrayst
message_handlert &message_handler,
bool get_array_constraints = false)
: arrayst(_ns, _prop, message_handler, get_array_constraints),
unbounded_array(unbounded_arrayt::U_NONE),
unbounded_array(unbounded_arrayt::U_AUTO),
bv_width(_ns),
bv_utils(_prop),
functions(*this),
Expand Down

0 comments on commit dc4157e

Please sign in to comment.