@@ -1590,3 +1590,62 @@ TEST_CASE(
1590
1590
smt_bit_vector_theoryt::extract (63 , 64 - object_bits)(
1591
1591
smt_bit_vector_theoryt::concat (object, offset))}));
1592
1592
}
1593
+
1594
+ TEST_CASE (
1595
+ " lower_address_of_array_index works correctly" ,
1596
+ " [core][smt2_incremental]" )
1597
+ {
1598
+ auto test =
1599
+ expr_to_smt_conversion_test_environmentt::make (test_archt::x86_64);
1600
+ const symbol_tablet symbol_table;
1601
+ const namespacet ns{symbol_table};
1602
+ const typet value_type = signedbv_typet{8 };
1603
+ const exprt array = symbol_exprt{
1604
+ " my_array" , array_typet{value_type, from_integer (10 , signed_size_type ())}};
1605
+ const exprt index = from_integer (42 , unsignedbv_typet{64 });
1606
+ const index_exprt index_expr{array, index};
1607
+ const address_of_exprt address_of_expr{index_expr};
1608
+ const plus_exprt lowered{
1609
+ address_of_exprt{
1610
+ array, type_checked_cast<pointer_typet>(address_of_expr.type ())},
1611
+ index};
1612
+ SECTION (" Lowering address_of(array[idx])" )
1613
+ {
1614
+ CHECK (lower_address_of_array_index (address_of_expr) == lowered);
1615
+ }
1616
+ SECTION (" Lowering expression containing address_of(array[idx])" )
1617
+ {
1618
+ const symbol_exprt symbol{" a_symbol" , address_of_expr.type ()};
1619
+ const equal_exprt assignment{symbol, address_of_expr};
1620
+ const equal_exprt expected{symbol, lowered};
1621
+ CHECK (lower_address_of_array_index (assignment) == expected);
1622
+ }
1623
+ SECTION (" Lowering does not lower other expressions" )
1624
+ {
1625
+ const symbol_exprt symbol{" a_symbol" , index_expr.type ()};
1626
+ const equal_exprt assignment{symbol, index_expr};
1627
+ CHECK (lower_address_of_array_index (assignment) == assignment);
1628
+ }
1629
+ SECTION (" Lowering is done during convert_to_smt" )
1630
+ {
1631
+ const symbol_exprt symbol{" a_symbol" , address_of_expr.type ()};
1632
+ const equal_exprt assignment{symbol, address_of_expr};
1633
+ track_expression_objects (assignment, ns, test.object_map );
1634
+ associate_pointer_sizes (
1635
+ assignment,
1636
+ ns,
1637
+ test.pointer_sizes ,
1638
+ test.object_map ,
1639
+ test.object_size_function .make_application );
1640
+ const smt_termt expected = smt_core_theoryt::equal (
1641
+ smt_identifier_termt (symbol.get_identifier (), smt_bit_vector_sortt{64 }),
1642
+ smt_bit_vector_theoryt::add (
1643
+ smt_bit_vector_theoryt::concat (
1644
+ smt_bit_vector_constant_termt{2 , 8 },
1645
+ smt_bit_vector_constant_termt{0 , 56 }),
1646
+ smt_bit_vector_theoryt::multiply (
1647
+ smt_bit_vector_constant_termt{42 , 64 },
1648
+ smt_bit_vector_constant_termt{1 , 64 })));
1649
+ CHECK (test.convert (assignment) == expected);
1650
+ }
1651
+ }
0 commit comments