Commit f95107e4 authored by Matthias Braun's avatar Matthias Braun
Browse files

fix default_layout_compound_type for unions

parent b4cf7f2c
......@@ -1472,7 +1472,8 @@ void set_default_size(ir_type *tp, unsigned size)
void default_layout_compound_type(ir_type *type)
{
int size = 0;
unsigned size = 0;
int offset = 0;
unsigned align_all = 1;
bool var_size = is_compound_variable_size(type);
for (size_t i = 0, n = get_compound_n_members(type); i < n; ++i) {
......@@ -1494,15 +1495,20 @@ void default_layout_compound_type(ir_type *type)
}
unsigned align = get_type_alignment_bytes(entity_type);
unsigned misalign = (align ? size % align : 0);
size += (misalign ? align - misalign : 0);
unsigned misalign = (align ? offset % align : 0);
offset += (misalign ? align - misalign : 0);
align_all = align > align_all ? align : align_all;
set_entity_offset(entity, size);
set_entity_offset(entity, offset);
if (!is_Union_type(type)) {
size += entity_size;
offset += entity_size;
} else if (entity_size > size) {
size = entity_size;
}
}
if (!is_Union_type(type))
size = offset;
if (align_all > 0 && size % align_all) {
size += align_all - (size % align_all);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment