Skip to content

Commit 5d7b958

Browse files
Attempt to get missing array size from symbol table
In some cases, like the test in regression/cbmc/Global_Initialization2, the array type is incomplete and changed in the symbol table after the main function has been converted, leading to inconsistencies. This means we can get nil instead of the size in field_sensitivityt::apply, though the actual size is present in the symbol table.
1 parent b8b98d8 commit 5d7b958

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,22 @@ exprt field_sensitivityt::apply(
9696
l2_index.simplify(ns);
9797
auto l2_array = state.rename(index.array(), ns);
9898
bool was_l2 = !tmp.get_level_2().empty();
99+
100+
exprt array_size_expr = to_array_type(l2_array.get().type()).size();
101+
if(array_size_expr.is_nil() && index.array().id() == ID_symbol)
102+
{
103+
// In case the array type was incomplete, attempt to retrieve it from
104+
// the symbol table.
105+
const symbolt *array_from_symbol_table = ns.get_symbol_table()
106+
.lookup(to_symbol_expr(index.array()).get_identifier());
107+
if(array_from_symbol_table != nullptr)
108+
array_size_expr = to_array_type(array_from_symbol_table->type).size();
109+
}
110+
99111
if(
100-
to_array_type(l2_array.get().type()).size().id() == ID_constant &&
101-
numeric_cast_v<mp_integer>(to_constant_expr(to_array_type(
102-
l2_array.get().type()).size()))
103-
<= max_field_sensitive_array_size &&
112+
array_size_expr.id() == ID_constant &&
113+
numeric_cast_v<mp_integer>(to_constant_expr(array_size_expr))
114+
<= max_field_sensitive_array_size &&
104115
l2_index.get().id() == ID_constant)
105116
{
106117
// place the entire index expression, not just the array operand, in an
@@ -324,8 +335,9 @@ bool field_sensitivityt::is_divisible(const ssa_exprt &expr)
324335
if(
325336
expr.type().id() == ID_array &&
326337
to_array_type(expr.type()).size().id() == ID_constant &&
327-
numeric_cast_v<mp_integer>(to_constant_expr(to_array_type(expr.type()).size()))
328-
<= max_field_sensitive_array_size)
338+
numeric_cast_v<mp_integer>(
339+
to_constant_expr(to_array_type(expr.type()).size()))
340+
<= max_field_sensitive_array_size)
329341
{
330342
return true;
331343
}

0 commit comments

Comments
 (0)