Skip to content

Commit 6a95fd8

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. The issue is reported here: diffblue#5022
1 parent b25fba2 commit 6a95fd8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/goto-symex/field_sensitivity.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,23 @@ exprt field_sensitivityt::apply(
9797
// SSA expression
9898
ssa_exprt tmp = to_ssa_expr(index.array());
9999
bool was_l2 = !tmp.get_level_2().empty();
100+
101+
exprt array_size_expr = to_array_type(l2_array.get().type()).size();
102+
if(array_size_expr.is_nil() && index.array().id() == ID_symbol)
103+
{
104+
// In case the array type was incomplete, attempt to retrieve it from
105+
// the symbol table.
106+
const symbolt *array_from_symbol_table = ns.get_symbol_table().lookup(
107+
to_symbol_expr(index.array()).get_identifier());
108+
if(array_from_symbol_table != nullptr)
109+
array_size_expr = to_array_type(array_from_symbol_table->type).size();
110+
}
111+
100112
if(
101-
l2_size.id() == ID_constant &&
102-
numeric_cast_v<mp_integer>(to_constant_expr(l2_size)) <=
103-
MAX_FIELD_SENSITIVITY_ARRAY_SIZE)
113+
array_size_expr.id() == ID_constant &&
114+
numeric_cast_v<mp_integer>(to_constant_expr(array_size_expr)) <=
115+
MAX_FIELD_SENSITIVITY_ARRAY_SIZE &&
116+
index.id() == ID_constant)
104117
{
105118
tmp.remove_level_2();
106119
index.array() = tmp.get_original_expr();

0 commit comments

Comments
 (0)