Skip to content

Commit e64675a

Browse files
committed
Pointer dereferencing cleanup: Make try_add_offset_to_indices file-local
This function does not require access to any state, and is really not generally usable or useful. Also, make explicit why it would not work for type casts.
1 parent 84df81e commit e64675a

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/pointer-analysis/value_set_dereference.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ static json_objectt value_set_dereference_stats_to_json(
9999
return json_result;
100100
}
101101

102-
optionalt<exprt> value_set_dereferencet::try_add_offset_to_indices(
103-
const exprt &expr,
104-
const exprt &offset_elements)
102+
/// If `expr` is of the form (c1 ? e1[o1] : c2 ? e2[o2] : c3 ? ...)
103+
/// then return `c1 ? e1[o1 + offset] : e2[o2 + offset] : c3 ? ...`
104+
/// otherwise return an empty optionalt.
105+
static optionalt<exprt>
106+
try_add_offset_to_indices(const exprt &expr, const exprt &offset_elements)
105107
{
106108
if(const auto *index_expr = expr_try_dynamic_cast<index_exprt>(expr))
107109
{
@@ -123,6 +125,13 @@ optionalt<exprt> value_set_dereferencet::try_add_offset_to_indices(
123125
return {};
124126
return if_exprt{if_expr->cond(), *true_case, *false_case};
125127
}
128+
else if(can_cast_expr<typecast_exprt>(expr))
129+
{
130+
// the case of a type cast is _not_ handled here, because that would require
131+
// doing arithmetic on the offset, and may result in an offset into some
132+
// sub-element
133+
return {};
134+
}
126135
else
127136
{
128137
return {};

src/pointer-analysis/value_set_dereference.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ class value_set_dereferencet final
5454
/// \param display_points_to_sets: Display size and contents of points to sets
5555
exprt dereference(const exprt &pointer, bool display_points_to_sets = false);
5656

57-
/// If `expr` is of the form (c1 ? e1[o1] : c2 ? e2[o2] : c3 ? ...)
58-
/// then return `c1 ? e1[o1 + offset] : e2[o2 + offset] : c3 ? ...`
59-
/// otherwise return an empty optionalt.
60-
optionalt<exprt>
61-
try_add_offset_to_indices(const exprt &expr, const exprt &offset);
62-
6357
/// Return value for `build_reference_to`; see that method for documentation.
6458
class valuet
6559
{

0 commit comments

Comments
 (0)