Fix struct #packed alignment calculation

This commit is contained in:
Ginger Bill
2017-08-12 20:04:35 +01:00
parent d7bd3f8402
commit 4262c125c5
4 changed files with 18 additions and 9 deletions

View File

@@ -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;