[hackers] [scc] Fix size of n.elem || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 14 Sep 2015 18:42:50 +0200 (CEST)

commit c4d94b222aa21eb5f956a37717627c0a55fd6404
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Sep 14 18:37:03 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Sep 14 18:37:03 2015 +0200

    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.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 3d0d427..ac615a6 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -52,7 +52,7 @@ struct type {
         } p;
         union {
                 unsigned char rank; /* convertion rank */
- TINT elem; /* number of type parameters */
+ TINT elem; /* number of type parameters */
         } n;
 };
 
_AT_@ -320,7 +320,7 @@ extern void cpperror(char *fmt, ...);
 /* 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);
 
diff --git a/cc1/code.c b/cc1/code.c
index cd54267..95d1c7b 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -235,7 +235,7 @@ emitletter(Type *tp)
 static void
 emittype(Type *tp)
 {
- int n;
+ TINT n;
         Type **vp;
         Symbol **sp;
         char *tag;
_AT_@ -350,7 +350,7 @@ static void
 emitfun(unsigned op, void *arg)
 {
         Symbol *sym = arg, **sp;
- int n;
+ TINT n;
 
         emitdcl(op, arg);
         puts("\n{");
diff --git a/cc1/decl.c b/cc1/decl.c
index 1c494e7..d213198 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -16,7 +16,7 @@ struct declarators {
         unsigned char nr;
         struct declarator {
                 unsigned char op;
- unsigned short nelem;
+ TINT nelem;
                 Symbol *sym;
                 Type **tpars;
                 Symbol **pars;
_AT_@ -33,7 +33,7 @@ struct decl {
 };
 
 static void
-push(struct declarators *dp, unsigned op, ...)
+push(struct declarators *dp, int op, ...)
 {
         va_list va;
         unsigned n;
_AT_@ -49,10 +49,10 @@ push(struct declarators *dp, unsigned op, ...)
 
         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;
_AT_@ -125,7 +125,7 @@ parameter(struct decl *dcl)
 {
         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;
_AT_@ -188,7 +188,7 @@ fundcl(struct declarators *dp)
 {
         Type type = {.n = {.elem = -1}, .p = {.pars= NULL}};
         Symbol *syms[NR_FUNPARAM], **sp;
- size_t size;
+ TINT size;
         Symbol *pars = NULL;
 
         pushctx();
_AT_@ -516,7 +516,7 @@ field(struct decl *dcl)
         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;
diff --git a/cc1/expr.c b/cc1/expr.c
index f66b08a..78a9822 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -532,7 +532,8 @@ static Node *assign(void);
 static Node *
 arguments(Node *np)
 {
- int n, toomany;;
+ int toomany;;
+ TINT n;
         Node *par = NULL, *arg;
         Type **targs, *tp = np->type;
 
_AT_@ -1057,7 +1058,8 @@ static void
 initlist(Symbol *sym, Type *tp)
 {
         struct designator *des;
- int n, toomany = 0;
+ int toomany = 0;
+ TINT n;
         Type *newtp;
 
         for (n = 0; ; ++n) {
diff --git a/cc1/types.c b/cc1/types.c
index 5f13f6f..33be7c9 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -350,13 +350,11 @@ invalid_type:
         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:
_AT_@ -391,7 +389,7 @@ typesize(Type *tp)
 }
 
 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;
_AT_@ -460,7 +458,7 @@ mktype(Type *tp, unsigned op, short nelem, Type *pars[])
 bool
 eqtype(Type *tp1, Type *tp2)
 {
- int n;
+ TINT n;
         Type **p1, **p2;
 
         if (!tp1 || !tp2)
_AT_@ -490,8 +488,5 @@ eqtype(Type *tp1, Type *tp2)
         case INT:
         case FLOAT:
                 return tp1->letter == tp2->letter;
- default:
- fputs("internal type error, aborting\n", stderr);
- abort();
         }
 }
Received on Mon Sep 14 2015 - 18:42:50 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 14 2015 - 18:48:10 CEST