Skip to content

Commit a6a0729

Browse files
authored
Merge pull request #5755 from jezhiggins/vsd-merge-and-eval
VSD: Simplifying abstract_objectt::write, collapsing inheritance hierarchy
2 parents cf40d22 + d9f7b72 commit a6a0729

File tree

58 files changed

+1569
-1915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1569
-1915
lines changed

scripts/expected_doxygen_warnings.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:232: warning: no matching class member found for
1+
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:246: warning: no matching class member found for
22
template
33
satcheck_glucose_baset< Glucose::Solver >::~satcheck_glucose_baset()
44

5-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:238: warning: no matching class member found for
5+
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_glucose.cpp:252: warning: no matching class member found for
66
template
77
satcheck_glucose_baset< Glucose::SimpSolver >::~satcheck_glucose_baset()
88

9-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_minisat2.cpp:312: warning: no matching class member found for
9+
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_minisat2.cpp:313: warning: no matching class member found for
1010
template
1111
satcheck_minisat2_baset< Minisat::Solver >::~satcheck_minisat2_baset()
1212

13-
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_minisat2.cpp:318: warning: no matching class member found for
13+
/home/runner/work/cbmc/cbmc/src/solvers/sat/satcheck_minisat2.cpp:319: warning: no matching class member found for
1414
template
1515
satcheck_minisat2_baset< Minisat::SimpSolver >::~satcheck_minisat2_baset()
1616

