Skip to content

Commit 1e01432

Browse files
author
Matthias Güdemann
committed
First try constant array index for interpreter
1 parent 8c77ad7 commit 1e01432

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/goto-programs/interpreter_evaluate.cpp

+23-5
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,29 @@ void interpretert::evaluate(
897897
true); // fail quietly
898898
if(address.is_zero())
899899
{
900-
// Try reading from a constant -- simplify_expr has all the relevant cases
901-
// (index-of-constant-array, member-of-constant-struct and so on)
902-
// Note we complain of a problem even if simplify did *something* but
903-
// still left us with an unresolved index, member, etc.
904-
exprt simplified = simplify_expr(expr, ns);
900+
exprt simplified;
901+
// In case of being an indexed access, try to evaluate the index, then
902+
// simplify.
903+
if(expr.id() == ID_index)
904+
{
905+
exprt evaluated_index = expr;
906+
mp_vectort idx;
907+
evaluate(expr.op1(), idx);
908+
if(idx.size() == 1)
909+
{
910+
evaluated_index.op1() =
911+
constant_exprt(integer2string(idx[0]), expr.op1().type());
912+
}
913+
simplified = simplify_expr(evaluated_index, ns);
914+
}
915+
else
916+
{
917+
// Try reading from a constant -- simplify_expr has all the relevant cases
918+
// (index-of-constant-array, member-of-constant-struct and so on)
919+
// Note we complain of a problem even if simplify did *something* but
920+
// still left us with an unresolved index, member, etc.
921+
simplified = simplify_expr(expr, ns);
922+
}
905923
if(simplified.id() == expr.id())
906924
evaluate_address(expr); // Evaluate again to print error message.
907925
else

0 commit comments

Comments
 (0)