Skip to content

Commit 684df8a

Browse files
authored
Merge pull request diffblue#50 from diffblue/feature/tests-for-sensitivity
Feature/tests for sensitivity
2 parents 6f75660 + 57a6cb7 commit 684df8a

14 files changed

+261
-71
lines changed

src/analyses/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SRC = natural_loops.cpp is_threaded.cpp dirty.cpp interval_analysis.cpp \
1616
variable-sensitivity/struct_abstract_object.cpp \
1717
variable-sensitivity/array_abstract_object.cpp \
1818
variable-sensitivity/constant_pointer_abstract_object.cpp \
19+
variable-sensitivity/variable_sensitivity_object_factory.cpp \
1920
# Empty last line
2021

2122
INCLUDES= -I ..

src/analyses/variable-sensitivity/abstract_enviroment.cpp

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include <analyses/variable-sensitivity/pointer_abstract_object.h>
1616
#include <analyses/variable-sensitivity/array_abstract_object.h>
1717
#include <analyses/variable-sensitivity/constant_pointer_abstract_object.h>
18+
#include <analyses/variable-sensitivity/variable_sensitivity_object_factory.h>
1819
#include <analyses/ai.h>
1920
#include <analyses/constant_propagator.h>
2021
#include <util/simplify_expr.h>
2122

2223

23-
2424
/*******************************************************************\
2525
2626
Function: abstract_environmentt::eval
@@ -36,7 +36,7 @@ Function: abstract_environmentt::eval
3636
\*******************************************************************/
3737

