From c61fd3a70ad3d98152939321bd1a33a57a85d559 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 28 Apr 2019 20:34:51 +0100 Subject: Modify type_set_offsets to patch minor bug --- src/types.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index 5aa2ab6e1..9960d50a0 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2409,7 +2409,7 @@ i64 type_align_of_internal(Type *t, TypePath *path) { return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.word_size); } -Array type_set_offsets_of(Array fields, bool is_packed, bool is_raw_union) { +Array type_set_offsets_of(Array const &fields, bool is_packed, bool is_raw_union) { gbAllocator a = heap_allocator(); auto offsets = array_make(a, fields.count); i64 curr_offset = 0; @@ -2442,6 +2442,7 @@ bool type_set_offsets(Type *t) { if (!t->Struct.are_offsets_set) { t->Struct.are_offsets_being_processed = true; t->Struct.offsets = type_set_offsets_of(t->Struct.fields, t->Struct.is_packed, t->Struct.is_raw_union); + GB_ASSERT(t->Struct.offsets.count == t->Struct.fields.count); t->Struct.are_offsets_being_processed = false; t->Struct.are_offsets_set = true; return true; @@ -2603,7 +2604,14 @@ i64 type_size_of_internal(Type *t, TypePath *path) { type_path_print_illegal_cycle(path, path->path.count-1); return FAILURE_SIZE; } + if (t->Struct.are_offsets_set && t->Struct.offsets.count != t->Struct.fields.count) { + // TODO(bill, 2019-04-28): Determine exactly why the offsets length is different thatn the field length + // Are the the same at some point and then the struct length is increased? + // Why is this not handled by the type cycle checker? + t->Struct.are_offsets_set = false; + } type_set_offsets(t); + GB_ASSERT_MSG(t->Struct.offsets.count == t->Struct.fields.count, "%s", type_to_string(t)); size = t->Struct.offsets[cast(isize)count-1] + type_size_of_internal(t->Struct.fields[cast(isize)count-1]->type, path); return align_formula(size, align); } -- cgit v1.2.3