harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 73ef2391dfc5311c9279667e3b8659a60f8faf26
parent 4a99171eb347382a7aeec4191f47135da9604009
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Mar 2021 09:34:13 -0500

type store: various fixes for struct types

Diffstat:
Msrc/type_store.c | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -145,7 +145,6 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, field->name = strdup(atype->field.name); field->type = type_store_lookup_atype(store, atype->field.type); - assert(field->type->size != SIZE_UNDEFINED); if (atype->offset) { *ccompat = false; @@ -163,21 +162,22 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, field->offset = offs; assert(offs % field->type->align == 0); // TODO? } else { - *size += *size % field->type->align; - field->offset = *size; + size_t offs = *size; + if (offs % field->type->align) { + offs += field->type->align - (offs % field->type->align); + } + field->offset = offs; + assert(field->offset % field->type->align == 0); } - if (storage == STORAGE_STRUCT) { - *size += field->type->size; + if (field->type->size == SIZE_UNDEFINED || *size == SIZE_UNDEFINED) { + *size = SIZE_UNDEFINED; + } else if (storage == STORAGE_STRUCT) { + *size = field->offset + field->type->size; } else { *usize = field->type->size > *usize ? field->type->size : *usize; } *align = field->type->align > *align ? field->type->align : *align; - - if (!atype->offset) { - assert(field->offset % field->type->align == 0); - assert(field->offset % *align == 0); - } } static void