Skip to content

Commit b63eb99

Browse files
author
Daniel Kroening
authored
Merge pull request diffblue#1418 from diffblue/address_of_unions
rewrite_union: fix address_of unions
2 parents e82701a + 2adc013 commit b63eb99

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/goto-symex/rewrite_union.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,42 @@ static bool have_to_rewrite_union(
4242
return false;
4343
}
4444

45+
// inside an address of (&x), unions can simply
46+
// be type casts and don't have to be re-written!
47+
void rewrite_union_address_of(
48+
exprt &expr,
49+
const namespacet &ns)
50+
{
51+
if(!have_to_rewrite_union(expr, ns))
52+
return;
53+
54+
if(expr.id()==ID_index)
55+
{
56+
rewrite_union_address_of(to_index_expr(expr).array(), ns);
57+
rewrite_union(to_index_expr(expr).index(), ns);
58+
}
59+
else if(expr.id()==ID_member)
60+
rewrite_union_address_of(to_member_expr(expr).struct_op(), ns);
61+
else if(expr.id()==ID_symbol)
62+
{
63+
// done!
64+
}
65+
else if(expr.id()==ID_dereference)
66+
rewrite_union(to_dereference_expr(expr).pointer(), ns);
67+
}
68+
4569
/// We rewrite u.c for unions u into byte_extract(u, 0), and { .c = v } into
4670
/// byte_update(NIL, 0, v)
4771
void rewrite_union(
4872
exprt &expr,
4973
const namespacet &ns)
5074
{
75+
if(expr.id()==ID_address_of)
76+
{
77+
rewrite_union_address_of(to_address_of_expr(expr).object(), ns);
78+
return;
79+
}
80+
5181
if(!have_to_rewrite_union(expr, ns))
5282
return;
5383

0 commit comments

Comments
 (0)