shithub: scc

Download patch

ref: c4d94b222aa21eb5f956a37717627c0a55fd6404
parent: ed20286ef867b32a21feddc766d676b79254e640
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Sep 14 14:37:03 EDT 2015

Fix size of n.elem

After the commit 7ba972c the type for n.elem in
the type struct was TINT, but in all the other
places we were using short, which was generating
different errors due to the implicit convertions.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -52,7 +52,7 @@
 	} p;
 	union {
 		unsigned char rank;     /* convertion rank */
-		TINT elem;             /* number of type parameters */
+		TINT elem;              /* number of type parameters */
 	} n;
 };
 
@@ -320,7 +320,7 @@
 /* types.c */
 extern bool eqtype(Type *tp1, Type *tp2);
 extern Type *ctype(unsigned type, unsigned sign, unsigned size);
-extern Type *mktype(Type *tp, unsigned op, short nelem, Type *data[]);
+extern Type *mktype(Type *tp, int op, TINT nelem, Type *data[]);
 extern Type *duptype(Type *base);
 extern struct limits *getlimits(Type *tp);
 
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -235,7 +235,7 @@
 static void
 emittype(Type *tp)
 {
-	int n;
+	TINT n;
 	Type **vp;
 	Symbol **sp;
 	char *tag;
@@ -350,7 +350,7 @@
 emitfun(unsigned op, void *arg)
 {
 	Symbol *sym = arg, **sp;
-	int n;
+	TINT n;
 
 	emitdcl(op, arg);
 	puts("\n{");
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -16,7 +16,7 @@
 	unsigned char nr;
 	struct declarator {
 		unsigned char op;
-		unsigned short nelem;
+		TINT  nelem;
 		Symbol *sym;
 		Type **tpars;
 		Symbol **pars;
@@ -33,7 +33,7 @@
 };
 
 static void
-push(struct declarators *dp, unsigned op, ...)
+push(struct declarators *dp, int op, ...)
 {
 	va_list va;
 	unsigned n;
@@ -49,10 +49,10 @@
 
 	switch (op) {
 	case ARY:
-		p->nelem = va_arg(va, unsigned);
+		p->nelem = va_arg(va, TINT);
 		break;
 	case FTN:
-		p->nelem = va_arg(va, unsigned);
+		p->nelem = va_arg(va, TINT);
 		p->tpars = va_arg(va, Type **);
 		p->pars = va_arg(va, Symbol **);
 		break;
@@ -125,7 +125,7 @@
 {
 	Symbol *sym = dcl->sym;
 	Type *funtp = dcl->parent, *tp = dcl->type;
-	size_t n = funtp->n.elem;
+	TINT n = funtp->n.elem;
 	char *name = sym->name;
 
 	sym->type = tp;
@@ -188,7 +188,7 @@
 {
 	Type type = {.n = {.elem = -1}, .p = {.pars= NULL}};
 	Symbol *syms[NR_FUNPARAM], **sp;
-	size_t size;
+	TINT size;
 	Symbol *pars = NULL;
 
 	pushctx();
@@ -516,7 +516,7 @@
 	Symbol *sym = dcl->sym;
 	char *name = sym->name;
 	Type *structp = dcl->parent, *tp = dcl->type;
-	size_t n = structp->n.elem;
+	TINT n = structp->n.elem;
 
 	if (!name) {
 		sym->type = tp;
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -532,7 +532,8 @@
 static Node *
 arguments(Node *np)
 {
-	int n, toomany;;
+	int toomany;;
+	TINT n;
 	Node *par = NULL, *arg;
 	Type **targs, *tp = np->type;
 
@@ -1057,7 +1058,8 @@
 initlist(Symbol *sym, Type *tp)
 {
 	struct designator *des;
-	int n, toomany = 0;
+	int toomany = 0;
+	TINT n;
 	Type *newtp;
 
 	for (n = 0; ; ++n) {
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -350,13 +350,11 @@
 	error("invalid type specification");
 }
 
-/* TODO: define a type for sizes instead of using short */
-static short
+static TINT
 typesize(Type *tp)
 {
-	short align, size;
 	Symbol **sp;
-	int n;
+	TINT n, size, align;
 
 	switch (tp->op) {
 	case ARY:
@@ -391,7 +389,7 @@
 }
 
 Type *
-mktype(Type *tp, unsigned op, short nelem, Type *pars[])
+mktype(Type *tp, int op, TINT nelem, Type *pars[])
 {
 	static Type *typetab[NR_TYPE_HASH];
 	Type **tbl, type;
@@ -460,7 +458,7 @@
 bool
 eqtype(Type *tp1, Type *tp2)
 {
-	int n;
+	TINT n;
 	Type **p1, **p2;
 
 	if (!tp1 || !tp2)
@@ -490,8 +488,5 @@
 	case INT:
 	case FLOAT:
 		return tp1->letter == tp2->letter;
-	default:
-		fputs("internal type error, aborting\n", stderr);
-		abort();
 	}
 }