Skip to content

Commit 1756460

Browse files
author
Enrico Steffinlongo
committed
Add test for duplicate_per_byte and simplification
1 parent 0ec5018 commit 1756460

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

unit/util/expr_initializer.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,50 @@ TEST_CASE(
241241
}
242242
}
243243

244+
TEST_CASE(
245+
"duplicate_per_byte calls simplify",
246+
"[core][util][duplicate_per_byte]")
247+
{
248+
auto test = expr_initializer_test_environmentt::make();
249+
// elements are init_expr, expected_value
250+
using rowt = std::tuple<exprt, std::size_t>;
251+
exprt init_expr;
252+
std::size_t expected_value;
253+
std::tie(init_expr, expected_value) = GENERATE(
254+
rowt{
255+
from_integer(0xAB, char_type()), 0xABAB}, // char type, no simplification
256+
rowt{
257+
typecast_exprt::conditional_cast(
258+
from_integer(0xAAB, unsignedbv_typet{24}), char_type()),
259+
0xABAB}, // cast to smaller type (truncating
260+
rowt{
261+
typecast_exprt::conditional_cast(
262+
from_integer(0xA, unsignedbv_typet{4}), unsignedbv_typet(8)),
263+
0x0A0A}, // cast to bigger type (zero-extended)
264+
rowt{
265+
plus_exprt{
266+
from_integer(0x0B, char_type()), from_integer(0xA0, char_type())},
267+
0xABAB}, // arithmetic operation on char type
268+
rowt{
269+
typecast_exprt::conditional_cast(
270+
plus_exprt{
271+
from_integer(0x0B, unsignedbv_typet{24}),
272+
from_integer(0xAA0, unsignedbv_typet(24))},
273+
char_type()),
274+
0xABAB}); // arithmetic operation with narrowing cast to char type
275+
276+
SECTION("Testing with expression")
277+
{
278+
const auto output_type = unsignedbv_typet{config.ansi_c.char_width * 2};
279+
280+
const auto result = duplicate_per_byte(init_expr, output_type, test.ns);
281+
282+
const auto expected = from_integer(expected_value, output_type);
283+
284+
REQUIRE(result == expected);
285+
}
286+
}
287+
244288
TEST_CASE(
245289
"duplicate_per_byte on unsigned_bv with non-constant expr",
246290
"[core][util][duplicate_per_byte]")

0 commit comments

Comments
 (0)