Skip to content

Commit cb0f485

Browse files
field_sensitivity::apply handle non-constant index
When the index is not constant when accessing a constant size array, we should expand the expression into `{array[0]; array[1];...}[index]` so that the relation with field sensitivity expressions `array[[0]]`, `array[[1]]`, etc, is not lost.
1 parent 830be65 commit cb0f485

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,29 @@ exprt field_sensitivityt::apply(
111111
if(
112112
array_size_expr.id() == ID_constant &&
113113
numeric_cast_v<mp_integer>(to_constant_expr(array_size_expr))
114-
<= max_field_sensitive_array_size &&
115-
l2_index.get().id() == ID_constant)
114+
<= max_field_sensitive_array_size )
116115
{
117-
// place the entire index expression, not just the array operand, in an
118-
// SSA expression
119-
ssa_exprt ssa_array = to_ssa_expr(l2_array.get());
120-
ssa_array.remove_level_2();
121-
index.array() = ssa_array.get_original_expr();
122-
index.index() = l2_index.get();
123-
tmp.set_expression(index);
124-
if(was_l2)
125-
return state.rename(std::move(tmp), ns).get();
116+
if(l2_index.get().id() == ID_constant)
117+
{
118+
// place the entire index expression, not just the array operand, in an
119+
// SSA expression
120+
ssa_exprt ssa_array = to_ssa_expr(l2_array.get());
121+
ssa_array.remove_level_2();
122+
index.array() = ssa_array.get_original_expr();
123+
index.index() = l2_index.get();
124+
tmp.set_expression(index);
125+
if(was_l2)
126+
return state.rename(std::move(tmp), ns).get();
127+
else
128+
return std::move(tmp);
129+
}
126130
else
127-
return std::move(tmp);
131+
{
132+
// Expand the array and return `{array[0]; array[1]; ...}[index]`
133+
exprt expanded_array =
134+
get_fields(ns, state, to_ssa_expr(l2_array.get()));
135+
return index_exprt{std::move(expanded_array), l2_index.get()};
136+
}
128137
}
129138
}
130139
}

0 commit comments

Comments
 (0)