Skip to content

Commit 46ffcec

Browse files
Add versions of get_value_set returning a value
These return the computed value, which makes the information flow clearer in the program. We deprecate at the same time the functions from the previous version.
1 parent 30a31c5 commit 46ffcec

15 files changed

+139
-12
lines changed

src/goto-symex/postcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ bool postconditiont::is_used(
160160
else if(expr.id()==ID_dereference)
161161
{
162162
// aliasing may happen here
163-
value_setst::valuest expr_set;
164-
value_set.get_value_set(to_dereference_expr(expr).pointer(), expr_set, ns);
163+
value_setst::valuest expr_set =
164+
value_set.get_value_set(to_dereference_expr(expr).pointer(), ns);
165165
std::unordered_set<irep_idt> symbols;
166166

167167
for(value_setst::valuest::const_iterator

src/goto-symex/precondition.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ void preconditiont::compute_rec(exprt &dest)
112112

113113
// aliasing may happen here
114114

115-
value_setst::valuest expr_set;
116-
value_sets.get_values(
117-
SSA_step.source.function_id, target, deref_expr.pointer(), expr_set);
115+
value_setst::valuest expr_set = value_sets.get_values(
116+
SSA_step.source.function_id, target, deref_expr.pointer());
118117
std::unordered_set<irep_idt> symbols;
119118

120119
for(value_setst::valuest::const_iterator

src/goto-symex/symex_dereference_state.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,10 @@ void symex_dereference_statet::get_value_set(
103103
std::cout << "**************************\n";
104104
#endif
105105
}
106+
107+
/// Just forwards a value-set query to `state.value_set`
108+
value_setst::valuest symex_dereference_statet::get_value_set(
109+
const exprt &expr) const
110+
{
111+
return state.value_set.get_value_set(expr, ns);
112+
}

src/goto-symex/symex_dereference_state.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ class symex_dereference_statet:
3434
goto_symext::statet &state;
3535
const namespacet &ns;
3636

37+
DEPRECATED(SINCE(2019, 05, 22, "use list returning version instead"))
3738
void get_value_set(const exprt &expr, value_setst::valuest &value_set)
3839
const override;
3940

41+
value_setst::valuest get_value_set(const exprt &expr)
42+
const override;
43+
4044
const symbolt *get_or_create_failed_symbol(const exprt &expr) override;
4145
};
4246

src/pointer-analysis/dereference_callback.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ class dereference_callbackt
2929
public:
3030
virtual ~dereference_callbackt() = default;
3131

32+
DEPRECATED(SINCE(2019, 05, 22, "use list returning version instead"))
3233
virtual void
3334
get_value_set(const exprt &expr, value_setst::valuest &value_set) const = 0;
3435

36+
virtual value_setst::valuest get_value_set(const exprt &expr) const = 0;
37+
3538
virtual const symbolt *get_or_create_failed_symbol(const exprt &expr) = 0;
3639
};
3740

src/pointer-analysis/goto_program_dereference.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ void goto_program_dereferencet::get_value_set(
147147
value_sets.get_values(current_function, current_target, expr, dest);
148148
}
149149

150+
/// Gets the value set corresponding to the current target and
151+
/// expression \p expr.
152+
/// \param expr: an expression
153+
/// \return the value set
154+
std::list<exprt> goto_program_dereferencet::get_value_set(
155+
const exprt &expr) const
156+
{
157+
return value_sets.get_values(current_function, current_target, expr);
158+
}
159+
150160
/// Remove dereference expressions contained in `expr`.
151161
/// \param expr: an expression
152162
/// \param checks_only: when true, execute the substitution on a copy of expr

src/pointer-analysis/goto_program_dereference.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ class goto_program_dereferencet:protected dereference_callbackt
6565

6666
const symbolt *get_or_create_failed_symbol(const exprt &expr) override;
6767

68+
DEPRECATED(SINCE(2019, 05, 22, "use list returning version instead"))
6869
void
6970
get_value_set(const exprt &expr, value_setst::valuest &dest) const override;
7071

72+
std::list<exprt> get_value_set(const exprt &expr) const override;
73+
7174
void dereference_instruction(
7275
goto_programt::targett target,
7376
bool checks_only=false);

src/pointer-analysis/value_set.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include <util/simplify_expr.h>
2222

2323
#include <langapi/language_util.h>
24+
#include <util/range.h>
2425

2526
#ifdef DEBUG
2627
#include <iostream>
@@ -307,8 +308,7 @@ bool value_sett::eval_pointer_offset(
307308
{
308309
assert(expr.operands().size()==1);
309310

310-
object_mapt reference_set;
311-
get_value_set(expr.op0(), reference_set, ns, true);
311+
const object_mapt reference_set = get_value_set(expr.op0(), ns, true);
312312

313313
exprt new_expr;
314314
mp_integer previous_offset=0;
@@ -355,8 +355,7 @@ void value_sett::get_value_set(
355355
value_setst::valuest &dest,
356356
const namespacet &ns) const
357357
{
358-
object_mapt object_map;
359-
get_value_set(std::move(expr), object_map, ns, false);
358+
object_mapt object_map = get_value_set(std::move(expr), ns, false);
360359

361360
for(object_map_dt::const_iterator
362361
it=object_map.read().begin();
@@ -371,6 +370,17 @@ void value_sett::get_value_set(
371370
#endif
372371
}
373372

373+
std::list<exprt> value_sett::get_value_set(
374+
exprt expr,
375+
const namespacet &ns) const
376+
{
377+
const object_mapt object_map = get_value_set(std::move(expr), ns, false);
378+
return make_range(object_map.read()).map(
379+
[&](const object_map_dt::value_type &pair){
380+
return to_expr(pair);
381+
});
382+
}
383+
374384
void value_sett::get_value_set(
375385
exprt expr,
376386
object_mapt &dest,
@@ -383,6 +393,20 @@ void value_sett::get_value_set(
383393
get_value_set_rec(expr, dest, "", expr.type(), ns);
384394
}
385395

396+
value_sett::object_mapt value_sett::get_value_set(
397+
exprt expr,
398+
const namespacet &ns,
399+
bool is_simplified) const
400+
{
401+
if(!is_simplified)
402+
simplify(expr, ns);
403+
404+
object_mapt dest;
405+
get_value_set_rec(expr, dest, "", expr.type(), ns);
406+
return dest;
407+
}
408+
409+
386410
/// Check if 'suffix' starts with 'field'.
387411
/// Suffix is delimited by periods and '[]' (array access) tokens, so we're
388412
/// looking for ".field($|[]|.)"
@@ -1305,8 +1329,7 @@ void value_sett::assign(
13051329
else
13061330
{
13071331
// basic type
1308-
object_mapt values_rhs;
1309-
get_value_set(rhs, values_rhs, ns, is_simplified);
1332+
object_mapt values_rhs = get_value_set(rhs, ns, is_simplified);
13101333

13111334
// Permit custom subclass to alter the read values prior to write:
13121335
adjust_assign_rhs_values(rhs, ns, values_rhs);

src/pointer-analysis/value_set.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,22 @@ class value_sett
272272
/// \param expr: query expression
273273
/// \param [out] dest: assigned a set of expressions that `expr` may point to
274274
/// \param ns: global namespace
275+
DEPRECATED(
276+
SINCE(2019, 05, 22, "Use get_value_set(exprt, const namespacet &) instead"))
275277
void get_value_set(
276278
exprt expr,
277279
value_setst::valuest &dest,
278280
const namespacet &ns) const;
279281

282+
/// Gets values pointed to by `expr`, including following dereference
283+
/// operators (i.e. this is not a simple lookup in `valuest`).
284+
/// \param expr: query expression
285+
/// \param ns: global namespace
286+
/// \return list of expressions that `expr` may point to
287+
std::list<exprt> get_value_set(
288+
exprt expr,
289+
const namespacet &ns) const;
290+
280291
/// Appears to be unimplemented.
281292
DEPRECATED(SINCE(2019, 05, 22, "Unimplemented"))
282293
expr_sett &get(const irep_idt &identifier, const std::string &suffix);
@@ -468,12 +479,25 @@ class value_sett
468479
/// \param [out] dest: overwritten by the set of object numbers pointed to
469480
/// \param ns: global namespace
470481
/// \param is_simplified: if false, simplify `expr` before reading.
482+
DEPRECATED(
483+
SINCE(2019, 05, 22, "Use the version returning object_mapt instead"))
471484
void get_value_set(
472485
exprt expr,
473486
object_mapt &dest,
474487
const namespacet &ns,
475488
bool is_simplified) const;
476489

490+
/// Reads the set of objects pointed to by `expr`, including making
491+
/// recursive lookups for dereference operations etc.
492+
/// \param expr: query expression
493+
/// \param ns: global namespace
494+
/// \param is_simplified: if false, simplify `expr` before reading.
495+
/// \return the set of object numbers pointed to
496+
object_mapt get_value_set(
497+
exprt expr,
498+
const namespacet &ns,
499+
bool is_simplified) const;
500+
477501
/// See the other overload of `get_reference_set`. This one returns object
478502
/// numbers and offsets instead of expressions.
479503
void get_reference_set(

src/pointer-analysis/value_set_analysis.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class value_set_analysis_templatet:
6565

6666
public:
6767
// interface value_sets
68+
DEPRECATED(SINCE(2019, 05, 22, "use list returning version instead"))
6869
void get_values(
6970
const irep_idt &,
7071
locationt l,
@@ -73,6 +74,15 @@ class value_set_analysis_templatet:
7374
{
7475
(*this)[l].value_set.get_value_set(expr, dest, baset::ns);
7576
}
77+
78+
// interface value_sets
79+
std::list<exprt> get_values(
80+
const irep_idt &,
81+
locationt l,
82+
const exprt &expr) override
83+
{
84+
return (*this)[l].value_set.get_value_set(expr, baset::ns);
85+
}
7686
};
7787

7888
typedef

src/pointer-analysis/value_set_analysis_fi.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,17 @@ bool value_set_analysis_fit::check_type(const typet &type)
195195

196196
return false;
197197
}
198+
199+
std::list<exprt> value_set_analysis_fit::get_values(
200+
const irep_idt &function_id,
201+
flow_insensitive_analysis_baset::locationt l,
202+
const exprt &expr)
203+
{
204+
state.value_set.from_function =
205+
state.value_set.function_numbering.number(function_id);
206+
state.value_set.to_function =
207+
state.value_set.function_numbering.number(function_id);
208+
state.value_set.from_target_index = l->location_number;
209+
state.value_set.to_target_index = l->location_number;
210+
return state.value_set.get_value_set(expr, ns);
211+
}

src/pointer-analysis/value_set_analysis_fi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class value_set_analysis_fit:
5858

5959
public:
6060
// interface value_sets
61+
DEPRECATED(
62+
SINCE(2019, 05, 22, "Use the version returning list instead"))
6163
void get_values(
6264
const irep_idt &function_id,
6365
locationt l,
@@ -72,6 +74,11 @@ class value_set_analysis_fit:
7274
state.value_set.to_target_index = l->location_number;
7375
state.value_set.get_value_set(expr, dest, ns);
7476
}
77+
78+
std::list<exprt> get_values(
79+
const irep_idt &function_id,
80+
locationt l,
81+
const exprt &expr) override;
7582
};
7683

7784
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_ANALYSIS_FI_H

src/pointer-analysis/value_set_fi.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ void value_set_fit::get_value_set(
296296
const exprt &expr,
297297
std::list<exprt> &value_set,
298298
const namespacet &ns) const
299+
{
300+
value_set = get_value_set(expr, ns);
301+
}
302+
303+
std::list<exprt> value_set_fit::get_value_set(
304+
const exprt &expr,
305+
const namespacet &ns) const
299306
{
300307
object_mapt object_map;
301308
get_value_set(expr, object_map, ns);
@@ -336,8 +343,9 @@ void value_set_fit::get_value_set(
336343
flat_map.write()[it->first]=it->second;
337344
}
338345

346+
std::list<exprt> result;
339347
forall_objects(fit, flat_map.read())
340-
value_set.push_back(to_expr(*fit));
348+
result.push_back(to_expr(*fit));
341349

342350
#if 0
343351
// Sanity check!
@@ -351,6 +359,8 @@ void value_set_fit::get_value_set(
351359
for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++)
352360
std::cout << "GET_VALUE_SET: " << format(*it) << '\n';
353361
#endif
362+
363+
return result;
354364
}
355365

356366
void value_set_fit::get_value_set(

src/pointer-analysis/value_set_fi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,17 @@ class value_set_fit
205205
typedef std::unordered_set<idt, string_hash> assign_recursion_sett;
206206
#endif
207207

208+
DEPRECATED(
209+
SINCE(2019, 05, 22, "Use the version returning object_mapt instead"))
208210
void get_value_set(
209211
const exprt &expr,
210212
std::list<exprt> &dest,
211213
const namespacet &ns) const;
212214

215+
std::list<exprt> get_value_set(
216+
const exprt &expr,
217+
const namespacet &ns) const;
218+
213219
expr_sett &get(
214220
const idt &identifier,
215221
const std::string &suffix);

src/pointer-analysis/value_sets.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ class value_setst
2828
typedef std::list<exprt> valuest;
2929

3030
// this is not const to allow a lazy evaluation
31+
DEPRECATED(SINCE(2019, 05, 22, "use list returning version instead"))
3132
virtual void get_values(
3233
const irep_idt &function_id,
3334
goto_programt::const_targett l,
3435
const exprt &expr,
3536
valuest &dest) = 0;
3637

38+
// this is not const to allow a lazy evaluation
39+
virtual valuest get_values(
40+
const irep_idt &function_id,
41+
goto_programt::const_targett l,
42+
const exprt &expr) = 0;
43+
3744
virtual ~value_setst()
3845
{
3946
}

0 commit comments

Comments
 (0)