@@ -1776,3 +1776,73 @@ TEST_CASE(
17761776 CHECK (test.convert (assignment) == expected);
17771777 }
17781778}
1779+
1780+ TEST_CASE (
1781+ " expr to smt conversion for bswap_exprt expressions" ,
1782+ " [core][smt2_incremental]" )
1783+ {
1784+ auto test =
1785+ expr_to_smt_conversion_test_environmentt::make (test_archt::x86_64);
1786+ SECTION (" 16-bit byte swap" )
1787+ {
1788+ const symbol_exprt operand{" my_value" , unsignedbv_typet{16 }};
1789+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{16 }};
1790+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1791+ const smt_identifier_termt operand_smt{" my_value" , smt_bit_vector_sortt{16 }};
1792+ // For 16-bit bswap, we extract [7:0] and [15:8], then concat in reverse order
1793+ // concat([7:0], [15:8]) puts [7:0] as most significant
1794+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1795+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1796+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt));
1797+ CHECK (test.convert (byte_swap) == expected);
1798+ }
1799+ SECTION (" 32-bit byte swap" )
1800+ {
1801+ const symbol_exprt operand{" my_value" , unsignedbv_typet{32 }};
1802+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{32 }};
1803+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1804+ const smt_identifier_termt operand_smt{" my_value" , smt_bit_vector_sortt{32 }};
1805+ // For 32-bit bswap, we extract 4 bytes and concat in reverse order
1806+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1807+ smt_bit_vector_theoryt::concat (
1808+ smt_bit_vector_theoryt::concat (
1809+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1810+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt)),
1811+ smt_bit_vector_theoryt::extract (23 , 16 )(operand_smt)),
1812+ smt_bit_vector_theoryt::extract (31 , 24 )(operand_smt));
1813+ CHECK (test.convert (byte_swap) == expected);
1814+ }
1815+ SECTION (" 64-bit byte swap" )
1816+ {
1817+ const symbol_exprt operand{" my_value" , unsignedbv_typet{64 }};
1818+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{64 }};
1819+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1820+ const smt_identifier_termt operand_smt{" my_value" , smt_bit_vector_sortt{64 }};
1821+ // For 64-bit bswap, we extract 8 bytes and concat in reverse order
1822+ const smt_termt expected = smt_bit_vector_theoryt::concat (
1823+ smt_bit_vector_theoryt::concat (
1824+ smt_bit_vector_theoryt::concat (
1825+ smt_bit_vector_theoryt::concat (
1826+ smt_bit_vector_theoryt::concat (
1827+ smt_bit_vector_theoryt::concat (
1828+ smt_bit_vector_theoryt::concat (
1829+ smt_bit_vector_theoryt::extract (7 , 0 )(operand_smt),
1830+ smt_bit_vector_theoryt::extract (15 , 8 )(operand_smt)),
1831+ smt_bit_vector_theoryt::extract (23 , 16 )(operand_smt)),
1832+ smt_bit_vector_theoryt::extract (31 , 24 )(operand_smt)),
1833+ smt_bit_vector_theoryt::extract (39 , 32 )(operand_smt)),
1834+ smt_bit_vector_theoryt::extract (47 , 40 )(operand_smt)),
1835+ smt_bit_vector_theoryt::extract (55 , 48 )(operand_smt)),
1836+ smt_bit_vector_theoryt::extract (63 , 56 )(operand_smt));
1837+ CHECK (test.convert (byte_swap) == expected);
1838+ }
1839+ SECTION (" Single byte (no swap needed)" )
1840+ {
1841+ const symbol_exprt operand{" my_value" , unsignedbv_typet{8 }};
1842+ const bswap_exprt byte_swap{operand, 8 , unsignedbv_typet{8 }};
1843+ INFO (" Expression being converted: " + byte_swap.pretty (2 , 0 ));
1844+ const smt_identifier_termt operand_smt{" my_value" , smt_bit_vector_sortt{8 }};
1845+ // Single byte should return operand unchanged
1846+ CHECK (test.convert (byte_swap) == operand_smt);
1847+ }
1848+ }
0 commit comments