File: merge.cpp

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (178 lines) | stat: -rw-r--r-- 5,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*******************************************************************\

 Module: Unit tests for variable/sensitivity/abstract_object::merge

 Author: DiffBlue Limited.

\*******************************************************************/

#include <util/arith_tools.h>
#include <util/bitvector_types.h>
#include <util/namespace.h>
#include <util/symbol_table.h>

#include <analyses/variable-sensitivity/abstract_environment.h>
#include <analyses/variable-sensitivity/abstract_object.h>
#include <testing-utils/use_catch.h>

// NOLINTNEXTLINE(whitespace/line_length)
#include <analyses/variable-sensitivity/constant_abstract_value.h> // IWYU pragma: keep
#include <analyses/variable-sensitivity/variable_sensitivity_object_factory.h>
#include <analyses/variable-sensitivity/variable_sensitivity_test_helpers.h>

SCENARIO(
  "merge abstract object",
  "[core][analyses][variable-sensitivity][abstract_object][merge]")
{
  GIVEN("merging two abstract objects")
  {
    WHEN("merging TOP with TOP")
    {
      abstract_object_pointert op1 = make_top_object();
      abstract_object_pointert op2 = make_top_object();

      auto result = abstract_objectt::merge(op1, op2, widen_modet::no);

      THEN("result is unmodified TOP")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging TOP with BOTTOM")
    {
      abstract_object_pointert op1 = make_top_object();
      abstract_object_pointert op2 = make_bottom_object();

      auto result = abstract_objectt::merge(op1, op2, widen_modet::no);

      THEN("result is unmodified TOP")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging BOTTOM with TOP")
    {
      abstract_object_pointert op1 = make_bottom_object();
      abstract_object_pointert op2 = make_top_object();

      auto result = abstract_objectt::merge(op1, op2, widen_modet::no);

      THEN("result is modified TOP")
      {
        EXPECT_MODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging BOTTOM with BOTTOM")
    {
      abstract_object_pointert op1 = make_bottom_object();
      abstract_object_pointert op2 = make_bottom_object();

      auto result = abstract_objectt::merge(op1, op2, widen_modet::no);

      THEN("result is unmodified BOTTOM")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_BOTTOM(result);
      }
    }
  }

  GIVEN("an abstract object and a constant")
  {
    const typet type = signedbv_typet(32);
    const exprt val1 = from_integer(1, type);
    const exprt val2 = from_integer(2, type);

    auto config = vsd_configt::constant_domain();
    config.context_tracking.data_dependency_context = false;
    config.context_tracking.last_write_context = false;
    auto object_factory =
      variable_sensitivity_object_factoryt::configured_with(config);
    abstract_environmentt environment{object_factory};
    environment.make_top();
    symbol_tablet symbol_table;
    namespacet ns(symbol_table);

    WHEN("merging TOP with 1")
    {
      auto top1 = make_top_object();
      auto op2 = make_constant(val1, environment, ns);

      auto result = abstract_objectt::merge(top1, op2, widen_modet::no);

      THEN("the result is unmodified TOP")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging TOP with TOP constant")
    {
      auto top1 = make_top_object();
      auto top2 = make_top_constant();

      auto result = abstract_objectt::merge(top1, top2, widen_modet::no);

      THEN("the result is unmodified TOP")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging TOP with BOTTOM constant")
    {
      auto top1 = make_top_object();
      auto bottom2 = make_bottom_constant();

      auto result = abstract_objectt::merge(top1, bottom2, widen_modet::no);

      THEN("the result is unmodified TOP")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging BOTTOM with 1")
    {
      auto op1 = make_bottom_object();
      auto op2 = make_constant(val1, environment, ns);

      auto result = abstract_objectt::merge(op1, op2, widen_modet::no);

      THEN("the result is modified TOP")
      {
        EXPECT_MODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging BOTTOM with TOP constant")
    {
      auto op1 = make_bottom_object();
      auto top2 = make_top_constant();

      auto result = abstract_objectt::merge(op1, top2, widen_modet::no);

      THEN("the result is modified TOP")
      {
        EXPECT_MODIFIED(result);
        EXPECT_TOP(result);
      }
    }
    WHEN("merging BOTTOM with BOTTOM constant")
    {
      auto bottom1 = make_bottom_object();
      auto bottom2 = make_bottom_constant();

      auto result = abstract_objectt::merge(bottom1, bottom2, widen_modet::no);

      THEN("result is unmodified BOTTOM")
      {
        EXPECT_UNMODIFIED(result);
        EXPECT_BOTTOM(result);
      }
    }
  }
}