Skip to content

Commit d449275

Browse files
smowtonMatthias Güdemann
authored and
Matthias Güdemann
committed
Interpreter: deal with member-of-constant-struct expressions
It could already do index-of-constant-array -- by replacing its custom code with simplify_expr we can expand that to also support member-of-constant-struct, as occurs when symex's deref'ing and then the interpreter's environment translate a variable-length array type like int[obj->length] into int[particular_object.length] and then int[{.length = 1, .data = &xyz}.length].
1 parent 4e0121a commit d449275

File tree

1 file changed

+12
-43
lines changed

1 file changed

+12
-43
lines changed

src/goto-programs/interpreter_evaluate.cpp

+12-43
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <util/fixedbv.h>
1515
#include <util/ieee_float.h>
1616
#include <util/pointer_offset_size.h>
17+
#include <util/simplify_expr.h>
1718
#include <util/string_container.h>
1819

1920
#include <langapi/language_util.h>
@@ -894,52 +895,20 @@ void interpretert::evaluate(
894895
mp_integer address=evaluate_address(
895896
expr,
896897
true); // fail quietly
897-
if(address.is_zero() && expr.id()==ID_index)
898+
if(address.is_zero())
898899
{
899-
// Try reading from a constant array:
900-
mp_vectort idx;
901-
evaluate(expr.op1(), idx);
902-
if(idx.size()==1)
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);
905+
if(simplified.id() == expr.id())
906+
evaluate_address(expr); // Evaluate again to print error message.
907+
else
903908
{
904-
mp_integer read_from_index=idx[0];
905-
if(expr.op0().id()==ID_array)
906-
{
907-
const auto &ops=expr.op0().operands();
908-
DATA_INVARIANT(read_from_index.is_long(), "index is too large");
909-
if(read_from_index>=0 && read_from_index<ops.size())
910-
{
911-
evaluate(ops[read_from_index.to_long()], dest);
912-
if(dest.size()!=0)
913-
return;
914-
}
915-
}
916-
else if(expr.op0().id() == ID_array_list)
917-
{
918-
// This sort of construct comes from boolbv_get, but doesn't seem
919-
// to have an exprt yet. Its operands are a list of key-value pairs.
920-
const auto &ops=expr.op0().operands();
921-
DATA_INVARIANT(
922-
ops.size()%2==0,
923-
"array-list has odd number of operands");
924-
for(size_t listidx=0; listidx!=ops.size(); listidx+=2)
925-
{
926-
mp_vectort elem_idx;
927-
evaluate(ops[listidx], elem_idx);
928-
CHECK_RETURN(elem_idx.size()==1);
929-
if(elem_idx[0]==read_from_index)
930-
{
931-
evaluate(ops[listidx+1], dest);
932-
if(dest.size()!=0)
933-
return;
934-
else
935-
break;
936-
}
937-
}
938-
// If we fall out the end of this loop then the constant array-list
939-
// didn't define an element matching the index we're looking for.
940-
}
909+
evaluate(simplified, dest);
910+
return;
941911
}
942-
evaluate_address(expr); // Evaluate again to print error message.
943912
}
944913
else if(!address.is_zero())
945914
{

0 commit comments

Comments
 (0)