Skip to content

Commit ac31213

Browse files
committed
Simplify initializer to remove byte_update
We introduce byte updates to soundly prepare union initializers, but such byte updates are not part of the C standard and thus aren't expected by dump-c. Run simplify to clean them up, when possible.
1 parent ed75598 commit ac31213

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ exprt c_typecheck_baset::do_initializer_rec(
7272
}
7373

7474
if(value.id()==ID_initializer_list)
75-
return do_initializer_list(value, type, force_constant);
75+
{
76+
return simplify_expr(
77+
do_initializer_list(value, type, force_constant), *this);
78+
}
7679

7780
if(
7881
value.id() == ID_array && value.get_bool(ID_C_string_constant) &&

src/ansi-c/expr2c.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,12 +1911,8 @@ std::string expr2ct::convert_constant(
19111911
if(type.subtype().id()!=ID_empty)
19121912
dest="(("+convert(type)+")"+dest+")";
19131913
}
1914-
else
1914+
else if(src.operands().size() == 1)
19151915
{
1916-
// we prefer the annotation
1917-
if(src.operands().size()!=1)
1918-
return convert_norep(src, precedence);
1919-
19201916
const auto &annotation = to_unary_expr(src).op();
19211917

19221918
if(annotation.id() == ID_constant)
@@ -1933,6 +1929,12 @@ std::string expr2ct::convert_constant(
19331929
else
19341930
return convert_with_precedence(annotation, precedence);
19351931
}
1932+
else
1933+
{
1934+
const auto width = to_pointer_type(type).get_width();
1935+
mp_integer int_value = bvrep2integer(value, width, false);
1936+
return "(" + convert(type) + ")" + integer2string(int_value);
1937+
}
19361938
}
19371939
else if(type.id()==ID_string)
19381940
{

0 commit comments

Comments
 (0)