3838
abstract_object_pointert abstract_environmentt::eval(
39-
const exprt &expr, const namespacet &ns) const
39+
const exprt &e, const namespacet &ns) const
4040
{
4141
assert(!is_bottom);
4242
typedef std::function<abstract_object_pointert(const exprt &)> eval_handlert;
@@ -49,7 +49,7 @@ abstract_object_pointert abstract_environmentt::eval(
4949
const auto &symbol_entry=map.find(symbol);
5050
if(symbol_entry==map.cend())
5151
{
52-
return abstract_object_factory(expr.type(), true);
52+
return abstract_object_factory(expr.type(), ns, true);
5353
}
5454
else
5555
{
@@ -72,7 +72,7 @@ abstract_object_pointert abstract_environmentt::eval(
7272
std::dynamic_pointer_cast<struct_abstract_objectt>(
7373
eval(member_expr.compound(), ns));
7474

75-
return struct_abstract_object->read_component(*this, member_expr);
75+
return struct_abstract_object->read_component(*this, member_expr, ns);
7676
}
7777
},
7878
{
@@ -105,13 +105,13 @@ abstract_object_pointert abstract_environmentt::eval(
105105
std::dynamic_pointer_cast<array_abstract_objectt>(
106106
eval(index_expr.array(), ns));
107107

108-
return array_abstract_object->read_index(*this, index_expr);
108+
return array_abstract_object->read_index(*this, index_expr, ns);
109109
}
110110
}
111111
};
112112

113113
// first try to collapse constant folding
114-
const exprt &simplified_expr=simplify_expr(expr, ns);
114+
const exprt &simplified_expr=simplify_expr(e, ns);
115115

116116
const auto &handler=handlers.find(simplified_expr.id());
117117
if(handler==handlers.cend())
@@ -124,7 +124,7 @@ abstract_object_pointert abstract_environmentt::eval(
124124
}
125125
else
126126
{
127-
return abstract_object_factory(simplified_expr.type(), true);
127+
return abstract_object_factory(simplified_expr.type(), ns, true);
128128
}
129129
}
130130
else
@@ -184,7 +184,8 @@ bool abstract_environmentt::assign(
184184
abstract_object_pointert symbol_object;
185185
if(map.find(symbol_expr)==map.end())
186186
{
187-
symbol_object=abstract_object_factory(symbol_expr.type(), true, false);
187+
symbol_object=abstract_object_factory(
188+
symbol_expr.type(), ns, true, false);
188189
}
189190
else
190191
{
@@ -376,6 +377,7 @@ Function: abstract_environmentt::abstract_object_factory
376377
Inputs:
377378
type - the type of the object whose state should be tracked
378379
top - does the type of the object start as top
380+
bottom - does the type of the object start as bottom in the two-value domain
379381
380382
Outputs: The abstract object that has been created
381383
@@ -385,23 +387,10 @@ Function: abstract_environmentt::abstract_object_factory
385387
\*******************************************************************/
386388

387389
abstract_object_pointert abstract_environmentt::abstract_object_factory(
388-
const typet type, bool top, bool bottom) const
390+
const typet type, const namespacet &ns, bool top, bool bottom) const
389391
{
390-
// TODO (tkiley): Here we should look at some config file
391-
if(type.id()==ID_signedbv || type.id()==ID_bool || type.id()==ID_c_bool)
392-
{
393-
return abstract_object_pointert(
394-
new constant_abstract_valuet(type, top, bottom));
395-
}
396-
else if(type.id()==ID_pointer)
397-
{
398-
return abstract_object_pointert(
399-
new constant_pointer_abstract_objectt(type, top, bottom, *this));
400-
}
401-
else
402-
{
403-
return abstract_object_pointert(new abstract_objectt(type, top, false));
404-
}
392+
exprt empty_constant_expr=exprt();
393+
return abstract_object_factory(type, top, bottom, empty_constant_expr, ns);
405394
}
406395

407396
/*******************************************************************\
@@ -420,23 +409,34 @@ Function: abstract_environmentt::abstract_object_factory
420409
\*******************************************************************/
421410

422411
abstract_object_pointert abstract_environmentt::abstract_object_factory(
423-
const typet type, const exprt e, const namespacet &ns) const
412+
const typet type, const exprt &e, const namespacet &ns) const
424413
{
425-
assert(type==e.type());
426-
if(type.id()==ID_signedbv || type.id()==ID_bool || type.id()==ID_c_bool)
427-
{
428-
return abstract_object_pointert(
429-
new constant_abstract_valuet(e));
430-
}
431-
else if(type.id()==ID_pointer)
432-
{
433-
return abstract_object_pointert(
434-
new constant_pointer_abstract_objectt(e, *this, ns));
435-
}
436-
else
437-
{
438-
return abstract_object_pointert(new abstract_objectt(e));
439-
}
414+
return abstract_object_factory(type, false, false, e, ns);
415+
}
416+
417+
/*******************************************************************\
418+
419+
Function: abstract_environmentt::abstract_object_factory
420+
421+
Inputs:
422+
type - the type of the object whose state should be tracked
423+
top - does the type of the object start as top in the two-value domain
424+
bottom - does the type of the object start as bottom in the two-value domain
425+
expr - the starting value of the symbol if top and bottom are both false
426+
427+
Outputs: The abstract object that has been created
428+
429+
Purpose: Look at the configuration for the sensitivity and create an
430+
appropriate abstract_object
431+
432+
\*******************************************************************/
433+
434+
abstract_object_pointert abstract_environmentt::abstract_object_factory(
435+
const typet type, bool top, bool bottom, const exprt &e,
436+
const namespacet &ns) const
437+
{
438+
return variable_sensitivity_object_factoryt::instance().get_abstract_object(
439+
type, top, bottom, e, ns);
440440
}
441441

