commit 0a4e0d2b962c78c25dca1099ddc66b9660951538
Author:     Michael Forney <[email protected]>
AuthorDate: Fri Feb 17 11:54:53 2017 -0800
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Feb 17 21:55:36 2017 +0100

    [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.

diff --git a/cc1/init.c b/cc1/init.c
index 468a3b9..febfe35 100644
--- 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
index ed20f23..f9d6391 100644
--- 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;
 

Reply via email to