Skip to content

Commit 660a11b

Browse files
committed
byte_extract lowering: ensure type consistency
Make sure we construct concatenations that are type consistent.
1 parent 31ff67a commit 660a11b

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
@@ -76,8 +76,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
7676
constant_exprt size = from_integer(8, size_type());
7777

7878
std::vector<typet> types = {
79-
// struct_typet({{"comp1", u16}, {"comp2", u16}}),
80-
// struct_typet({{"comp1", u32}, {"comp2", u64}}),
79+
struct_typet({{"comp1", u16}, {"comp2", u16}}),
80+
struct_typet({{"comp1", u32}, {"comp2", u64}}),
8181
#if 0
8282
// not currently handled: components not byte aligned
8383
struct_typet({{"comp1", u32},
@@ -86,8 +86,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
8686
{"comp2", u8}}),
8787
#endif
8888
// union_typet({{"compA", u32}, {"compB", u64}}),
89-
// c_enum_typet(u16),
90-
// c_enum_typet(unsignedbv_typet(128)),
89+
c_enum_typet(u16),
90+
c_enum_typet(unsignedbv_typet(128)),
9191
// array_typet(u8, size),
9292
// array_typet(s32, size),
9393
// array_typet(u64, size),
@@ -157,10 +157,8 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
157157
// TODO: does not currently hold
158158
// REQUIRE(!has_subexpr(lower_be, ID_byte_extract_little_endian));
159159
REQUIRE(lower_be.type() == be.type());
160-
// TODO: does not currently hold
161-
// REQUIRE(lower_be == r);
162-
// TODO: does not currently hold
163-
// REQUIRE(lower_be_s == r);
160+
REQUIRE(lower_be == r);
161+
REQUIRE(lower_be_s == r);
164162
}
165163
}
166164
}

0 commit comments

Comments
 (0)