Skip to content

Commit 5a65118

Browse files
committed
Simplify array size expressions
Symbolic execution may be able to replace symbolic sizes by constants, but even the symbolic size might include a type cast (for examples, ones arising from uses of havoc_slice). Simplify those expressions to avoid appearance of almost-a-constant expressions.
1 parent d921808 commit 5a65118

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/util/simplify_expr.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,17 @@ bool simplify_exprt::simplify_node_preorder(exprt &expr)
27112711
}
27122712
}
27132713

2714+
if(as_const(expr).type().id() == ID_array)
2715+
{
2716+
const array_typet &array_type = to_array_type(as_const(expr).type());
2717+
resultt<> simp_size = simplify_rec(array_type.size());
2718+
if(simp_size.has_changed())
2719+
{
2720+
to_array_type(expr.type()).size() = simp_size.expr;
2721+
result = false;
2722+
}
2723+
}
2724+
27142725
return result;
27152726
}
27162727

@@ -3035,7 +3046,10 @@ simplify_exprt::resultt<> simplify_exprt::simplify_rec(const exprt &expr)
30353046
else // change, new expression is 'tmp'
30363047
{
30373048
POSTCONDITION_WITH_DIAGNOSTICS(
3038-
as_const(tmp).type() == expr.type(), tmp.pretty(), expr.pretty());
3049+
(as_const(tmp).type().id() == ID_array && expr.type().id() == ID_array) ||
3050+
as_const(tmp).type() == expr.type(),
3051+
tmp.pretty(),
3052+
expr.pretty());
30393053

30403054
#ifdef USE_CACHE
30413055
// save in cache

0 commit comments

Comments
 (0)