Skip to content

Commit e1af2ee

Browse files
author
Owen
committed
Refactor value_set_dereferencet
The aim is to make value_set_dereferencet::build_reference_to accessible from the outside, by making it public and static. This required making several other functions public and static as well. The motivation is to use in value_set_element_to_expr, which is a helper function for goto_symext::try_filter_value_sets.
1 parent 6ac3619 commit e1af2ee

File tree

2 files changed

+59
-34
lines changed

2 files changed

+59
-34
lines changed

src/pointer-analysis/value_set_dereference.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ exprt value_set_dereferencet::dereference(const exprt &pointer)
7474
it!=points_to_set.end();
7575
it++)
7676
{
77-
valuet value = build_reference_to(*it, pointer);
77+
valuet value =
78+
build_reference_to(*it, pointer, exclude_null_derefs, language_mode, ns);
7879

7980
#if 0
8081
std::cout << "V: " << format(value.pointer_guard) << " --> ";
@@ -179,7 +180,8 @@ exprt value_set_dereferencet::dereference(const exprt &pointer)
179180
/// - object_type=(int *), dereference_type=(void **) is not ok;
180181
bool value_set_dereferencet::dereference_type_compare(
181182
const typet &object_type,
182-
const typet &dereference_type) const
183+
const typet &dereference_type,
184+
const namespacet &ns)
183185
{
184186
const typet *object_unwrapped = &object_type;
185187
const typet *dereference_unwrapped = &dereference_type;
@@ -245,6 +247,11 @@ bool value_set_dereferencet::dereference_type_compare(
245247
/// ID_unknown, ID_invalid, or an object_descriptor_exprt giving a referred
246248
/// object and offset.
247249
/// \param pointer_expr: pointer expression that may point to `what`
250+
/// \param exclude_null_derefs: Ignore value-set entries that indicate a
251+
/// given dereference may follow a null pointer
252+
/// \param language_mode: Mode for any new symbols created to represent a
253+
/// dereference failure
254+
/// \param ns: A namespace
248255
/// \return a `valuet` object containing `guard`, `value` and `ignore` fields.
249256
/// The `ignore` field is true for a `null` object when `exclude_null_derefs`
250257
/// is true (set by our creator when they know \p what cannot be null)
@@ -258,7 +265,10 @@ bool value_set_dereferencet::dereference_type_compare(
258265
/// .ignore = false}`
259266
value_set_dereferencet::valuet value_set_dereferencet::build_reference_to(
260267
const exprt &what,
261-
const exprt &pointer_expr)
268+
const exprt &pointer_expr,
269+
const bool exclude_null_derefs,
270+
const irep_idt language_mode,
271+
const namespacet &ns)
262272
{
263273
const typet &dereference_type = pointer_expr.type().subtype();
264274

@@ -324,8 +334,9 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to(
324334

325335
result.value=index_expr;
326336
}
327-
else if(dereference_type_compare(
328-
memory_symbol.type.subtype(), dereference_type))
337+
else if(
338+
dereference_type_compare(
339+
memory_symbol.type.subtype(), dereference_type, ns))
329340
{
330341
const index_exprt index_expr(
331342
symbol_expr,
@@ -372,18 +383,19 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to(
372383

373384
exprt root_object_subexpression=root_object;
374385

375-
if(dereference_type_compare(object_type, dereference_type) &&
376-
o.offset().is_zero())
386+
if(
387+
dereference_type_compare(object_type, dereference_type, ns) &&
388+
o.offset().is_zero())
377389
{
378390
// The simplest case: types match, and offset is zero!
379391
// This is great, we are almost done.
380392

381393
result.value = typecast_exprt::conditional_cast(object, dereference_type);
382394
}
383-
else if(root_object_type.id()==ID_array &&
384-
dereference_type_compare(
385-
root_object_type.subtype(),
386-
dereference_type))
395+
else if(
396+
root_object_type.id() == ID_array &&
397+
dereference_type_compare(
398+
root_object_type.subtype(), dereference_type, ns))
387399
{
388400
// We have an array with a subtype that matches
389401
// the dereferencing type.
@@ -451,7 +463,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to(
451463
else
452464
offset=o.offset();
453465

454-
if(memory_model(result.value, dereference_type, offset))
466+
if(memory_model(result.value, dereference_type, offset, ns))
455467
{
456468
// ok, done
457469
}
@@ -486,7 +498,8 @@ static bool is_a_bv_type(const typet &type)
486498
bool value_set_dereferencet::memory_model(
487499
exprt &value,
488500
const typet &to_type,
489-
const exprt &offset)
501+
const exprt &offset,
502+
const namespacet &ns)
490503
{
491504
// we will allow more or less arbitrary pointer type cast
492505

@@ -518,7 +531,7 @@ bool value_set_dereferencet::memory_model(
518531

519532
// otherwise, we will stitch it together from bytes
520533

521-
return memory_model_bytes(value, to_type, offset);
534+
return memory_model_bytes(value, to_type, offset, ns);
522535
}
523536

524537
/// Replace `value` by an expression of type `to_type` corresponding to the
@@ -532,7 +545,8 @@ bool value_set_dereferencet::memory_model(
532545
bool value_set_dereferencet::memory_model_bytes(
533546
exprt &value,
534547
const typet &to_type,
535-
const exprt &offset)
548+
const exprt &offset,
549+
const namespacet &ns)
536550
{
537551
const typet from_type=value.type();
538552

src/pointer-analysis/value_set_dereference.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ class value_set_dereferencet final
5454
/// \param pointer: A pointer-typed expression, to be dereferenced.
5555
exprt dereference(const exprt &pointer);
5656

57-
private:
58-
const namespacet &ns;
59-
symbol_tablet &new_symbol_table;
60-
dereference_callbackt &dereference_callback;
61-
/// language_mode: ID_java, ID_C or another language identifier
62-
/// if we know the source language in use, irep_idt() otherwise.
63-
const irep_idt language_mode;
64-
/// Flag indicating whether `value_set_dereferencet::dereference` should
65-
/// disregard an apparent attempt to dereference NULL
66-
const bool exclude_null_derefs;
67-
68-
bool dereference_type_compare(
69-
const typet &object_type,
70-
const typet &dereference_type) const;
71-
7257
/// Return value for `build_reference_to`; see that method for documentation.
7358
class valuet
7459
{
@@ -82,14 +67,40 @@ class value_set_dereferencet final
8267
}
8368
};
8469

85-
valuet build_reference_to(const exprt &what, const exprt &pointer);
70+
static valuet build_reference_to(
71+
const exprt &what,
72+
const exprt &pointer,
73+
bool exclude_null_derefs,
74+
irep_idt language_mode,
75+
const namespacet &ns);
76+
77+
static bool dereference_type_compare(
78+
const typet &object_type,
79+
const typet &dereference_type,
80+
const namespacet &ns);
8681

87-
bool memory_model(exprt &value, const typet &type, const exprt &offset);
82+
static bool memory_model(
83+
exprt &value,
84+
const typet &type,
85+
const exprt &offset,
86+
const namespacet &ns);
8887

89-
bool memory_model_bytes(
88+
static bool memory_model_bytes(
9089
exprt &value,
9190
const typet &type,
92-
const exprt &offset);
91+
const exprt &offset,
92+
const namespacet &ns);
93+
94+
private:
95+
const namespacet &ns;
96+
symbol_tablet &new_symbol_table;
97+
dereference_callbackt &dereference_callback;
98+
/// language_mode: ID_java, ID_C or another language identifier
99+
/// if we know the source language in use, irep_idt() otherwise.
100+
const irep_idt language_mode;
101+
/// Flag indicating whether `value_set_dereferencet::dereference` should
102+
/// disregard an apparent attempt to dereference NULL
103+
const bool exclude_null_derefs;
93104
};
94105

95106
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DEREFERENCE_H

0 commit comments

Comments
 (0)