Skip to content

Partly revert "Simplify initializer to remove byte_update" #5780

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
Jan 30, 2021
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions regression/goto-instrument/dump-union2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <assert.h>

struct S2
{
signed char f0;
unsigned short f1;
};

union U10 {
unsigned short f0;
struct S2 f3;
};

union U10 g_2110 = {.f0 = 53747};

union U6 {
signed f0 : 3;
};

union U6 g_1197 = {1L};

int main()
{
assert(g_2110.f0 == 53747);

return 0;
}
11 changes: 11 additions & 0 deletions regression/goto-instrument/dump-union2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--dump-c
VERIFICATION SUCCESSFUL
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
This test must verify successfully also for the output generated using dump-c,
which previously did not correctly represent the union initializer.
5 changes: 1 addition & 4 deletions src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ exprt c_typecheck_baset::do_initializer_rec(
}

if(value.id()==ID_initializer_list)
{
return simplify_expr(
do_initializer_list(value, type, force_constant), *this);
}
return do_initializer_list(value, type, force_constant);

if(
value.id() == ID_array && value.get_bool(ID_C_string_constant) &&
Expand Down
19 changes: 19 additions & 0 deletions src/goto-instrument/dump_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]

#include <util/byte_operators.h>
#include <util/config.h>
#include <util/expr_initializer.h>
#include <util/find_symbols.h>
#include <util/get_base_name.h>
#include <util/invariant.h>
Expand Down Expand Up @@ -1467,6 +1468,24 @@ void dump_ct::cleanup_expr(exprt &expr)
}
}
}
else if(
ns.follow(bu.type()).id() == ID_union &&
bu.source_location().get_function().empty() &&
bu.op() == zero_initializer(bu.op().type(), source_locationt{}, ns)
.value_or(nil_exprt{}))
{
const union_typet &union_type = to_union_type(ns.follow(bu.type()));

for(const auto &comp : union_type.components())
{
if(bu.value().type() == comp.type())
{
union_exprt union_expr{comp.get_name(), bu.value(), bu.type()};
expr.swap(union_expr);
break;
}
}
}
}
}

Expand Down