|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Tests for constant_pointer_abstract_objectt::to_predicate |
| 4 | +
|
| 5 | + Author: Jez Higgins |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <analyses/variable-sensitivity/variable_sensitivity_object_factory.h> |
| 10 | +#include <analyses/variable-sensitivity/variable_sensitivity_test_helpers.h> |
| 11 | +#include <testing-utils/use_catch.h> |
| 12 | +#include <util/arith_tools.h> |
| 13 | +#include <util/bitvector_types.h> |
| 14 | +#include <util/pointer_expr.h> |
| 15 | + |
| 16 | +SCENARIO( |
| 17 | + "constant_pointer_abstract_object to predicate", |
| 18 | + "[core][analyses][variable-sensitivity][constant_pointer_abstract_object][to_" |
| 19 | + "predicate]") |
| 20 | +{ |
| 21 | + const auto int_type = signedbv_typet(32); |
| 22 | + const auto ptr_type = pointer_typet(int_type, 32); |
| 23 | + const auto val2_symbol = symbol_exprt(dstringt("val2"), int_type); |
| 24 | + |
| 25 | + const auto x_name = symbol_exprt(dstringt("x"), int_type); |
| 26 | + |
| 27 | + auto config = vsd_configt::constant_domain(); |
| 28 | + config.context_tracking.data_dependency_context = false; |
| 29 | + config.context_tracking.last_write_context = false; |
| 30 | + auto object_factory = |
| 31 | + variable_sensitivity_object_factoryt::configured_with(config); |
| 32 | + abstract_environmentt environment{object_factory}; |
| 33 | + environment.make_top(); |
| 34 | + symbol_tablet symbol_table; |
| 35 | + namespacet ns(symbol_table); |
| 36 | + |
| 37 | + GIVEN("constant_pointer_abstract_object") |
| 38 | + { |
| 39 | + WHEN("it is TOP") |
| 40 | + { |
| 41 | + auto obj = std::make_shared<constant_pointer_abstract_objectt>( |
| 42 | + ptr_type, true, false); |
| 43 | + THEN_PREDICATE(obj, "TRUE"); |
| 44 | + } |
| 45 | + WHEN("it is BOTTOM") |
| 46 | + { |
| 47 | + auto obj = std::make_shared<constant_pointer_abstract_objectt>( |
| 48 | + ptr_type, false, true); |
| 49 | + THEN_PREDICATE(obj, "FALSE"); |
| 50 | + } |
| 51 | + WHEN("points to a &symbol") |
| 52 | + { |
| 53 | + const auto address_of = address_of_exprt(val2_symbol); |
| 54 | + auto obj = std::make_shared<constant_pointer_abstract_objectt>( |
| 55 | + address_of, environment, ns); |
| 56 | + THEN_PREDICATE(obj, "x == &val2"); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments