Skip to content

Commit 769f7a2

Browse files
committed
SMT2 back-end: ite-conversion must uphold type consistency
WITH expressions in an ite expression could previously trigger one-sided expression flattening.
1 parent 9a1df4b commit 769f7a2

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
typedef struct
2+
{
3+
int coeffs[1];
4+
} mld_poly;
5+
6+
typedef struct
7+
{
8+
mld_poly vec[1];
9+
} mld_polyveck;
10+
11+
int main()
12+
{
13+
mld_polyveck h;
14+
15+
// clang-format off
16+
for(unsigned int i = 0; i < 1; ++i)
17+
__CPROVER_loop_invariant(i <= 1)
18+
{
19+
h.vec[i].coeffs[0] = 1;
20+
}
21+
// clang-format on
22+
23+
return 0;
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--dfcc main --apply-loop-contracts _ --cprover-smt2
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Make sure the SMT back-end produces valid SMT2 when structs and arrays are
10+
nested in each other.

src/solvers/smt2/smt2_conv.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,35 @@ void smt2_convt::convert_expr(const exprt &expr)
14071407
out << "(ite ";
14081408
convert_expr(if_expr.cond());
14091409
out << " ";
1410-
convert_expr(if_expr.true_case());
1410+
if(
1411+
expr.type().id() == ID_array && !use_array_theory(if_expr.true_case()) &&
1412+
use_array_theory(if_expr.false_case()))
1413+
{
1414+
unflatten(wheret::BEGIN, expr.type());
1415+
1416+
convert_expr(if_expr.true_case());
1417+
1418+
unflatten(wheret::END, expr.type());
1419+
}
1420+
else
1421+
{
1422+
convert_expr(if_expr.true_case());
1423+
}
14111424
out << " ";
1412-
convert_expr(if_expr.false_case());
1425+
if(
1426+
expr.type().id() == ID_array && use_array_theory(if_expr.true_case()) &&
1427+
!use_array_theory(if_expr.false_case()))
1428+
{
1429+
unflatten(wheret::BEGIN, expr.type());
1430+
1431+
convert_expr(if_expr.false_case());
1432+
1433+
unflatten(wheret::END, expr.type());
1434+
}
1435+
else
1436+
{
1437+
convert_expr(if_expr.false_case());
1438+
}
14131439
out << ")";
14141440
}
14151441
else if(expr.id()==ID_and ||

0 commit comments

Comments
 (0)