Skip to content

Commit 27dcf96

Browse files
committed
Do not simplify (T)bv-typed when T has smaller bit width
We must not modify the bit width of bv (and not signed/unsigned bv) typed expressions via type casts. Make sure simplification doesn't give rise to such expressions. Fixes: #7426
1 parent 8c18ecd commit 27dcf96

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/util/simplify_expr.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,20 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
13061306
// where T1 has fewer bits than T2
13071307
if(
13081308
op_type_id == expr_type_id &&
1309-
(expr_type_id == ID_unsignedbv || expr_type_id == ID_signedbv ||
1310-
expr_type_id == ID_bv) &&
1311-
to_bitvector_type(expr_type).get_width() <=
1309+
(expr_type_id == ID_unsignedbv || expr_type_id == ID_signedbv) &&
1310+
to_bitvector_type(expr_type).get_width() <
1311+
to_bitvector_type(operand.type()).get_width() &&
1312+
to_typecast_expr(operand).op().type().id() != ID_bv)
1313+
{
1314+
auto new_expr = expr;
1315+
new_expr.op() = to_typecast_expr(operand).op();
1316+
// might enable further simplification
1317+
return changed(simplify_typecast(new_expr)); // recursive call
1318+
}
1319+
else if(
1320+
op_type_id == ID_bv &&
1321+
(expr_type_id == ID_signedbv || expr_type_id == ID_unsignedbv) &&
1322+
to_bitvector_type(expr_type).get_width() ==
13121323
to_bitvector_type(operand.type()).get_width())
13131324
{
13141325
auto new_expr = expr;

0 commit comments

Comments
 (0)