scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit b140b6aa1a408ef2e6693ed093d82432583a3be5
parent 27b5cb7089f903689568e99e95e3b32dd7fce2e6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  1 Dec 2016 09:25:58 +0100

[cc1] Call to typesize() in all the defined types

Typesize() fills the size and aligment fields of new
types, but it cannot be called until the type is defined.
At this point it was called only for structs and enumerations,
but it must be called for any defined type.

Diffstat:
Mcc1/decl.c | 1+
Mcc1/init.c | 1+
Mcc1/types.c | 3+++
3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -554,6 +554,7 @@ enumdcl(void) if (tp->prop & TDEFINED) errorp("redefinition of enumeration '%s'", tagsym->name); tp->prop |= TDEFINED; + typesize(tp); namespace = NS_IDEN; /* TODO: check incorrect values in val */ diff --git a/cc1/init.c b/cc1/init.c @@ -121,6 +121,7 @@ initialize(Type *tp) if (!(tp->prop & TDEFINED)) { tp->prop |= TDEFINED; tp->n.elem = len+1; + typesize(tp); } else if (tp->n.elem < len) { warn("initializer-string for array of chars is too long"); } diff --git a/cc1/types.c b/cc1/types.c @@ -263,6 +263,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) case UNION: c = L_UNION; break; } + memset(&type, 0, sizeof(type)); type.type = tp; type.op = op; type.prop = k_r ? TK_R : 0; @@ -306,6 +307,8 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) } } + if (type.prop & TDEFINED) + typesize(&type); bp = xmalloc(sizeof(*bp)); *bp = type; bp->id = newid();