|
10 | 10 | #include <testing-utils/use_catch.h>
|
11 | 11 |
|
12 | 12 | #include <goto-symex/goto_symex.h>
|
| 13 | +#include <util/arith_tools.h> |
13 | 14 | #include <util/c_types.h>
|
14 | 15 |
|
15 | 16 | static void add_to_symbol_table(
|
@@ -123,4 +124,56 @@ SCENARIO("Try to evaluate pointer comparisons",
|
123 | 124 | }
|
124 | 125 | }
|
125 | 126 | }
|
| 127 | + |
| 128 | + GIVEN("A struct whose first element can only point to `&value1`") |
| 129 | + { |
| 130 | + // member is `struct_symbol.pointer_field` |
| 131 | + const member_exprt member = [&](){ |
| 132 | + std::vector<struct_typet::componentt> components; |
| 133 | + components.emplace_back("pointer_field", ptr_type); |
| 134 | + const struct_typet struct_type{components}; |
| 135 | + const symbol_exprt struct_symbol{"struct_symbol", struct_type}; |
| 136 | + add_to_symbol_table(symbol_table, struct_symbol); |
| 137 | + return member_exprt{struct_symbol, components.back()}; |
| 138 | + }(); |
| 139 | + |
| 140 | + value_sett value_set; |
| 141 | + const renamedt<exprt, L1> member_l1 = state.rename<L1>(member, ns); |
| 142 | + const renamedt<exprt, L1> address1_l1 = state.rename<L1>(address1, ns); |
| 143 | + |
| 144 | + // struct_symbol..pointer_field <- &value1 |
| 145 | + { |
| 146 | + field_sensitivityt field_sensitivity; |
| 147 | + const exprt index_fs = |
| 148 | + field_sensitivity.apply(ns, state, member_l1.get(), true); |
| 149 | + value_set.assign(index_fs, address1_l1.get(), ns, false, false); |
| 150 | + } |
| 151 | + |
| 152 | + WHEN("Evaluating struct_symbol.pointer_field == &value1") |
| 153 | + { |
| 154 | + const equal_exprt comparison{member, address1}; |
| 155 | + const renamedt<exprt, L2> renamed_comparison = |
| 156 | + state.rename(comparison, ns); |
| 157 | + auto result = try_evaluate_pointer_comparisons( |
| 158 | + renamed_comparison, value_set, ID_java, ns); |
| 159 | + THEN("Evaluation succeeds") |
| 160 | + { |
| 161 | + REQUIRE(result.get() == true_exprt{}); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + WHEN("Evaluating struct_symbol.pointer_field == &value2") |
| 166 | + { |
| 167 | + const equal_exprt comparison{member, address2}; |
| 168 | + const renamedt<exprt, L2> renamed_comparison = |
| 169 | + state.rename(comparison, ns); |
| 170 | + auto result = try_evaluate_pointer_comparisons( |
| 171 | + renamed_comparison, value_set, ID_java, ns); |
| 172 | + THEN("Evaluation succeeds") |
| 173 | + { |
| 174 | + REQUIRE(result.get() == false_exprt{}); |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + |
126 | 179 | }
|
0 commit comments