Skip to content

Commit 90842e5

Browse files
peterschrammelEnrico Steffinlongo
authored and
Enrico Steffinlongo
committed
Recanonicalize with_exprt when renaming old member
It may happen that during renaming the `old` subexpression of a `with_exprt` expression is propagated with a value that has an array type with a size that is a symbol with an L2 index that is different. In this case the type of the `with_exprt` will not match with the type of the `old` subexpression anymore. To address this issue we re-canonicalize the `with_exprt` by propagating the type of the `old` subexpression to the type of the `with_exprt`.
1 parent 99c5402 commit 90842e5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ goto_symex_statet::rename(exprt expr, const namespacet &ns)
263263
*it = rename<level>(std::move(*it), ns).get();
264264

265265
const exprt &c_expr = as_const(expr);
266+
267+
// It may happen that the `old` subexpression of a `with_exprt` expression
268+
// is propagated with a value that has an array type with a size that is a
269+
// symbol with an L2 index that is different. In this case the type of the
270+
// `with_exprt` will not match with the type of the `old` subexpression
271+
// anymore.
272+
// To address this issue we re-canonicalize the `with_exprt` by propagating
273+
// the type of the `old` subexpression to the type of the `with_exprt`.
274+
const auto *c_with_expr = expr_try_dynamic_cast<with_exprt>(c_expr);
275+
if(
276+
c_with_expr && can_cast_type<array_typet>(c_with_expr->type()) &&
277+
can_cast_type<array_typet>(c_with_expr->old().type()) &&
278+
c_with_expr->type() != c_with_expr->old().type())
279+
{
280+
expr.type() = to_with_expr(expr).old().type();
281+
}
266282
INVARIANT_WITH_DIAGNOSTICS(
267283
(expr.id() != ID_with ||
268284
c_expr.type() == to_with_expr(c_expr).old().type()) &&

0 commit comments

Comments
 (0)