Skip to content

Commit 60ffbcd

Browse files
authored
Merge pull request #5610 from jezhiggins/variable-sensitivity-object-factory-rework
Variable sensitivity object factory rework
2 parents 4144414 + dfb0e0d commit 60ffbcd

File tree

15 files changed

+146
-82
lines changed

15 files changed

+146
-82
lines changed

src/analyses/variable-sensitivity/abstract_enviroment.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ abstract_object_pointert abstract_environmentt::abstract_object_factory(
337337
const abstract_environmentt &environment,
338338
const namespacet &ns) const
339339
{
340-
return variable_sensitivity_object_factoryt::instance().get_abstract_object(
340+
return object_factory->get_abstract_object(
341341
type, top, bottom, e, environment, ns);
342342
}
343343

@@ -527,7 +527,3 @@ abstract_environmentt::gather_statistics(const namespacet &ns) const
527527
}
528528
return statistics;
529529
}
530-
531-
abstract_environmentt::abstract_environmentt() : bottom(true)
532-
{
533-
}

src/analyses/variable-sensitivity/abstract_enviroment.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,23 @@
2828
#include <util/sharing_map.h>
2929
#include <util/std_expr.h>
3030

31+
class variable_sensitivity_object_factoryt;
32+
using variable_sensitivity_object_factory_ptrt =
33+
std::shared_ptr<variable_sensitivity_object_factoryt>;
34+
3135
class abstract_environmentt
3236
{
3337
public:
3438
using map_keyt = irep_idt;
35-
abstract_environmentt();
39+
40+
abstract_environmentt() = delete;
41+
42+
abstract_environmentt(
43+
variable_sensitivity_object_factory_ptrt _object_factory)
44+
: bottom(true), object_factory(_object_factory)
45+
{
46+
}
47+
3648
/// These three are really the heart of the method
3749

3850
/// Evaluate the value of an expression relative to the current domain
@@ -248,6 +260,8 @@ class abstract_environmentt
248260
const exprt &e,
249261
const abstract_environmentt &environment,
250262
const namespacet &ns) const;
263+
264+
variable_sensitivity_object_factory_ptrt object_factory;
251265
};
252266

253267
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_ABSTRACT_ENVIROMENT_H

src/analyses/variable-sensitivity/variable_sensitivity_dependence_graph.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,31 +613,37 @@ class variable_sensitivity_dependence_domain_factoryt
613613
{
614614
public:
615615
explicit variable_sensitivity_dependence_domain_factoryt(
616-
variable_sensitivity_dependence_grapht &_dg)
617-
: dg(_dg)
616+
variable_sensitivity_dependence_grapht &_dg,
617+
variable_sensitivity_object_factory_ptrt _object_factory)
618+
: dg(_dg), object_factory(_object_factory)
618619
{
619620
}
620621

621622
std::unique_ptr<statet> make(locationt l) const override
622623
{
623624
auto node_id = dg.add_node();
624625
dg.nodes[node_id].PC = l;
625-
auto p = util_make_unique<variable_sensitivity_dependence_domaint>(node_id);
626+
auto p = util_make_unique<variable_sensitivity_dependence_domaint>(
627+
node_id, object_factory);
626628
CHECK_RETURN(p->is_bottom());
627629

628630
return std::unique_ptr<statet>(p.release());
629631
}
630632

631633
private:
632634
variable_sensitivity_dependence_grapht &dg;
635+
variable_sensitivity_object_factory_ptrt object_factory;
633636
};
634637

635638
variable_sensitivity_dependence_grapht::variable_sensitivity_dependence_grapht(
636639
const goto_functionst &goto_functions,
637-
const namespacet &_ns)
640+
const namespacet &_ns,
641+
variable_sensitivity_object_factory_ptrt _object_factory)
638642
: ai_three_way_merget(
639643
util_make_unique<ai_history_factory_default_constructort<ahistoricalt>>(),
640-
util_make_unique<variable_sensitivity_dependence_domain_factoryt>(*this),
644+
util_make_unique<variable_sensitivity_dependence_domain_factoryt>(
645+
*this,
646+
_object_factory),
641647
util_make_unique<location_sensitive_storaget>()),
642648
goto_functions(goto_functions),
643649
ns(_ns)

