|
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(
|
@@ -127,4 +128,55 @@ SCENARIO(
|
127 | 128 | }
|
128 | 129 | }
|
129 | 130 | }
|
| 131 | + |
| 132 | + GIVEN("A struct whose first element can only point to `&value1`") |
| 133 | + { |
| 134 | + // member is `struct_symbol.pointer_field` |
| 135 | + const member_exprt member = [&]() { |
| 136 | + std::vector<struct_typet::componentt> components; |
| 137 | + components.emplace_back("pointer_field", ptr_type); |
| 138 | + const struct_typet struct_type{components}; |
| 139 | + const symbol_exprt struct_symbol{"struct_symbol", struct_type}; |
| 140 | + add_to_symbol_table(symbol_table, struct_symbol); |
| 141 | + return member_exprt{struct_symbol, components.back()}; |
| 142 | + }(); |
| 143 | + |
| 144 | + value_sett value_set; |
| 145 | + const renamedt<exprt, L1> member_l1 = state.rename<L1>(member, ns); |
| 146 | + const renamedt<exprt, L1> address1_l1 = state.rename<L1>(address1, ns); |
| 147 | + |
| 148 | + // struct_symbol..pointer_field <- &value1 |
| 149 | + { |
| 150 | + field_sensitivityt field_sensitivity; |
| 151 | + const exprt index_fs = |
| 152 | + field_sensitivity.apply(ns, state, member_l1.get(), true); |
| 153 | + value_set.assign(index_fs, address1_l1.get(), ns, false, false); |
| 154 | + } |
| 155 | + |
| 156 | + WHEN("Evaluating struct_symbol.pointer_field == &value1") |
| 157 | + { |
| 158 | + const equal_exprt comparison{member, address1}; |
| 159 | + const renamedt<exprt, L2> renamed_comparison = |
| 160 | + state.rename(comparison, ns); |
| 161 | + auto result = try_evaluate_pointer_comparisons( |
| 162 | + renamed_comparison, value_set, ID_java, ns); |
| 163 | + THEN("Evaluation succeeds") |
| 164 | + { |
| 165 | + REQUIRE(result.get() == true_exprt{}); |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + WHEN("Evaluating struct_symbol.pointer_field == &value2") |
| 170 | + { |
| 171 | + const equal_exprt comparison{member, address2}; |
| 172 | + const renamedt<exprt, L2> renamed_comparison = |
| 173 | + state.rename(comparison, ns); |
| 174 | + auto result = try_evaluate_pointer_comparisons( |
| 175 | + renamed_comparison, value_set, ID_java, ns); |
| 176 | + THEN("Evaluation succeeds") |
| 177 | + { |
| 178 | + REQUIRE(result.get() == false_exprt{}); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
130 | 182 | }
|
0 commit comments