Skip to content

Commit 8d314eb

Browse files
authored
Merge pull request #6484 from tautschnig/bits2expr-test
Extend unit test of bits2expr/expr2bits with struct type
2 parents 65cd7eb + 7b2dcad commit 8d314eb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

unit/util/simplify_expr.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ TEST_CASE("expr2bits and bits2expr respect bit order", "[core][util]")
108108
const auto should_be_deadbeef2 =
109109
bits2expr(*be, unsignedbv_typet(32), false, ns);
110110
REQUIRE(deadbeef == *should_be_deadbeef2);
111+
112+
c_bit_field_typet four_bits{unsignedbv_typet{8}, 4};
113+
struct_typet st{{{"s", unsignedbv_typet{16}},
114+
{"bf1", four_bits},
115+
{"bf2", four_bits},
116+
{"b", unsignedbv_typet{8}}}};
117+
118+
const auto fill_struct_le = bits2expr(*le, st, true, ns);
119+
REQUIRE(fill_struct_le.has_value());
120+
REQUIRE(
121+
to_struct_expr(*fill_struct_le).operands()[1] ==
122+
from_integer(0xd, four_bits));
123+
REQUIRE(
124+
to_struct_expr(*fill_struct_le).operands()[2] ==
125+
from_integer(0xa, four_bits));
126+
127+
const auto fill_struct_be = bits2expr(*be, st, false, ns);
128+
REQUIRE(fill_struct_be.has_value());
129+
REQUIRE(
130+
to_struct_expr(*fill_struct_be).operands()[1] ==
131+
from_integer(0xb, four_bits));
132+
REQUIRE(
133+
to_struct_expr(*fill_struct_be).operands()[2] ==
134+
from_integer(0xe, four_bits));
111135
}
112136

113137
TEST_CASE("Simplify extractbit", "[core][util]")

0 commit comments

Comments
 (0)