From 8e4233b86a1e688facd23e7cf80ef9f6127dddaa Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sun, 8 Oct 2017 15:19:01 +0100 Subject: [PATCH] Correct union size --- src/types.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types.cpp b/src/types.cpp index bb9e95667..313c75a35 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1877,7 +1877,6 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) { return gb_clamp(t->Union.custom_align, 1, build_context.max_align); } - i64 max = union_tag_size(t); for_array(i, t->Union.variants) { Type *variant = t->Union.variants[i]; @@ -2126,12 +2125,13 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) { } } - // NOTE(bill): Align to int - i64 size = align_formula(max, build_context.word_size); + // NOTE(bill): Align to tag + i64 tag_size = union_tag_size(t); + i64 size = align_formula(max, tag_size); // NOTE(bill): Calculate the padding between the common fields and the tag t->Union.variant_block_size = size - field_size; - size += type_size_of(allocator, t_int); + size += tag_size; size = align_formula(size, align); return size; } break;