Skip to content

Commit b60259a

Browse files
authored
Merge pull request #6267 from jezhiggins/vsd-to-predicate
VSD - to predicate
2 parents b829c54 + 7af8e92 commit b60259a

Some content is hidden

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

44 files changed

+1449
-362
lines changed

src/analyses/variable-sensitivity/abstract_environment.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,41 @@ void abstract_environmentt::output(
408408
{
409409
out << "{\n";
410410

411-
decltype(map)::viewt view;
412-
map.get_view(view);
413-
for(const auto &entry : view)
411+
for(const auto &entry : map.get_view())
414412
{
415413
out << entry.first << " () -> ";
416414
entry.second->output(out, ai, ns);
417415
out << "\n";
418416
}
417+
419418
out << "}\n";
420419
}
421420

421+
exprt abstract_environmentt::to_predicate() const
422+
{
423+
if(is_bottom())
424+
return false_exprt();
425+
if(is_top())
426+
return true_exprt();
427+
428+
auto predicates = std::vector<exprt>{};
429+
for(const auto &entry : map.get_view())
430+
{
431+
auto sym = entry.first;
432+
auto val = entry.second;
433+
auto pred = val->to_predicate(symbol_exprt(sym, val->type()));
434+
435+
predicates.push_back(pred);
436+
}
437+
438+
if(predicates.size() == 1)
439+
return predicates.front();
440+
return and_exprt(predicates);
441+
}
442+
422443
bool abstract_environmentt::verify() const
423444
{
424-
decltype(map)::viewt view;
425-
map.get_view(view);
426-
for(const auto &entry : view)
445+
for(const auto &entry : map.get_view())
427446
{
428447
if(entry.second == nullptr)
429448
{
@@ -460,9 +479,7 @@ abstract_environmentt::modified_symbols(
460479
{
461480
// Find all symbols who have different write locations in each map
462481
std::vector<abstract_environmentt::map_keyt> symbols_diff;
463-
decltype(first.map)::viewt view;
464-
first.map.get_view(view);
465-
for(const auto &entry : view)
482+
for(const auto &entry : first.map.get_view())
466483
{
467484
const auto &second_entry = second.map.find(entry.first);
468485
if(second_entry.has_value())
@@ -505,10 +522,8 @@ abstract_environmentt::gather_statistics(const namespacet &ns) const
505522
{
506523
abstract_object_statisticst statistics = {};
507524
statistics.number_of_globals = count_globals(ns);
508-
decltype(map)::viewt view;
509-
map.get_view(view);
510525
abstract_object_visitedt visited;
511-
for(auto const &object : view)
526+
for(auto const &object : map.get_view())
512527
{
513528
if(visited.find(object.second) == visited.end())
514529
{

src/analyses/variable-sensitivity/abstract_environment.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ class abstract_environmentt
224224
void output(std::ostream &out, const class ai_baset &ai, const namespacet &ns)
225225
const;
226226

227+
/// Gives a boolean condition that is true for all values represented by the
228+
/// environment.
229+
///
230+
/// \return An exprt describing the environment
231+
exprt to_predicate() const;
232+
227233
/// Check the structural invariants are maintained.
228234
/// In this case this is checking there aren't any null pointer mapped values
229235
bool verify() const;

src/analyses/variable-sensitivity/abstract_object.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ exprt abstract_objectt::to_constant() const
172172
return nil_exprt();
173173
}
174174

175+
exprt abstract_objectt::to_predicate(const exprt &name) const
176+
{
177+
if(is_top())
178+
return true_exprt();
179+
if(is_bottom())
180+
return false_exprt();
181+
return to_predicate_internal(name);
182+
}
183+
184+
exprt abstract_objectt::to_predicate_internal(const exprt &name) const
185+
{
186+
UNREACHABLE;
187+
return nil_exprt();
188+
}
189+
175190
void abstract_objectt::output(
176191
std::ostream &out,
177192
const ai_baset &ai,

src/analyses/variable-sensitivity/abstract_object.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ class abstract_objectt : public std::enable_shared_from_this<abstract_objectt>
171171
/// that allows an object to be built from a value.
172172
virtual exprt to_constant() const;
173173

174+
/// Converts to an invariant expression
175+
///
176+
/// \param name - the variable name to substitute into the expression
177+
/// \return Returns an exprt representing the object as an invariant.
178+
///
179+
/// The the abstract element represents a single value the expression will
180+
/// have the form _name = value_, if the value is an interval it will have the
181+
/// the form _lower <= name <= upper_, etc.
182+
/// If the value is bottom returns false, if top returns true.
183+
exprt to_predicate(const exprt &name) const;
184+
174185
/**
175186
* A helper function to evaluate writing to a component of an
176187
* abstract object. More precise abstractions may override this to
@@ -352,6 +363,11 @@ class abstract_objectt : public std::enable_shared_from_this<abstract_objectt>
352363
return shared_from_this() == other;
353364
}
354365

366+
/// to_predicate implementation - derived classes will override
367+
/// \param name - the variable name to substitute into the expression
368+
/// \return Returns an exprt representing the object as an invariant.
369+
virtual exprt to_predicate_internal(const exprt &name) const;
370+
355371
private:
356372
/// To enforce copy-on-write these are private and have read-only accessors
357373
typet t;

src/analyses/variable-sensitivity/constant_abstract_value.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ abstract_value_pointert constant_abstract_valuet::constrain(
144144
return as_value(mutable_clone());
145145
}
146146

147+
exprt constant_abstract_valuet::to_predicate_internal(const exprt &name) const
148+
{
149+
return equal_exprt(name, value);
150+
}
151+
147152
void constant_abstract_valuet::get_statistics(
148153
abstract_object_statisticst &statistics,
149154
abstract_object_visitedt &visited,

src/analyses/variable-sensitivity/constant_abstract_value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class constant_abstract_valuet : public abstract_value_objectt
8181
abstract_object_pointert
8282
meet_with_value(const abstract_value_pointert &other) const override;
8383

84+
exprt to_predicate_internal(const exprt &name) const override;
85+
8486
private:
8587
exprt value;
8688
};

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,9 @@ exprt constant_pointer_abstract_objectt::ptr_comparison_expr(
388388
return true_exprt();
389389
return nil_exprt();
390390
}
391+
392+
exprt constant_pointer_abstract_objectt::to_predicate_internal(
393+
const exprt &name) const
394+
{
395+
return equal_exprt(name, value_stack.to_expression());
396+
}

src/analyses/variable-sensitivity/constant_pointer_abstract_object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class constant_pointer_abstract_objectt : public abstract_pointer_objectt
145145

146146
CLONE
147147

148+
exprt to_predicate_internal(const exprt &name) const override;
149+
148150
private:
149151
bool same_target(abstract_object_pointert other) const;
150152
exprt offset() const;

src/analyses/variable-sensitivity/context_abstract_object.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ abstract_object_pointert context_abstract_objectt::unwrap_context() const
160160
return child_abstract_object->unwrap_context();
161161
}
162162

163+
exprt context_abstract_objectt::to_predicate_internal(const exprt &name) const
164+
{
165+
return child_abstract_object->to_predicate(name);
166+
}
167+
163168
void context_abstract_objectt::get_statistics(
164169
abstract_object_statisticst &statistics,
165170
abstract_object_visitedt &visited,

src/analyses/variable-sensitivity/context_abstract_object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class context_abstract_objectt : public abstract_objectt
117117
bool merging_write) const override;
118118

119119
bool has_been_modified(const abstract_object_pointert &before) const override;
120+
121+
exprt to_predicate_internal(const exprt &name) const override;
120122
};
121123

122124
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_CONTEXT_ABSTRACT_OBJECT_H

0 commit comments

Comments
 (0)