@@ -597,16 +597,25 @@ exprt interpretert::get_value(
597
597
exprt result=array_exprt (to_array_type (real_type));
598
598
const exprt &size_expr=static_cast <const exprt &>(type.find (ID_size));
599
599
size_t subtype_size=get_size (type.subtype ());
600
- mp_integer mp_count;
601
- to_integer (size_expr, mp_count);
602
- unsigned count=integer2unsigned (mp_count);
600
+ std::size_t count;
601
+ if (size_expr.id ()!=ID_constant)
602
+ {
603
+ count=base_address_to_actual_size (offset)/subtype_size;
604
+ }
605
+ else
606
+ {
607
+ mp_integer mp_count;
608
+ to_integer (size_expr, mp_count);
609
+ count=integer2size_t (mp_count);
610
+ }
603
611
604
612
// Retrieve the value for each member in the array
605
613
result.reserve_operands (count);
606
614
for (unsigned i=0 ; i<count; i++)
607
615
{
608
- const exprt operand=get_value (type.subtype (),
609
- offset+i*subtype_size);
616
+ const exprt operand=get_value (
617
+ type.subtype (),
618
+ offset+i*subtype_size);
610
619
result.copy_to_operands (operand);
611
620
}
612
621
return result;
@@ -663,9 +672,17 @@ exprt interpretert::get_value(
663
672
664
673
// Get size of array
665
674
size_t subtype_size=get_size (type.subtype ());
666
- mp_integer mp_count;
667
- to_integer (size_expr, mp_count);
668
- unsigned count=integer2unsigned (mp_count);
675
+ unsigned count;
676
+ if (unbounded_size (type))
677
+ {
678
+ count=base_address_to_actual_size (offset)/subtype_size;
679
+ }
680
+ else
681
+ {
682
+ mp_integer mp_count;
683
+ to_integer (size_expr, mp_count);
684
+ count=integer2unsigned (mp_count);
685
+ }
669
686
670
687
// Retrieve the value for each member in the array
671
688
result.reserve_operands (count);
@@ -917,7 +934,9 @@ void interpretert::execute_function_call()
917
934
// of the interpreter run to fill it with the corresponding data
918
935
goto_trace_stept &trace_step=steps.get_last_step ();
919
936
std::size_t address=integer2size_t (a);
937
+ #if 0
920
938
const memory_cellt &cell=memory[address];
939
+ #endif
921
940
const irep_idt &identifier=address_to_identifier (address);
922
941
trace_step.identifier =identifier;
923
942
@@ -1113,7 +1132,7 @@ Function: interpretert::build_memory_map
1113
1132
1114
1133
Inputs:
1115
1134
1116
- Outputs: Updtaes the memory map to include variable id if it does
1135
+ Outputs: Updates the memory map to include variable id if it does
1117
1136
not exist
1118
1137
1119
1138
Purpose: Populates dynamic entries of the memory map
@@ -1152,20 +1171,45 @@ mp_integer interpretert::build_memory_map(
1152
1171
return address;
1153
1172
}
1154
1173
1174
+ bool interpretert::unbounded_size (const typet &type)
1175
+ {
1176
+ if (type.id ()==ID_array)
1177
+ {
1178
+ const exprt &size=to_array_type (type).size ();
1179
+ if (size.id ()==ID_infinity)
1180
+ return true ;
1181
+ return unbounded_size (type.subtype ());
1182
+ }
1183
+ else if (type.id ()==ID_struct)
1184
+ {
1185
+ const auto &st=to_struct_type (type);
1186
+ if (st.components ().empty ())
1187
+ return false ;
1188
+ return unbounded_size (st.components ().back ().type ());
1189
+ }
1190
+ return false ;
1191
+ }
1192
+
1155
1193
/* ******************************************************************\
1156
1194
1157
1195
Function: interpretert::get_size
1158
1196
1159
1197
Inputs:
1198
+ type - a structured type
1160
1199
1161
- Outputs:
1200
+ Outputs: Size of the given type
1162
1201
1163
- Purpose: Retrieves the actual size of the provided structured type
1202
+ Purpose: Retrieves the actual size of the provided structured type.
1203
+ Unbounded objects get allocated 2^32 address space each
1204
+ (of a 2^64 sized space).
1164
1205
1165
1206
\*******************************************************************/
1166
1207
1167
1208
size_t interpretert::get_size (const typet &type)
1168
1209
{
1210
+ if (unbounded_size (type))
1211
+ return 2ULL << 32ULL ;
1212
+
1169
1213
if (type.id ()==ID_struct)
1170
1214
{
1171
1215
const struct_typet::componentst &components=
@@ -1253,7 +1297,7 @@ exprt interpretert::get_value(const irep_idt &id)
1253
1297
symbol_exprt symbol_expr (id, get_type);
1254
1298
mp_integer whole_lhs_object_address=evaluate_address (symbol_expr);
1255
1299
1256
- return get_value (get_type, integer2unsigned (whole_lhs_object_address));
1300
+ return get_value (get_type, integer2size_t (whole_lhs_object_address));
1257
1301
}
1258
1302
1259
1303
/* ******************************************************************\
@@ -1295,10 +1339,13 @@ Function: interpretert::print_memory
1295
1339
1296
1340
void interpretert::print_memory (bool input_flags)
1297
1341
{
1298
- for (size_t i= 0 ; i<memory. size (); i++ )
1342
+ for (const auto &cell_address : memory )
1299
1343
{
1300
- memory_cellt &cell=memory[i];
1301
- debug () << cell.identifier << " [" << cell.offset << " ]"
1344
+ std::size_t i=cell_address.first ;
1345
+ const memory_cellt &cell=cell_address.second ;
1346
+ const auto identifier=address_to_identifier (i);
1347
+ const auto offset=address_to_offset (i);
1348
+ debug () << identifier << " [" << offset << " ]"
1302
1349
<< " =" << cell.value << eom;
1303
1350
if (input_flags)
1304
1351
debug () << " (" << static_cast <int >(cell.initialized ) << " )"
0 commit comments