442442
/*******************************************************************\
@@ -662,8 +662,3 @@ abstract_object_pointert abstract_environmentt::eval_expression(
662662
abstract_object_pointert lhs=eval(e.op0(), ns);
663663
return lhs->expression_transform(e, *this, ns);
664664
}
665-
666-
abstract_object_pointert abstract_environmentt::eval_rest(const exprt &e) const
667-
{
668-
return abstract_object_factory(e.type());
669-
}

src/analyses/variable-sensitivity/abstract_enviroment.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,21 @@ class abstract_environmentt
3636
bool merge_write);
3737

3838
virtual abstract_object_pointert abstract_object_factory(
39-
const typet type, bool top=true, bool bottom=false) const;
39+
const typet type,
40+
const namespacet &ns,
41+
bool top=true,
42+
bool bottom=false) const;
4043
// For converting constants in the program
4144
// Maybe these two should be compacted to one call...
4245
virtual abstract_object_pointert abstract_object_factory(
43-
const typet type, const exprt e, const namespacet &ns) const;
46+
const typet type, const exprt &e, const namespacet &ns) const;
4447

4548

4649
virtual bool merge(const abstract_environmentt &env);
4750

4851
// This should be used as a default case / everything else has failed
49-
// The string is so that I can easily find and diagnose cases where this occurs
52+
// The string is so that I can easily find and diagnose cases where this
53+
// occurs
5054
virtual void havoc(const std::string &havoc_string);
5155

5256
void make_top();
@@ -69,14 +73,13 @@ class abstract_environmentt
6973
virtual abstract_object_pointert eval_expression(
7074
const exprt &e, const namespacet &ns) const;
7175

72-
// Hook for domain specific handling of operators
73-
virtual abstract_object_pointert eval_rest(const exprt &e) const;
74-
75-
76-
77-
typedef symbol_exprt map_keyt;
78-
std::map<map_keyt, abstract_object_pointert> map;
76+
typedef symbol_exprt map_keyt;
77+
std::map<map_keyt, abstract_object_pointert> map;
7978

79+
private:
80+
abstract_object_pointert abstract_object_factory(
81+
const typet type, bool top, bool bottom, const exprt &e,
82+
const namespacet &ns) const;
8083
};
8184

8285
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_ABSTRACT_ENVIROMENT_H

src/analyses/variable-sensitivity/abstract_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ abstract_object_pointert abstract_objectt::expression_transform(
206206
}
207207
else
208208
{
209-
return environment.abstract_object_factory(expr.type(), true, false);
209+
return environment.abstract_object_factory(expr.type(), ns, true, false);
210210
}
211211
}
212212

src/analyses/variable-sensitivity/array_abstract_object.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Function: array_abstract_objectt::array_abstract_objectt
8585
8686
\*******************************************************************/
8787

88-
array_abstract_objectt::array_abstract_objectt(const constant_exprt &e):
88+
array_abstract_objectt::array_abstract_objectt(const exprt &e):
8989
abstract_objectt(e)
9090
{
9191
assert(e.type().id()==ID_array);
@@ -107,14 +107,16 @@ Function: array_abstract_objectt::read_index
107107
\*******************************************************************/
108108

109109
abstract_object_pointert array_abstract_objectt::read_index(
110-
const abstract_environmentt &env, const index_exprt &index) const
110+
const abstract_environmentt &env,
111+
const index_exprt &index,
112+
const namespacet& ns) const
111113
{
112114
array_typet array_type(to_array_type(type));
113115
const typet &subtype=array_type.subtype();
114116

115117
// if we are bottom then so are the values in the array
116118
// otherwise the values are top
117-
return env.abstract_object_factory(subtype, !is_bottom(), is_bottom());
119+
return env.abstract_object_factory(subtype, ns, !is_bottom(), is_bottom());
118120
}
119121

