@@ -8,6 +8,8 @@ Author: Daniel Kroening
8
8
9
9
#include < iostream>
10
10
11
+ #include < util/base_type.h>
12
+ #include < util/byte_operators.h>
11
13
#include < util/config.h>
12
14
#include < util/i2string.h>
13
15
#include < util/arith_tools.h>
@@ -91,32 +93,53 @@ std::string graphml_witnesst::convert_assign_rec(
91
93
else if (assign.rhs ().id ()==ID_struct ||
92
94
assign.rhs ().id ()==ID_union)
93
95
{
96
+ // dereferencing may have resulted in an lhs that is the first
97
+ // struct member; undo this
98
+ if (assign.lhs ().id ()==ID_member &&
99
+ !base_type_eq (assign.lhs ().type (), assign.rhs ().type (), ns))
100
+ {
101
+ code_assignt tmp=assign;
102
+ tmp.lhs ()=to_member_expr (assign.lhs ()).struct_op ();
103
+
104
+ return convert_assign_rec (identifier, tmp);
105
+ }
106
+ else if (assign.lhs ().id ()==ID_byte_extract_little_endian ||
107
+ assign.lhs ().id ()==ID_byte_extract_big_endian)
108
+ {
109
+ code_assignt tmp=assign;
110
+ tmp.lhs ()=to_byte_extract_expr (assign.lhs ()).op ();
111
+
112
+ return convert_assign_rec (identifier, tmp);
113
+ }
114
+
94
115
const struct_union_typet &type=
95
116
to_struct_union_type (ns.follow (assign.lhs ().type ()));
96
117
const struct_union_typet::componentst &components=
97
118
type.components ();
98
119
99
- struct_union_typet::componentst ::const_iterator c_it =
100
- components .begin ();
101
- forall_operands (it, assign. rhs () )
120
+ exprt::operandst ::const_iterator it =
121
+ assign. rhs (). operands () .begin ();
122
+ for ( const auto & comp : components )
102
123
{
103
- if (c_it-> type ().id ()==ID_code ||
104
- c_it-> get_is_padding () ||
124
+ if (comp. type ().id ()==ID_code ||
125
+ comp. get_is_padding () ||
105
126
// for some reason #is_padding gets lost in *some* cases
106
- has_prefix (id2string (c_it->get_name ()), " $pad" ))
107
- {
108
- ++c_it;
127
+ has_prefix (id2string (comp.get_name ()), " $pad" ))
109
128
continue ;
110
- }
111
129
112
- assert (c_it!=components.end ());
130
+ assert (it!=assign.rhs ().operands ().end ());
131
+
113
132
member_exprt member (
114
133
assign.lhs (),
115
- c_it-> get_name (),
134
+ comp. get_name (),
116
135
it->type ());
117
136
if (!result.empty ()) result+=' ' ;
118
137
result+=convert_assign_rec (identifier, code_assignt (member, *it));
119
- ++c_it;
138
+ ++it;
139
+
140
+ // for unions just assign to the first member
141
+ if (assign.rhs ().id ()==ID_union)
142
+ break ;
120
143
}
121
144
}
122
145
else
@@ -404,7 +427,8 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation)
404
427
405
428
if (from==sink)
406
429
{
407
- ++it; ++step_nr;
430
+ ++it;
431
+ ++step_nr;
408
432
continue ;
409
433
}
410
434
0 commit comments