src/analyses/variable-sensitivity/variable_sensitivity_dependence_graph.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ class variable_sensitivity_dependence_domaint
7474
public:
7575
typedef grapht<vs_dep_nodet>::node_indext node_indext;
7676

77-
explicit variable_sensitivity_dependence_domaint(node_indext id)
78-
: node_id(id), has_values(false), has_changed(false)
77+
explicit variable_sensitivity_dependence_domaint(
78+
node_indext id,
79+
variable_sensitivity_object_factory_ptrt object_factory)
80+
: variable_sensitivity_domaint(object_factory),
81+
node_id(id),
82+
has_values(false),
83+
has_changed(false)
7984
{
8085
}
8186

@@ -237,7 +242,8 @@ class variable_sensitivity_dependence_grapht : public ai_three_way_merget,
237242

238243
explicit variable_sensitivity_dependence_grapht(
239244
const goto_functionst &goto_functions,
240-
const namespacet &_ns);
245+
const namespacet &_ns,
246+
variable_sensitivity_object_factory_ptrt object_factory);
241247

242248
void
243249
initialize(const irep_idt &function_id, const goto_programt &goto_program)

src/analyses/variable-sensitivity/variable_sensitivity_domain.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
class variable_sensitivity_domaint : public ai_domain_baset
7575
{
7676
public:
77+
explicit variable_sensitivity_domaint(
78+
variable_sensitivity_object_factory_ptrt _object_factory)
79+
: abstract_state(_object_factory)
80+
{
81+
}
82+
7783
/// Compute the abstract transformer for a single instruction
7884
///
7985
/// \param function_from: the name of the function containing from
@@ -212,6 +218,27 @@ class variable_sensitivity_domaint : public ai_domain_baset
212218
#endif
213219
};
214220

221+
class variable_sensitivity_domain_factoryt
222+
: public ai_domain_factoryt<variable_sensitivity_domaint>
223+
{
224+
public:
225+
explicit variable_sensitivity_domain_factoryt(
226+
variable_sensitivity_object_factory_ptrt _object_factory)
227+
: object_factory(_object_factory)
228+
{
229+
}
230+
231+
std::unique_ptr<statet> make(locationt l) const override
232+
{
233+
auto d = util_make_unique<variable_sensitivity_domaint>(object_factory);
234+
CHECK_RETURN(d->is_bottom());
235+
return std::unique_ptr<statet>(d.release());
236+
}
237+
238+
private:
239+
variable_sensitivity_object_factory_ptrt object_factory;
240+
};
241+
215242
#ifdef ENABLE_STATS
216243
template <>
217244
struct get_domain_statisticst<variable_sensitivity_domaint>

src/analyses/variable-sensitivity/variable_sensitivity_object_factory.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include "util/namespace.h"
1111
#include "value_set_abstract_value.h"
1212

13-
variable_sensitivity_object_factoryt
14-
variable_sensitivity_object_factoryt::s_instance;
15-
1613
variable_sensitivity_object_factoryt::ABSTRACT_OBJECT_TYPET
1714
variable_sensitivity_object_factoryt::get_abstract_object_type(const typet type)
1815
{
@@ -143,10 +140,3 @@ variable_sensitivity_object_factoryt::get_abstract_object(
143140
followed_type, top, bottom, e, environment, ns);
144141
}
145142
}
146-
147-
void variable_sensitivity_object_factoryt::set_options(
148-
const vsd_configt &options)
149-
{
150-
this->configuration = options;
151-
initialized = true;
152-
}

src/analyses/variable-sensitivity/variable_sensitivity_object_factory.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,22 @@ struct vsd_configt
122122
}
123123
};
124124

125+
class variable_sensitivity_object_factoryt;
126+
using variable_sensitivity_object_factory_ptrt =
127+
std::shared_ptr<variable_sensitivity_object_factoryt>;
128+
125129
class variable_sensitivity_object_factoryt
126130
{
127131
public:
128-
static variable_sensitivity_object_factoryt &instance()
132+
static variable_sensitivity_object_factory_ptrt
133+
configured_with(const vsd_configt &options)
134+
{
135+
return std::make_shared<variable_sensitivity_object_factoryt>(options);
136+
}
137+
138+
explicit variable_sensitivity_object_factoryt(const vsd_configt &options)
139+
: configuration(options), initialized(true)
129140
{
130-
return s_instance;
131141
}
132142

133143
/// Get the appropriate abstract object for the variable under
@@ -152,17 +162,11 @@ class variable_sensitivity_object_factoryt
152162
const abstract_environmentt &environment,
153163
const namespacet &ns);
154164

