Skip to content

Commit 52b9097

Browse files
authored
Merge pull request #7299 from tautschnig/bugfixes/smt-union-flatten
SMT back-end: use_array_theory compatibility with unions
2 parents f71edea + babbd24 commit 52b9097

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

regression/cbmc/bounds_check1/test.desc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-z3-smt-backend
1+
CORE thorough-smt-backend
22
main.c
33
--bounds-check --pointer-check
44
^EXIT=10$
@@ -12,3 +12,6 @@ payload\[\(.*\)[kl]2\]: FAILURE
1212
\[\(.*\)i\]: FAILURE
1313
dest\[\(.*\)j\]: FAILURE
1414
payload\[\(.*\)[kl]\]: FAILURE
15+
--
16+
Appears to take Z3 more than 10 minutes to solve, and approximately 500 seconds
17+
when using the in-tree SMT solver.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-z3-smt-backend
1+
CORE
22
union_member.c
33

44
^EXIT=10$
@@ -8,6 +8,3 @@ union_member.c
88
^VERIFICATION FAILED$
99
--
1010
^warning: ignoring
11-
--
12-
This fails when using the SMT backend with Z3 with the error message
13-
"select requires 1 arguments, but was provided with 2 arguments"
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-z3-smt-backend
1+
CORE
22
union_update.c
33

44
^EXIT=10$
@@ -8,6 +8,3 @@ union_update.c
88
^VERIFICATION FAILED$
99
--
1010
^warning: ignoring
11-
--
12-
This fails when using the SMT backend with Z3 with the error message
13-
"store expects the first argument sort to be an array".

src/solvers/smt2/smt2_conv.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5459,20 +5459,18 @@ bool smt2_convt::use_array_theory(const exprt &expr)
54595459
const typet &type = expr.type();
54605460
PRECONDITION(type.id()==ID_array);
54615461

5462-
if(use_datatypes)
5462+
// a union is always flattened; else always use array theory when we have
5463+
// datatypes
5464+
if(expr.id() == ID_with)
5465+
return use_array_theory(to_with_expr(expr).old());
5466+
else if(auto member = expr_try_dynamic_cast<member_exprt>(expr))
54635467
{
5464-
return true; // always use array theory when we have datatypes
5468+
// arrays inside structs get flattened, unless we have datatypes
5469+
return use_datatypes && member->compound().type().id() != ID_union &&
5470+
member->compound().type().id() != ID_union_tag;
54655471
}
54665472
else
5467-
{
5468-
// arrays inside structs or unions get flattened
5469-
if(expr.id()==ID_with)
5470-
return use_array_theory(to_with_expr(expr).old());
5471-
else if(expr.id()==ID_member)
5472-
return false;
5473-
else
5474-
return true;
5475-
}
5473+
return true;
54765474
}
54775475

54785476
void smt2_convt::convert_type(const typet &type)

0 commit comments

Comments
 (0)