120122
/*******************************************************************\

src/analyses/variable-sensitivity/array_abstract_object.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ class array_abstract_objectt:public abstract_objectt
2222
explicit array_abstract_objectt(const typet &type);
2323
array_abstract_objectt(const typet &type, bool top, bool bottom);
2424
explicit array_abstract_objectt(const array_abstract_objectt &old);
25-
explicit array_abstract_objectt(const constant_exprt &expr);
25+
explicit array_abstract_objectt(const exprt &expr);
2626

2727
CLONE
2828
MERGE(abstract_objectt)
2929

3030
virtual abstract_object_pointert read_index(
31-
const abstract_environmentt &env, const index_exprt &index) const;
31+
const abstract_environmentt &env,
32+
const index_exprt &index,
33+
const namespacet &ns) const;
3234

3335
virtual sharing_ptrt<array_abstract_objectt> write_index(
3436
abstract_environmentt &environment,

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ abstract_object_pointert constant_pointer_abstract_objectt::read_dereference(
276276
// Return top if dereferencing a null pointer or we are top
277277
bool is_value_top = top || value.id()==ID_nil;
278278
return env.abstract_object_factory(
279-
type.subtype(), is_value_top, !is_value_top);
279+
type.subtype(), ns, is_value_top, !is_value_top);
280280
}
281281
else
282282
{
@@ -287,11 +287,11 @@ abstract_object_pointert constant_pointer_abstract_objectt::read_dereference(
287287
else if(value.id()==ID_constant)
288288
{
289289
// Reading a null pointer, return top
290-
return env.abstract_object_factory(type.subtype(), true, false);
290+
return env.abstract_object_factory(type.subtype(), ns, true, false);
291291
}
292292
else
293293
{
294-
return env.abstract_object_factory(type.subtype(), true, false);
294+
return env.abstract_object_factory(type.subtype(), ns, true, false);
295295
}
296296
}
297297
}

src/analyses/variable-sensitivity/pointer_abstract_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ abstract_object_pointert pointer_abstract_objectt::read_dereference(
113113
pointer_typet pointer_type(to_pointer_type(type));
114114
const typet &pointed_to_type=pointer_type.subtype();
115115

116-
return env.abstract_object_factory(pointed_to_type, true, false);
116+
return env.abstract_object_factory(pointed_to_type, ns, true, false);
117117
}
118118

119119
/*******************************************************************\

src/analyses/variable-sensitivity/struct_abstract_object.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Function: struct_abstract_objectt::struct_abstract_objectt
8686
8787
\*******************************************************************/
8888

89-
struct_abstract_objectt::struct_abstract_objectt(const constant_exprt &e):
89+
struct_abstract_objectt::struct_abstract_objectt(const exprt &e):
9090
abstract_objectt(e)
9191
{
9292
assert(e.type().id()==ID_struct);
@@ -111,12 +111,14 @@ Function: struct_abstract_objectt::read_component
111111
\*******************************************************************/
112112

113113
abstract_object_pointert struct_abstract_objectt::read_component(
114-
const abstract_environmentt &environment, const member_exprt &member_expr)
114+
const abstract_environmentt &environment,
115+
const member_exprt &member_expr,
116+
const namespacet& ns)
115117
{
116118
// If we are bottom then so are the components
117119
// otherwise the components could be anything
118120
return environment.abstract_object_factory(
119-
member_expr.type(), !is_bottom(), is_bottom());
121+
member_expr.type(), ns, !is_bottom(), is_bottom());
120122
}
121123

122124
/*******************************************************************\

src/analyses/variable-sensitivity/struct_abstract_object.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ class struct_abstract_objectt:public abstract_objectt
2121
explicit struct_abstract_objectt(const typet &type);
2222
struct_abstract_objectt(const typet &type, bool top, bool bottom);
2323
explicit struct_abstract_objectt(const struct_abstract_objectt &old);
24-
explicit struct_abstract_objectt(const constant_exprt &expr);
24+
explicit struct_abstract_objectt(const exprt &expr);
2525

2626
CLONE
2727
MERGE(abstract_objectt)
2828

2929
// struct interface
3030
virtual abstract_object_pointert read_component(
31-
const abstract_environmentt &environment, const member_exprt &member_expr);
31+
const abstract_environmentt &environment,
32+
const member_exprt &member_expr,
33+
const namespacet& ns);
3234

3335
virtual sharing_ptrt<struct_abstract_objectt> write_component(
3436
const abstract_environmentt &environment,

src/analyses/variable-sensitivity/variable_sensitivity_domain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void variable_sensitivity_domaint::transform(
5353
// Assign to top is the same as removing
5454
abstract_object_pointert top_object=
5555
abstract_state.abstract_object_factory(
56-
to_code_dead(instruction.code).symbol().type(), true);
56+
to_code_dead(instruction.code).symbol().type(), ns, true);
5757
abstract_state.assign(
5858
to_code_dead(instruction.code).symbol(), top_object, ns);
5959
}

0 commit comments

Comments
 (0)