Skip to content

Commit 29bc3b8

Browse files
author
Daniel Kroening
committed
custom_bitvector_domain: allow objects that are members
1 parent ab7270e commit 29bc3b8

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

src/analyses/custom_bitvector_analysis.cpp

+57-19
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ irep_idt custom_bitvector_domaint::object2id(const exprt &src)
8484
return '*'+id2string(op_id);
8585
}
8686
}
87+
else if(src.id()==ID_member)
88+
{
89+
const auto &m=to_member_expr(src);
90+
const exprt &op=m.compound();
91+
92+
irep_idt op_id=object2id(op);
93+
94+
if(op_id.empty())
95+
return irep_idt();
96+
else
97+
return id2string(op_id)+'.'+
98+
id2string(m.get_component_name());
99+
}
87100
else if(src.id()==ID_typecast)
88101
return object2id(to_typecast_expr(src).op());
89102
else
@@ -209,6 +222,49 @@ std::set<exprt> custom_bitvector_analysist::aliases(
209222
return std::set<exprt>();
210223
}
211224

225+
void custom_bitvector_domaint::assign_struct_rec(
226+
locationt from,
227+
const exprt &lhs,
228+
const exprt &rhs,
229+
custom_bitvector_analysist &cba,
230+
const namespacet &ns)
231+
{
232+
if(ns.follow(lhs.type()).id()==ID_struct)
233+
{
234+
const struct_typet &struct_type=
235+
to_struct_type(ns.follow(lhs.type()));
236+
237+
// assign member-by-member
238+
for(const auto &c : struct_type.components())
239+
{
240+
member_exprt lhs_member(lhs, c),
241+
rhs_member(rhs, c);
242+
assign_struct_rec(from, lhs_member, rhs_member, cba, ns);
243+
}
244+
}
245+
else
246+
{
247+
// may alias other stuff
248+
std::set<exprt> lhs_set=cba.aliases(lhs, from);
249+
250+
vectorst rhs_vectors=get_rhs(rhs);
251+
252+
for(const auto &lhs_alias : lhs_set)
253+
{
254+
assign_lhs(lhs_alias, rhs_vectors);
255+
}
256+
257+
// is it a pointer?
258+
if(lhs.type().id()==ID_pointer)
259+
{
260+
dereference_exprt lhs_deref(lhs);
261+
dereference_exprt rhs_deref(rhs);
262+
vectorst rhs_vectors=get_rhs(rhs_deref);
263+
assign_lhs(lhs_deref, rhs_vectors);
264+
}
265+
}
266+
}
267+
212268
void custom_bitvector_domaint::transform(
213269
locationt from,
214270
locationt to,
@@ -226,25 +282,7 @@ void custom_bitvector_domaint::transform(
226282
case ASSIGN:
227283
{
228284
const code_assignt &code_assign=to_code_assign(instruction.code);
229-
230-
// may alias other stuff
231-
std::set<exprt> lhs_set=cba.aliases(code_assign.lhs(), from);
232-
233-
vectorst rhs_vectors=get_rhs(code_assign.rhs());
234-
235-
for(const auto &lhs : lhs_set)
236-
{
237-
assign_lhs(lhs, rhs_vectors);
238-
}
239-
240-
// is it a pointer?
241-
if(code_assign.lhs().type().id()==ID_pointer)
242-
{
243-
dereference_exprt lhs_deref(code_assign.lhs());
244-
dereference_exprt rhs_deref(code_assign.rhs());
245-
vectorst rhs_vectors=get_rhs(rhs_deref);
246-
assign_lhs(lhs_deref, rhs_vectors);
247-
}
285+
assign_struct_rec(from, code_assign.lhs(), code_assign.rhs(), cba, ns);
248286
}
249287
break;
250288

src/analyses/custom_bitvector_analysis.h

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class custom_bitvector_domaint:public ai_domain_baset
9696

9797
bitst may_bits, must_bits;
9898

99+
void assign_struct_rec(
100+
locationt from,
101+
const exprt &lhs,
102+
const exprt &rhs,
103+
custom_bitvector_analysist &,
104+
const namespacet &);
105+
99106
void assign_lhs(const exprt &, const vectorst &);
100107
void assign_lhs(const irep_idt &, const vectorst &);
101108
vectorst get_rhs(const exprt &) const;

0 commit comments

Comments
 (0)