Skip to content

Commit b2c5cf1

Browse files
author
Daniel Kroening
committed
smt2: convert struct_tag and union_tag types
1 parent a7fc931 commit b2c5cf1

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ void smt2_convt::convert_address_of_rec(
556556
const typet &struct_op_type=ns.follow(struct_op.type());
557557

558558
DATA_INVARIANT(
559-
struct_op_type.id() == ID_struct,
559+
struct_op_type.id() == ID_struct || struct_op_type.id() == ID_struct_tag,
560560
"member expression operand shall have struct type");
561561

562-
const struct_typet &struct_type = to_struct_type(struct_op_type);
562+
const struct_typet &struct_type = to_struct_type(ns.follow(struct_op_type));
563563

564564
const irep_idt &component_name = member_expr.get_component_name();
565565

@@ -2140,7 +2140,9 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
21402140
else
21412141
SMT2_TODO("can't convert non-constant integer to bitvector");
21422142
}
2143-
else if(src_type.id()==ID_struct) // flatten a struct to a bit-vector
2143+
else if(
2144+
src_type.id() == ID_struct ||
2145+
src_type.id() == ID_struct_tag) // flatten a struct to a bit-vector
21442146
{
21452147
if(use_datatypes)
21462148
{
@@ -2157,7 +2159,9 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
21572159
convert_expr(src); // nothing else to do!
21582160
}
21592161
}
2160-
else if(src_type.id()==ID_union) // flatten a union
2162+
else if(
2163+
src_type.id() == ID_union ||
2164+
src_type.id() == ID_union_tag) // flatten a union
21612165
{
21622166
INVARIANT(
21632167
boolbv_width(src_type) == boolbv_width(dest_type),
@@ -2570,7 +2574,7 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
25702574

25712575
void smt2_convt::convert_struct(const struct_exprt &expr)
25722576
{
2573-
const struct_typet &struct_type=to_struct_type(expr.type());
2577+
const struct_typet &struct_type = to_struct_type(ns.follow(expr.type()));
25742578

25752579
const struct_typet::componentst &components=
25762580
struct_type.components();
@@ -2664,7 +2668,7 @@ void smt2_convt::flatten_array(const exprt &expr)
26642668

26652669
void smt2_convt::convert_union(const union_exprt &expr)
26662670
{
2667-
const union_typet &union_type=to_union_type(expr.type());
2671+
const union_typet &union_type = to_union_type(ns.follow(expr.type()));
26682672
const exprt &op=expr.op();
26692673

26702674
boolbv_widtht boolbv_width(ns);
@@ -3551,9 +3555,9 @@ void smt2_convt::convert_with(const with_exprt &expr)
35513555
out << ") distance?)))"; // zero_extend, bvlshr, bvor, let
35523556
}
35533557
}
3554-
else if(expr_type.id()==ID_struct)
3558+
else if(expr_type.id() == ID_struct || expr_type.id() == ID_struct_tag)
35553559
{
3556-
const struct_typet &struct_type=to_struct_type(expr_type);
3560+
const struct_typet &struct_type = to_struct_type(ns.follow(expr_type));
35573561

35583562
const exprt &index=expr.op1();
35593563
const exprt &value=expr.op2();
@@ -3621,9 +3625,9 @@ void smt2_convt::convert_with(const with_exprt &expr)
36213625
out << ")"; // let ?withop
36223626
}
36233627
}
3624-
else if(expr_type.id()==ID_union)
3628+
else if(expr_type.id() == ID_union || expr_type.id() == ID_union_tag)
36253629
{
3626-
const union_typet &union_type=to_union_type(expr_type);
3630+
const union_typet &union_type = to_union_type(ns.follow(expr_type));
36273631

36283632
const exprt &value=expr.op2();
36293633

@@ -3827,10 +3831,9 @@ void smt2_convt::convert_member(const member_exprt &expr)
38273831
const typet &struct_op_type=ns.follow(struct_op.type());
38283832
const irep_idt &name=member_expr.get_component_name();
38293833

3830-
if(struct_op_type.id()==ID_struct)
3834+
if(struct_op_type.id() == ID_struct || struct_op_type.id() == ID_struct_tag)
38313835
{
3832-
const struct_typet &struct_type=
3833-
to_struct_type(struct_op_type);
3836+
const struct_typet &struct_type = to_struct_type(ns.follow(struct_op_type));
38343837

38353838
INVARIANT(
38363839
struct_type.has_component(name), "struct should have accessed component");
@@ -3860,7 +3863,8 @@ void smt2_convt::convert_member(const member_exprt &expr)
38603863
out << ")";
38613864
}
38623865
}
3863-
else if(struct_op_type.id()==ID_union)
3866+
else if(
3867+
struct_op_type.id() == ID_union || struct_op_type.id() == ID_union_tag)
38643868
{
38653869
std::size_t width=boolbv_width(expr.type());
38663870
CHECK_RETURN_WITH_DIAGNOSTICS(
@@ -3922,14 +3926,14 @@ void smt2_convt::flatten2bv(const exprt &expr)
39223926
{
39233927
convert_expr(expr);
39243928
}
3925-
else if(type.id()==ID_struct)
3929+
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
39263930
{
39273931
if(use_datatypes)
39283932
{
39293933
const std::string &smt_typename = datatype_map.at(type);
39303934

39313935
// concatenate elements
3932-
const struct_typet &struct_type=to_struct_type(type);
3936+
const struct_typet &struct_type = to_struct_type(ns.follow(type));
39333937

39343938
out << "(let ((?sflop ";
39353939
convert_expr(expr);
@@ -4025,7 +4029,7 @@ void smt2_convt::unflatten(
40254029
// nop, already a bv
40264030
}
40274031
}
4028-
else if(type.id()==ID_struct)
4032+
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
40294033
{
40304034
if(use_datatypes)
40314035
{
@@ -4040,7 +4044,7 @@ void smt2_convt::unflatten(
40404044

40414045
out << "(mk-" << smt_typename;
40424046

4043-
const struct_typet &struct_type=to_struct_type(type);
4047+
const struct_typet &struct_type = to_struct_type(ns.follow(type));
40444048

40454049
const struct_typet::componentst &components=
40464050
struct_type.components();
@@ -4411,7 +4415,7 @@ void smt2_convt::convert_type(const typet &type)
44114415
{
44124416
out << "Bool";
44134417
}
4414-
else if(type.id()==ID_struct)
4418+
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
44154419
{
44164420
if(use_datatypes)
44174421
{
@@ -4450,7 +4454,7 @@ void smt2_convt::convert_type(const typet &type)
44504454
// member count.
44514455
out << "Bool";
44524456
}
4453-
else if(type.id()==ID_union)
4457+
else if(type.id() == ID_union || type.id() == ID_union_tag)
44544458
{
44554459
boolbv_widtht boolbv_width(ns);
44564460

@@ -4602,7 +4606,7 @@ void smt2_convt::find_symbols_rec(
46024606
out << "))))\n";
46034607
}
46044608
}
4605-
else if(type.id()==ID_struct)
4609+
else if(type.id() == ID_struct)
46064610
{
46074611
// Cater for mutually recursive struct types
46084612
bool need_decl=false;
@@ -4615,11 +4619,11 @@ void smt2_convt::find_symbols_rec(
46154619
need_decl=true;
46164620
}
46174621

4618-
const struct_typet::componentst &components=
4622+
const struct_typet::componentst &components =
46194623
to_struct_type(type).components();
46204624

4621-
for(const auto &component : components)
4622-
find_symbols_rec(component.type(), recstack);
4625+
for(const auto &component : components)
4626+
find_symbols_rec(component.type(), recstack);
46234627

46244628
// Declare the corresponding SMT type if we haven't already.
46254629
if(need_decl)
@@ -4698,9 +4702,9 @@ void smt2_convt::find_symbols_rec(
46984702
out << "\n";
46994703
}
47004704
}
4701-
else if(type.id()==ID_union)
4705+
else if(type.id() == ID_union)
47024706
{
4703-
const union_typet::componentst &components=
4707+
const union_typet::componentst &components =
47044708
to_union_type(type).components();
47054709

47064710
for(const auto &component : components)
@@ -4730,6 +4734,28 @@ void smt2_convt::find_symbols_rec(
47304734
find_symbols_rec(ns.follow(type), recstack);
47314735
}
47324736
}
4737+
else if(type.id() == ID_struct_tag)
4738+
{
4739+
const auto &struct_tag = to_struct_tag_type(type);
4740+
const irep_idt &id = struct_tag.get_identifier();
4741+
4742+
if(recstack.find(id) == recstack.end())
4743+
{
4744+
recstack.insert(id);
4745+
find_symbols_rec(ns.follow_tag(struct_tag), recstack);
4746+
}
4747+
}
4748+
else if(type.id() == ID_union_tag)
4749+
{
4750+
const auto &union_tag = to_union_tag_type(type);
4751+
const irep_idt &id = union_tag.get_identifier();
4752+
4753+
if(recstack.find(id) == recstack.end())
4754+
{
4755+
recstack.insert(id);
4756+
find_symbols_rec(ns.follow_tag(union_tag), recstack);
4757+
}
4758+
}
47334759
}
47344760

47354761
exprt smt2_convt::letify(exprt &expr)

0 commit comments

Comments
 (0)