scc

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

commit 0a4e0d2b962c78c25dca1099ddc66b9660951538
parent 123d9473c025b4846e8f3b215bcc42606290c77e
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 17 Feb 2017 11:54:53 -0800

[cc1] Fix inferred array sizes

It seems most everything was in place for this, but mktype was
unconditionally defining the incomplete array type by passing 1 to
newtype. Instead, make newtype use t.prop & TDEFINED to decide whether
to call deftype.

Also, call deftype in initlist to compute the size and emit the type IR.

This fixes 0096-inferredarraysize.c.

Diffstat:
Mcc1/init.c | 2+-
Mcc1/types.c | 12+++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/cc1/init.c b/cc1/init.c @@ -277,7 +277,7 @@ initlist(Type *tp) if (tp->op == ARY && !(tp->prop & TDEFINED)) { tp->n.elem = in.max; - tp->prop |= TDEFINED; + deftype(tp); } if (tp->op == ARY || tp->op == STRUCT) in.max = tp->n.elem; diff --git a/cc1/types.c b/cc1/types.c @@ -256,7 +256,7 @@ deftype(Type *tp) } static Type * -newtype(Type *base, int defined) +newtype(Type *base) { Type *tp; @@ -269,7 +269,7 @@ newtype(Type *base, int defined) tp->next = localtypes; localtypes = tp; } - if (defined) + if (tp->prop & TDEFINED) deftype(tp); return tp; } @@ -296,7 +296,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) type.prop |= TDEFINED; break; case KRFTN: - type.prop |= TK_R; + type.prop |= TDEFINED | TK_R; type.op = FTN; type.letter = L_FUNCTION; break; @@ -304,9 +304,11 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) if (nelem > 0 && pars[nelem-1] == ellipsistype) type.prop |= TELLIPSIS; type.letter = L_FUNCTION; + type.prop |= TDEFINED; break; case PTR: type.letter = L_POINTER; + type.prop |= TDEFINED; break; case ENUM: type.letter = inttype->letter; @@ -321,7 +323,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) type.letter = L_UNION; type.prop |= TAGGREG; create_type: - return newtype(&type, 0); + return newtype(&type); default: abort(); } @@ -339,7 +341,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) } } - bp = newtype(&type, 1); + bp = newtype(&type); bp->h_next = *tbl; *tbl = bp;