@@ -612,21 +612,14 @@ smt2_convt::parse_struct(const irept &src, const struct_typet &type)
612
612
{
613
613
// Structs look like:
614
614
// (mk-struct.1 <component0> <component1> ... <componentN>)
615
- std::size_t j = 1 ;
615
+
616
+ if (src.get_sub ().size ()!=components.size ()+1 )
617
+ return result; // give up
618
+
616
619
for (std::size_t i=0 ; i<components.size (); i++)
617
620
{
618
621
const struct_typet::componentt &c=components[i];
619
- if (is_zero_width (components[i].type (), ns))
620
- {
621
- result.operands ()[i] = nil_exprt{};
622
- }
623
- else
624
- {
625
- DATA_INVARIANT (
626
- src.get_sub ().size () > j, " insufficient number of component values" );
627
- result.operands ()[i] = parse_rec (src.get_sub ()[j], c.type ());
628
- ++j;
629
- }
622
+ result.operands ()[i]=parse_rec (src.get_sub ()[i+1 ], c.type ());
630
623
}
631
624
}
632
625
else
@@ -3225,8 +3218,6 @@ void smt2_convt::convert_struct(const struct_exprt &expr)
3225
3218
" number of struct components as indicated by the struct type shall be equal"
3226
3219
" to the number of operands of the struct expression" );
3227
3220
3228
- DATA_INVARIANT (!components.empty (), " struct shall have struct components" );
3229
-
3230
3221
if (use_datatypes)
3231
3222
{
3232
3223
const std::string &smt_typename = datatype_map.at (struct_type);
@@ -3240,16 +3231,29 @@ void smt2_convt::convert_struct(const struct_exprt &expr)
3240
3231
it!=components.end ();
3241
3232
it++, i++)
3242
3233
{
3243
- if (is_zero_width (it->type (), ns))
3234
+ if (
3235
+ it->type ().id () != ID_struct_tag && it->type ().id () != ID_struct &&
3236
+ is_zero_width (it->type (), ns))
3237
+ {
3244
3238
continue ;
3239
+ }
3240
+
3245
3241
out << " " ;
3246
3242
convert_expr (expr.operands ()[i]);
3247
3243
}
3248
3244
3245
+ if (components.empty ())
3246
+ {
3247
+ out << " " ;
3248
+ convert_expr (from_integer (0 , unsignedbv_typet{1 }));
3249
+ }
3250
+
3249
3251
out << " )" ;
3250
3252
}
3251
3253
else
3252
3254
{
3255
+ DATA_INVARIANT (!components.empty (), " struct shall have struct components" );
3256
+
3253
3257
if (components.size ()==1 )
3254
3258
{
3255
3259
const exprt &op = expr.op0 ();
@@ -4903,9 +4907,6 @@ void smt2_convt::unflatten(
4903
4907
it!=components.end ();
4904
4908
it++, i++)
4905
4909
{
4906
- if (is_zero_width (it->type (), ns))
4907
- continue ;
4908
-
4909
4910
std::size_t member_width=boolbv_width (it->type ());
4910
4911
4911
4912
out << " " ;
@@ -4916,6 +4917,12 @@ void smt2_convt::unflatten(
4916
4917
offset+=member_width;
4917
4918
}
4918
4919
4920
+ if (components.empty ())
4921
+ {
4922
+ out << " " ;
4923
+ convert_expr (from_integer (0 , unsignedbv_typet{1 }));
4924
+ }
4925
+
4919
4926
out << " ))" ; // mk-, let
4920
4927
}
4921
4928
}
@@ -5940,15 +5947,27 @@ void smt2_convt::find_symbols_rec(
5940
5947
5941
5948
for (const auto &component : components)
5942
5949
{
5943
- if (is_zero_width (component.type (), ns))
5950
+ if (
5951
+ component.type ().id () != ID_struct_tag &&
5952
+ component.type ().id () != ID_struct &&
5953
+ is_zero_width (component.type (), ns))
5954
+ {
5944
5955
continue ;
5956
+ }
5945
5957
5946
5958
out << " (" << smt_typename << " ." << component.get_name ()
5947
5959
<< " " ;
5948
5960
convert_type (component.type ());
5949
5961
out << " ) " ;
5950
5962
}
5951
5963
5964
+ if (components.empty ())
5965
+ {
5966
+ out << " (" << smt_typename << " .0 " ;
5967
+ convert_type (unsignedbv_typet{1 });
5968
+ out << " ) " ;
5969
+ }
5970
+
5952
5971
out << " ))))" << " \n " ;
5953
5972
5954
5973
// Let's also declare convenience functions to update individual
0 commit comments