@@ -87,16 +87,16 @@ warning: Included by graph for 'arith_tools.h' not generated, too many nodes (18
8787
warning: Included by graph for 'c_types.h' not generated, too many nodes (111), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8888
warning: Included by graph for 'config.h' not generated, too many nodes (85), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
8989
warning: Included by graph for 'exception_utils.h' not generated, too many nodes (61), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
90-
warning: Included by graph for 'expr.h' not generated, too many nodes (88), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
90+
warning: Included by graph for 'expr.h' not generated, too many nodes (87), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9191
warning: Included by graph for 'expr_util.h' not generated, too many nodes (61), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9292
warning: Included by graph for 'invariant.h' not generated, too many nodes (187), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9393
warning: Included by graph for 'irep.h' not generated, too many nodes (62), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9494
warning: Included by graph for 'message.h' not generated, too many nodes (116), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
95-
warning: Included by graph for 'namespace.h' not generated, too many nodes (113), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
95+
warning: Included by graph for 'namespace.h' not generated, too many nodes (110), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9696
warning: Included by graph for 'pointer_expr.h' not generated, too many nodes (101), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9797
warning: Included by graph for 'prefix.h' not generated, too many nodes (86), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9898
warning: Included by graph for 'simplify_expr.h' not generated, too many nodes (77), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
9999
warning: Included by graph for 'std_code.h' not generated, too many nodes (78), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
100-
warning: Included by graph for 'std_expr.h' not generated, too many nodes (248), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
101-
warning: Included by graph for 'std_types.h' not generated, too many nodes (124), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
100+
warning: Included by graph for 'std_expr.h' not generated, too many nodes (245), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
101+
warning: Included by graph for 'std_types.h' not generated, too many nodes (122), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.
102102
warning: Included by graph for 'symbol_table.h' not generated, too many nodes (95), threshold is 60. Consider increasing DOT_GRAPH_MAX_NODES.

src/analyses/Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,26 @@ SRC = ai.cpp \
3434
uncaught_exceptions_analysis.cpp \
3535
uninitialized_domain.cpp \
3636
variable-sensitivity/abstract_object.cpp \
37-
variable-sensitivity/abstract_enviroment.cpp \
38-
variable-sensitivity/abstract_value.cpp \
39-
variable-sensitivity/array_abstract_object.cpp \
37+
variable-sensitivity/abstract_environment.cpp \
38+
variable-sensitivity/abstract_value_object.cpp \
4039
variable-sensitivity/constant_abstract_value.cpp \
4140
variable-sensitivity/constant_pointer_abstract_object.cpp \
4241
variable-sensitivity/context_abstract_object.cpp \
4342
variable-sensitivity/write_location_context.cpp \
4443
variable-sensitivity/pointer_abstract_object.cpp \
45-
variable-sensitivity/struct_abstract_object.cpp \
4644
variable-sensitivity/variable_sensitivity_domain.cpp \
4745
variable-sensitivity/variable_sensitivity_object_factory.cpp \
4846
variable-sensitivity/full_struct_abstract_object.cpp \
49-
variable-sensitivity/constant_array_abstract_object.cpp \
50-
variable-sensitivity/union_abstract_object.cpp \
47+
variable-sensitivity/full_array_abstract_object.cpp \
5148
variable-sensitivity/write_stack.cpp \
5249
variable-sensitivity/write_stack_entry.cpp \
5350
variable-sensitivity/data_dependency_context.cpp \
5451
variable-sensitivity/value_set_abstract_object.cpp \
5552
variable-sensitivity/variable_sensitivity_dependence_graph.cpp \
5653
variable-sensitivity/interval_abstract_value.cpp \
57-
variable-sensitivity/interval_array_abstract_object.cpp \
5854
variable-sensitivity/value_set_abstract_object.cpp \
5955
variable-sensitivity/value_set_abstract_value.cpp \
6056
variable-sensitivity/value_set_pointer_abstract_object.cpp \
61-
variable-sensitivity/value_set_array_abstract_object.cpp \
6257
variable-sensitivity/three_way_merge_abstract_interpreter.cpp \
6358
variable-sensitivity/variable_sensitivity_configuration.cpp \
6459
# Empty last line
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*******************************************************************\
2+
3+
Module: analyses variable-sensitivity
4+
5+
Author: Jez Higgins, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Common behaviour for abstract objects modelling aggregate values -
11+
/// arrays, structs, etc.
12+
#ifndef CBMC_ABSTRACT_AGGREGATE_OBJECT_H
13+
#define CBMC_ABSTRACT_AGGREGATE_OBJECT_H
14+
15+
#include <analyses/variable-sensitivity/abstract_environment.h>
16+
#include <analyses/variable-sensitivity/abstract_object.h>
17+
#include <stack>
18+
19+
class abstract_aggregate_tag
20+
{
21+
};
22+
23+
template <class aggregate_typet, class aggregate_traitst>
24+
class abstract_aggregate_objectt : public abstract_objectt,
25+
public abstract_aggregate_tag
26+
{
27+
public:
28+
explicit abstract_aggregate_objectt(const typet &type)
29+
: abstract_objectt(type)
30+
{
31+
PRECONDITION(type.id() == aggregate_traitst::TYPE_ID());
32+
}
33+
34+
abstract_aggregate_objectt(const typet &type, bool tp, bool bttm)
35+
: abstract_objectt(type, tp, bttm)
36+
{
37+
PRECONDITION(type.id() == aggregate_traitst::TYPE_ID());
38+
}
39+
40+
abstract_aggregate_objectt(
41+
const exprt &expr,
42+
const abstract_environmentt &environment,
43+
const namespacet &ns)
44+
: abstract_objectt(expr, environment, ns)
45+
{
46+
PRECONDITION(ns.follow(expr.type()).id() == aggregate_traitst::TYPE_ID());
47+
}
48+
49+
abstract_object_pointert expression_transform(
50+
const exprt &expr,
51+
const std::vector<abstract_object_pointert> &operands,
52+
const abstract_environmentt &environment,
53+
const namespacet &ns) const override
54+
{
55+
if(expr.id() == aggregate_traitst::ACCESS_EXPR_ID())
56+
return read_component(environment, expr, ns);
57+
58+
return abstract_objectt::expression_transform(
59+
expr, operands, environment, ns);
60+
}
61+
62+
abstract_object_pointert write(
63+
abstract_environmentt &environment,
64+
const namespacet &ns,
65+
const std::stack<exprt> &stack,
66+
const exprt &specifier,
67+
const abstract_object_pointert &value,
68+
bool merging_write) const override
69+
{
70+
return write_component(
71+
environment, ns, stack, specifier, value, merging_write);
72+
}
73+
74+
void get_statistics(
75+
abstract_object_statisticst &statistics,
76+
abstract_object_visitedt &visited,
77+
const abstract_environmentt &env,
78+
const namespacet &ns) const override
79+
{
80+
abstract_objectt::get_statistics(statistics, visited, env, ns);
81+
aggregate_traitst::get_statistics(statistics, visited, env, ns);
82+
this->statistics(statistics, visited, env, ns);
83+
}
84+
85+
protected:
86+
virtual abstract_object_pointert read_component(
87+
const abstract_environmentt &environment,
88+
const exprt &expr,
89+
const namespacet &ns) const
90+
{
91+
// If we are bottom then so are the components
92+
// otherwise the components could be anything
93+
return environment.abstract_object_factory(
94+
aggregate_traitst::read_type(expr.type(), type()),
95+
ns,
96+
!is_bottom(),
97+
is_bottom());
98+
}
99+
100+
virtual abstract_object_pointert write_component(
101+
abstract_environmentt &environment,
102+
const namespacet &ns,
103+
const std::stack<exprt> &stack,
104+
const exprt &expr,
105+
const abstract_object_pointert &value,
106+
bool merging_write) const
107+
{
108+
if(is_top() || is_bottom())
109+
{
110+
return shared_from_this();
111+
}
112+
else
113+
{
114+
return std::make_shared<aggregate_typet>(type(), true, false);
115+
}
116+
}
117+
118+
virtual void statistics(
119+
abstract_object_statisticst &statistics,
120+
abstract_object_visitedt &visited,
121+
const abstract_environmentt &env,
122+
const namespacet &ns) const = 0;
123+
124+
template <class keyt, typename hash>
125+
static bool merge_shared_maps(
126+
const sharing_mapt<keyt, abstract_object_pointert, false, hash> &map1,
127+
const sharing_mapt<keyt, abstract_object_pointert, false, hash> &map2,
128+
sharing_mapt<keyt, abstract_object_pointert, false, hash> &out_map)
129+
{
130+
bool modified = false;
131+
132+
typename sharing_mapt<keyt, abstract_object_pointert, false, hash>::
133+
delta_viewt delta_view;
134+
map1.get_delta_view(map2, delta_view, true);
135+
136+
for(auto &item : delta_view)
137+
{
138+
bool changes = false;
139+
abstract_object_pointert v_new =
140+
abstract_objectt::merge(item.m, item.get_other_map_value(), changes);
141+
if(changes)
142+
{
143+
modified = true;
144+
out_map.replace(item.k, v_new);
145+
}
146+
}
147+
148+
return modified;
149+
}
150+
};
151+
152+
struct array_aggregate_typet
153+
{
154+
static const irep_idt TYPE_ID()
155+
{
156+
return ID_array;
157+
}
158+
static const irep_idt ACCESS_EXPR_ID()
159+
{
160+
return ID_index;
161+
}
162+
static typet read_type(const typet &, const typet &object_type)
163+
{
164+
array_typet array_type(to_array_type(object_type));
165+
return array_type.subtype();
166+
}
167+
168+
static void get_statistics(
169+
abstract_object_statisticst &statistics,
170+
abstract_object_visitedt &visited,
171+
const abstract_environmentt &env,
172+
const namespacet &ns)
173+
{
174+
++statistics.number_of_arrays;
175+
}
176+
};
177+
178+
struct struct_aggregate_typet
179+
{
180+
static const irep_idt &TYPE_ID()
181+
{
182+
return ID_struct;
183+
}
184+
static const irep_idt &ACCESS_EXPR_ID()
185+
{
186+
return ID_member;
187+
}
188+
static const typet &read_type(const typet &expr_type, const typet &)
189+
{
190+
return expr_type;
191+
}
192+
193+
static void get_statistics(
194+
abstract_object_statisticst &statistics,
195+
abstract_object_visitedt &visited,
196+
const abstract_environmentt &env,
197+
const namespacet &ns)
198+
{
199+
++statistics.number_of_structs;
200+
}
201+
};
202+
203+
struct union_aggregate_typet
204+
{
205+
static const irep_idt TYPE_ID()
206+
{
207+
return ID_union;
208+
}
209+
static const irep_idt ACCESS_EXPR_ID()
210+
{
211+
return ID_member;
212+
}
213+
static typet read_type(const typet &, const typet &object_type)
214+
{
215+
return object_type;
216+
}
217+
218+
static void get_statistics(
219+
abstract_object_statisticst &statistics,
220+
abstract_object_visitedt &visited,
221+
const abstract_environmentt &env,
222+
const namespacet &ns)
223+
{
224+
}
225+
};
226+
227+
#endif //CBMC_ABSTRACT_AGGREGATE_OBJECT_H

0 commit comments

Comments
 (0)