diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-05-10 22:51:35 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-05-10 22:51:35 +0100 |
| commit | 87f1a62ca4280105eb845e5bae3acd8b8a0a0810 (patch) | |
| tree | bf791a7d0a593f75165f73bb45a4e718fbda9b67 /src/types.c | |
| parent | c6d531df9597253ee95593c56e61039fe4e40ba2 (diff) | |
Fix alignment for normal structures to match LLVM
Diffstat (limited to 'src/types.c')
| -rw-r--r-- | src/types.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/types.c b/src/types.c index c67dc11ef..b4a2248cf 100644 --- a/src/types.c +++ b/src/types.c @@ -1614,31 +1614,23 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) { return gb_clamp(t->Record.custom_align, 1, build_context.max_align); } if (t->Record.field_count > 0) { - // TODO(bill): What is this supposed to be? + i64 max = 1; if (t->Record.is_packed) { - i64 max = build_context.word_size; - for (isize i = 0; i < t->Record.field_count; i++) { - Type *field_type = t->Record.fields[i]->type; - type_path_push(path, field_type); - if (path->failure) { - return FAILURE_ALIGNMENT; - } - i64 align = type_align_of_internal(allocator, field_type, path); - type_path_pop(path); - if (max < align) { - max = align; - } - } - return max; + max = build_context.word_size; } - Type *field_type = t->Record.fields[0]->type; - type_path_push(path, field_type); - if (path->failure) { - return FAILURE_ALIGNMENT; + for (isize i = 0; i < t->Record.field_count; i++) { + Type *field_type = t->Record.fields[i]->type; + type_path_push(path, field_type); + if (path->failure) { + return FAILURE_ALIGNMENT; + } + i64 align = type_align_of_internal(allocator, field_type, path); + type_path_pop(path); + if (max < align) { + max = align; + } } - i64 align = type_align_of_internal(allocator, field_type, path); - type_path_pop(path); - return align; + return max; } break; case TypeRecord_Union: { |