Skip to content

Commit a3d77e6

Browse files
committed
byte_extract lowering: ensure type consistency
Make sure we construct concatenations that are type consistent.
1 parent f4ed82a commit a3d77e6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/solvers/lowering/byte_operators.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,10 @@ exprt lower_byte_extract(const byte_extract_exprt &src, const namespacet &ns)
343343
return simplify_expr(typecast_exprt(op.front(), src.type()), ns);
344344
else // width_bytes>=2
345345
{
346-
concatenation_exprt concatenation(std::move(op), src.type());
347-
return simplify_expr(concatenation, ns);
346+
concatenation_exprt concatenation(
347+
std::move(op), bitvector_typet(subtype.id(), width_bytes * 8));
348+
return simplify_expr(
349+
typecast_exprt(std::move(concatenation), src.type()), ns);
348350
}
349351
}
350352

unit/solvers/lowering/byte_operators.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
104104
constant_exprt size = from_integer(8, size_type());
105105

106106
std::vector<typet> types = {
107-
// struct_typet({{"comp1", u16}, {"comp2", u16}}),
108-
// struct_typet({{"comp1", u32}, {"comp2", u64}}),
107+
struct_typet({{"comp1", u16}, {"comp2", u16}}),
108+
struct_typet({{"comp1", u32}, {"comp2", u64}}),
109109
#if 0
110110
// not currently handled: components not byte aligned
111111
struct_typet({{"comp1", u32},
@@ -114,8 +114,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
114114
{"comp2", u8}}),
115115
#endif
116116
// union_typet({{"compA", u32}, {"compB", u64}}),
117-
// c_enum_typet(u16),
118-
// c_enum_typet(unsignedbv_typet(128)),
117+
c_enum_typet(u16),
118+
c_enum_typet(unsignedbv_typet(128)),
119119
// array_typet(u8, size),
120120
// array_typet(s32, size),
121121
// array_typet(u64, size),
@@ -193,10 +193,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
193193
REQUIRE(!has_subexpr(lower_be, ID_byte_extract_little_endian));
194194
REQUIRE(!has_subexpr(lower_be, ID_byte_extract_big_endian));
195195
REQUIRE(lower_be.type() == be.type());
196-
// TODO: does not currently hold
197-
// REQUIRE(lower_be == r);
198-
// TODO: does not currently hold
199-
// REQUIRE(lower_be_s == r);
196+
REQUIRE(lower_be == r);
197+
REQUIRE(lower_be_s == r);
200198
}
201199
}
202200
}

0 commit comments

Comments
 (0)