From 4262c125c5c56db61c57e090ea76db61c16bcebc Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 12 Aug 2017 20:04:35 +0100 Subject: Fix struct #packed alignment calculation --- src/types.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index dd05f3238..dec7428eb 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1864,21 +1864,20 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) { return max; } else if (t->Struct.fields.count > 0) { i64 max = 1; - if (t->Struct.is_packed) { - max = build_context.word_size; - } + // NOTE(bill): Check the fields to check for cyclic definitions for_array(i, t->Struct.fields) { Type *field_type = t->Struct.fields[i]->type; type_path_push(path, field_type); - if (path->failure) { - return FAILURE_ALIGNMENT; - } + 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; } } + if (t->Struct.is_packed) { + return 1; + } return max; } } break; -- cgit v1.2.3