harec

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

commit 3899d4bd6f27663d8256cf48209dbe788bf241ce
parent ff4b568a8f0d8bf8d70695af34240acd69be1c8a
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 14 Aug 2021 14:30:16 +0200

all: fix padding at end of types

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/emit.c | 2+-
Msrc/qtype.c | 6+++++-
Msrc/type_store.c | 5+++++
3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/emit.c b/src/emit.c @@ -51,7 +51,7 @@ qemit_type(const struct qbe_def *def, FILE *out) const struct type *base = def->type.base; if (base) { char *tn = gen_typename(base); - fprintf(out, "# %s [id: %u]\n", tn, base->id); + fprintf(out, "# %s [id: %u; size: %zu]\n", tn, base->id, base->size); free(tn); fprintf(out, "type :%s =", def->name); if (base->align != (size_t)-1) { diff --git a/src/qtype.c b/src/qtype.c @@ -3,8 +3,8 @@ #include <stdio.h> #include "gen.h" #include "qbe.h" -#include "types.h" #include "type_store.h" +#include "types.h" #include "util.h" static int @@ -77,6 +77,10 @@ aggregate_lookup(struct gen_context *ctx, const struct type *type) def->type.base = type; def->type.name = name; + assert(type->size == SIZE_UNDEFINED + || type->size == 0 + || type->size % type->align == 0); + struct qbe_field *field = &def->type.fields; switch (type->storage) { case STORAGE_ARRAY: diff --git a/src/type_store.c b/src/type_store.c @@ -706,6 +706,11 @@ _type_store_lookup_type( bucket = *next = xcalloc(1, sizeof(struct type_bucket)); bucket->type = *type; bucket->type.id = hash; + if (type->size != SIZE_UNDEFINED + && type->size != 0 + && type->size % type->align != 0) { + bucket->type.size += type->align - (type->size - type->align) % type->align; + } return &bucket->type; }