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