Skip to content

Commit 25abf15

Browse files
authored
Merge pull request #7352 from tautschnig/bugfixes/struct-union-empty
Byte-operator lowering: struct and union constants are not ID_constant
2 parents 20535ad + 54369a6 commit 25abf15

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/util/lower_byte_operators.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ static struct_exprt bv_to_struct_expr(
9898

9999
if(component_bits == 0)
100100
{
101-
operands.push_back(constant_exprt{irep_idt{}, comp.type()});
101+
operands.push_back(
102+
bv_to_expr(bitvector_expr, comp.type(), endianness_map, ns));
102103
continue;
103104
}
104105

@@ -123,17 +124,16 @@ static struct_exprt bv_to_struct_expr(
123124

124125
/// Convert a bitvector-typed expression \p bitvector_expr to a union-typed
125126
/// expression. See \ref bv_to_expr for an overview.
126-
static union_exprt bv_to_union_expr(
127+
static exprt bv_to_union_expr(
127128
const exprt &bitvector_expr,
128129
const union_typet &union_type,
129130
const endianness_mapt &endianness_map,
130131
const namespacet &ns)
131132
{
132133
const union_typet::componentst &components = union_type.components();
133134

134-
// empty union, handled the same way as done in expr_initializert
135135
if(components.empty())
136-
return union_exprt{irep_idt{}, nil_exprt{}, union_type};
136+
return empty_union_exprt{union_type};
137137

138138
const auto widest_member = union_type.find_widest_union_component(ns);
139139

@@ -147,7 +147,7 @@ static union_exprt bv_to_union_expr(
147147
{
148148
return union_exprt{
149149
components.front().get_name(),
150-
constant_exprt{irep_idt{}, components.front().type()},
150+
bv_to_expr(bitvector_expr, components.front().type(), endianness_map, ns),
151151
union_type};
152152
}
153153

@@ -371,13 +371,13 @@ static exprt bv_to_expr(
371371
}
372372
else if(target_type.id() == ID_union_tag)
373373
{
374-
union_exprt result = bv_to_union_expr(
374+
exprt result = bv_to_union_expr(
375375
bitvector_expr,
376376
ns.follow_tag(to_union_tag_type(target_type)),
377377
endianness_map,
378378
ns);
379379
result.type() = target_type;
380-
return std::move(result);
380+
return result;
381381
}
382382
else if(target_type.id() == ID_array)
383383
{

src/util/simplify_expr_struct.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,20 @@ simplify_exprt::simplify_member(const member_exprt &expr)
104104
}
105105
}
106106
}
107-
else if(op.id()==ID_struct ||
108-
op.id()==ID_constant)
107+
else if(op.id() == ID_struct)
109108
{
110-
if(op_type.id()==ID_struct)
109+
// pull out the right member
110+
const struct_typet &struct_type = to_struct_type(op_type);
111+
if(struct_type.has_component(component_name))
111112
{
112-
// pull out the right member
113-
const struct_typet &struct_type=to_struct_type(op_type);
114-
if(struct_type.has_component(component_name))
115-
{
116-
std::size_t number=struct_type.component_number(component_name);
117-
DATA_INVARIANT(
118-
op.operands()[number].type() == expr.type(),
119-
"member expression type must match component type");
120-
return op.operands()[number];
121-
}
113+
std::size_t number = struct_type.component_number(component_name);
114+
DATA_INVARIANT(
115+
op.operands().size() > number,
116+
"struct expression must have sufficiently many operands");
117+
DATA_INVARIANT(
118+
op.operands()[number].type() == expr.type(),
119+
"member expression type must match component type");
120+
return op.operands()[number];
122121
}
123122
}
124123
else if(op.id()==ID_byte_extract_little_endian ||

0 commit comments

Comments
 (0)