Skip to content

Commit f67691e

Browse files
committed
Byte-operator lowering: do not unconditionally insert bv cast
In 848e633 a cast to bv was inserted to block interpreting floatbv type casts from taking place. It was unnecessarily inserted for all bitvector types. While this does not result in wrong semantics, it may block simplification for happening when we end up (via other simplifier rules) creating a bv (and not (un)signed bv) typed constant. All of these transformations are correct, but we may end up with an equality over pointer-typed constants where the underlying constant is a(n) (un)signed bv on one side, and a bv on the other side. The bit patterns match, so the back-end will correctly solve this, but the simplifier cannot. Observed when studying model-checking/kani#1978.
1 parent e024ecb commit f67691e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/util/lower_byte_operators.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,22 @@ static exprt bv_to_expr(
337337
{
338338
PRECONDITION(can_cast_type<bitvector_typet>(bitvector_expr.type()));
339339

340-
if(
341-
can_cast_type<bitvector_typet>(target_type) ||
342-
target_type.id() == ID_c_enum || target_type.id() == ID_c_enum_tag ||
343-
target_type.id() == ID_string)
340+
if(target_type.id() == ID_floatbv)
344341
{
345342
std::size_t width = to_bitvector_type(bitvector_expr.type()).get_width();
346343
exprt bv_expr =
347344
typecast_exprt::conditional_cast(bitvector_expr, bv_typet{width});
348345
return simplify_expr(
349346
typecast_exprt::conditional_cast(bv_expr, target_type), ns);
350347
}
348+
else if(
349+
can_cast_type<bitvector_typet>(target_type) ||
350+
target_type.id() == ID_c_enum || target_type.id() == ID_c_enum_tag ||
351+
target_type.id() == ID_string)
352+
{
353+
return simplify_expr(
354+
typecast_exprt::conditional_cast(bitvector_expr, target_type), ns);
355+
}
351356

352357
if(target_type.id() == ID_struct)
353358
{

0 commit comments

Comments
 (0)