155-
/// Called once to record the appropriate variables from the command line
156-
/// options so that they can be accessed easily when they are needed.
157-
///
158-
/// \param options: the command line options
159-
void set_options(const vsd_configt &options);
160-
161165
private:
162166
variable_sensitivity_object_factoryt() : initialized(false)
163167
{
164168
}
165-
static variable_sensitivity_object_factoryt s_instance;
169+
166170
enum ABSTRACT_OBJECT_TYPET
167171
{
168172
TWO_VALUE,

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ ai_baset *goto_analyzer_parse_optionst::build_analyzer(
446446
const optionst &options,
447447
const namespacet &ns)
448448
{
449+
auto vsd_config = vsd_configt::from_options(options);
450+
auto vs_object_factory =
451+
variable_sensitivity_object_factoryt::configured_with(vsd_config);
452+
449453
// These support all of the option categories
450454
if(
451455
options.get_bool_option("recursive-interprocedural") ||
@@ -485,8 +489,8 @@ ai_baset *goto_analyzer_parse_optionst::build_analyzer(
485489
}
486490
else if(options.get_bool_option("vsd"))
487491
{
488-
df = util_make_unique<
489-
ai_domain_factory_default_constructort<variable_sensitivity_domaint>>();
492+
df = util_make_unique<variable_sensitivity_domain_factoryt>(
493+
vs_object_factory);
490494
}
491495
// non-null is not fully supported, despite the historical options
492496
// dependency-graph is quite heavily tied to the legacy-ait infrastructure
@@ -537,11 +541,13 @@ ai_baset *goto_analyzer_parse_optionst::build_analyzer(
537541
else if(options.get_bool_option("dependence-graph-vs"))
538542
{
539543
return new variable_sensitivity_dependence_grapht(
540-
goto_model.goto_functions, ns);
544+
goto_model.goto_functions, ns, vs_object_factory);
541545
}
542546
else if(options.get_bool_option("vsd"))
543547
{
544-
return new ait<variable_sensitivity_domaint>();
548+
auto df = util_make_unique<variable_sensitivity_domain_factoryt>(
549+
vs_object_factory);
550+
return new ait<variable_sensitivity_domaint>(std::move(df));
545551
}
546552
else if(options.get_bool_option("intervals"))
547553
{
@@ -629,7 +635,6 @@ int goto_analyzer_parse_optionst::doit()
629635
return perform_analysis(options);
630636
}
631637

632-
633638
/// Depending on the command line mode, run one of the analysis tasks
634639
int goto_analyzer_parse_optionst::perform_analysis(const optionst &options)
635640
{
@@ -758,18 +763,6 @@ int goto_analyzer_parse_optionst::perform_analysis(const optionst &options)
758763

759764
if(options.get_bool_option("general-analysis"))
760765
{
761-
// TODO : replace with the domain factory infrastructure
762-
try
763-
{
764-
variable_sensitivity_object_factoryt::instance().set_options(
765-
vsd_configt::from_options(options));
766-
}
767-
catch(const invalid_command_line_argument_exceptiont &e)
768-
{
769-
log.error() << e.what() << messaget::eom;
770-
return CPROVER_EXIT_USAGE_ERROR;
771-
}
772-
773766
// Output file factory
774767
const std::string outfile=options.get_option("outfile");
775768

@@ -790,7 +783,17 @@ int goto_analyzer_parse_optionst::perform_analysis(const optionst &options)
790783
// Build analyzer
791784
log.status() << "Selecting abstract domain" << messaget::eom;
792785
namespacet ns(goto_model.symbol_table); // Must live as long as the domain.
793-
std::unique_ptr<ai_baset> analyzer(build_analyzer(options, ns));
786+
std::unique_ptr<ai_baset> analyzer;
787+
788+
try
789+
{
790+
analyzer.reset(build_analyzer(options, ns));
791+
}
792+
catch(const invalid_command_line_argument_exceptiont &e)
793+
{
794+
log.error() << e.what() << messaget::eom;
795+
return CPROVER_EXIT_USAGE_ERROR;
796+
}
794797

795798
if(analyzer == nullptr)
796799
{
@@ -862,7 +865,6 @@ int goto_analyzer_parse_optionst::perform_analysis(const optionst &options)
862865
CPROVER_EXIT_VERIFICATION_UNSAFE : CPROVER_EXIT_VERIFICATION_SAFE;
863866
}
864867

865-
866868
// Final defensive error case
867869
log.error() << "no analysis option given -- consider reading --help"
868870
<< messaget::eom;

unit/analyses/variable-sensitivity/constant_abstract_value/merge.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <analyses/variable-sensitivity/abstract_enviroment.h>
1010
#include <analyses/variable-sensitivity/abstract_object.h>
1111
#include <analyses/variable-sensitivity/constant_abstract_value.h>
12+
#include <analyses/variable-sensitivity/variable_sensitivity_object_factory.h>
1213
#include <testing-utils/use_catch.h>
1314
#include <typeinfo>
1415
#include <util/arith_tools.h>
@@ -27,7 +28,9 @@ SCENARIO(
2728
const exprt val1 = from_integer(1, integer_typet());
2829
const exprt val2 = from_integer(2, integer_typet());
2930

30-
abstract_environmentt enviroment;
31+
auto object_factory = variable_sensitivity_object_factoryt::configured_with(
32+
vsd_configt::constant_domain());
33+
abstract_environmentt enviroment{object_factory};
3134
enviroment.make_top();
3235
symbol_tablet symbol_table;
3336
namespacet ns(symbol_table);

unit/analyses/variable-sensitivity/constant_array_abstract_object/merge.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ SCENARIO(
101101
const index_exprt i2 =
102102
index_exprt(nil_exprt(), from_integer(2, integer_typet()));
103103

104-
abstract_environmentt enviroment;
104+
auto object_factory = variable_sensitivity_object_factoryt::configured_with(
105+
vsd_configt::constant_domain());
106+
abstract_environmentt enviroment(object_factory);
105107
enviroment.make_top();
106108
symbol_tablet symbol_table;
107109
namespacet ns(symbol_table);
108110

109-
variable_sensitivity_object_factoryt::instance().set_options(
110-
vsd_configt::constant_domain());
111-
112111
array_utilt util(enviroment, ns);
113112

114113
abstract_object_pointert result;

unit/analyses/variable-sensitivity/eval.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ SCENARIO(
2121
{
2222
GIVEN("An environment with intervals domain")
2323
{
24-
variable_sensitivity_object_factoryt::instance().set_options(
24+
auto object_factory = variable_sensitivity_object_factoryt::configured_with(
2525
vsd_configt::intervals());
26-
abstract_environmentt environment;
26+
abstract_environmentt environment(object_factory);
2727
environment.make_top(); // Domains are bottom on construction
2828

2929
symbol_tablet symbol_table;
@@ -68,7 +68,7 @@ SCENARIO(
6868
// b1 = 0
6969
environment.assign(
7070
b1.symbol_expr(),
71-
variable_sensitivity_object_factoryt::instance().get_abstract_object(
71+
object_factory->get_abstract_object(
7272
number_type,
7373
false,
7474
false,

unit/analyses/variable-sensitivity/full_struct_abstract_object/merge.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,13 @@ SCENARIO(
128128
const member_exprt b(nil_exprt(), "b", integer_typet());
129129
const member_exprt c(nil_exprt(), "c", integer_typet());
130130

131-
abstract_environmentt enviroment;
131+
auto object_factory = variable_sensitivity_object_factoryt::configured_with(
132+
vsd_configt::constant_domain());
133+
abstract_environmentt enviroment(object_factory);
132134
enviroment.make_top();
133135
symbol_tablet symbol_table;
134136
namespacet ns(symbol_table);
135137

136-
variable_sensitivity_object_factoryt::instance().set_options(
137-
vsd_configt::constant_domain());
138-
139138
struct_utilt util(enviroment, ns);
140139

141140
abstract_object_pointert result;

0 commit comments

Comments
 (0)