shithub: scc

Download patch

ref: 3b4a9b64611b6b71d9a19754caa6cb23731d7ba6
parent: 81272f61a868aa2d047c2620191b88d4fe9769bd
author: Michael Forney <[email protected]>
date: Fri Feb 17 06:54:53 EST 2017

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

--- a/cc1/init.c
+++ b/cc1/init.c
@@ -277,7 +277,7 @@
 
 	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;
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -256,7 +256,7 @@
 }
 
 static Type *
-newtype(Type *base, int defined)
+newtype(Type *base)
 {
 	Type *tp;
 
@@ -269,7 +269,7 @@
 		tp->next = localtypes;
 		localtypes = tp;
 	}
-	if (defined)
+	if (tp->prop & TDEFINED)
 		deftype(tp);
 	return tp;
 }
@@ -296,7 +296,7 @@
 			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 @@
 		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 @@
 		type.letter = L_UNION;
 		type.prop |= TAGGREG;
 	create_type:
-		return newtype(&type, 0);
+		return newtype(&type);
 	default:
 		abort();
 	}
@@ -339,7 +341,7 @@
 		}
 	}
 
-	bp = newtype(&type, 1);
+	bp = newtype(&type);
 	bp->h_next = *tbl;
 	*tbl = bp;