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) ...@@ -1472,7 +1472,8 @@ void set_default_size(ir_type *tp, unsigned size)
void default_layout_compound_type(ir_type *type) void default_layout_compound_type(ir_type *type)
{ {
int size = 0; unsigned size = 0;
int offset = 0;
unsigned align_all = 1; unsigned align_all = 1;
bool var_size = is_compound_variable_size(type); bool var_size = is_compound_variable_size(type);
for (size_t i = 0, n = get_compound_n_members(type); i < n; ++i) { for (size_t i = 0, n = get_compound_n_members(type); i < n; ++i) {
...@@ -1493,16 +1494,21 @@ void default_layout_compound_type(ir_type *type) ...@@ -1493,16 +1494,21 @@ void default_layout_compound_type(ir_type *type)
entity_size = 0; entity_size = 0;
} }
unsigned align = get_type_alignment_bytes(entity_type); unsigned align = get_type_alignment_bytes(entity_type);
unsigned misalign = (align ? size % align : 0); unsigned misalign = (align ? offset % align : 0);
size += (misalign ? align - misalign : 0); offset += (misalign ? align - misalign : 0);
align_all = align > align_all ? align : align_all; align_all = align > align_all ? align : align_all;
set_entity_offset(entity, size); set_entity_offset(entity, offset);
if (!is_Union_type(type)) { 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) { if (align_all > 0 && size % align_all) {
size += align_all - (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