Skip to content

rewrite_union: fix address_of unions #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/goto-symex/rewrite_union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,42 @@ static bool have_to_rewrite_union(
return false;
}

// inside an address of (&x), unions can simply
// be type casts and don't have to be re-written!
void rewrite_union_address_of(
exprt &expr,
const namespacet &ns)
{
if(!have_to_rewrite_union(expr, ns))
return;

if(expr.id()==ID_index)
{
rewrite_union_address_of(to_index_expr(expr).array(), ns);
rewrite_union(to_index_expr(expr).index(), ns);
}
else if(expr.id()==ID_member)
rewrite_union_address_of(to_member_expr(expr).struct_op(), ns);
else if(expr.id()==ID_symbol)
{
// done!
}
else if(expr.id()==ID_dereference)
rewrite_union(to_dereference_expr(expr).pointer(), ns);
}

/// We rewrite u.c for unions u into byte_extract(u, 0), and { .c = v } into
/// byte_update(NIL, 0, v)
void rewrite_union(
exprt &expr,
const namespacet &ns)
{
if(expr.id()==ID_address_of)
{
rewrite_union_address_of(to_address_of_expr(expr).object(), ns);
return;
}

if(!have_to_rewrite_union(expr, ns))
return;

Expand Down