[hackers] [scc] [cc1] Fix inferred array sizes || Michael Forney

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 21:58:11 +0100 (CET)

commit 0a4e0d2b962c78c25dca1099ddc66b9660951538
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri Feb 17 11:54:53 2017 -0800
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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
_AT_@ -256,7 +256,7 @@ deftype(Type *tp)
 }
 
 static Type *
-newtype(Type *base, int defined)
+newtype(Type *base)
 {
         Type *tp;
 
_AT_@ -269,7 +269,7 @@ newtype(Type *base, int defined)
                 tp->next = localtypes;
                 localtypes = tp;
         }
- if (defined)
+ if (tp->prop & TDEFINED)
                 deftype(tp);
         return tp;
 }
_AT_@ -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;
_AT_@ -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;
_AT_@ -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();
         }
_AT_@ -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;
 
Received on Fri Feb 17 2017 - 21:58:11 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 22:00:25 CET