[hackers] [scc] [cc1] Free the types defined in functions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 12 Dec 2016 15:53:03 +0100 (CET)

commit 662f5dda9ab4c51c2339dcde074ab76b5c49afb0
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Dec 12 14:42:07 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Dec 12 15:34:11 2016 +0100

    [cc1] Free the types defined in functions
    
    We were not freeing ever the types defined locally,
    and since all the symbols in cc2 were strictly freed
    at the end of the function we had a problem of dangling
    identifiers.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 55d7bf8..9f4c15d 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -292,6 +292,7 @@ struct type {
                 unsigned char rank; /* convertion rank */
                 TINT elem; /* number of type parameters */
         } n;
+ Type *next; /* local list pointer */
         Type *h_prev, *h_next; /* hash pointers */
 };
 
_AT_@ -356,6 +357,7 @@ extern Type *mktype(Type *tp, int op, TINT nelem, Type *data[]);
 extern Type *duptype(Type *base);
 extern struct limits *getlimits(Type *tp);
 extern void typesize(Type *tp);
+extern void flushtypes(void);
 extern void itypes(void);
 
 /* symbol.c */
diff --git a/cc1/decl.c b/cc1/decl.c
index ee97af0..ee3f05c 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -907,6 +907,7 @@ decl(void)
         emit(OFUN, sym);
         compound(NULL, NULL, NULL);
         emit(OEFUN, NULL);
+ flushtypes();
         curfun = ocurfun;
 }
 
diff --git a/cc1/tests/test016.c b/cc1/tests/test016.c
index 0780d16..cd84371 100644
--- a/cc1/tests/test016.c
+++ b/cc1/tests/test016.c
_AT_@ -31,15 +31,15 @@ G11 I F "func2
 {
 \
 A12 I "x
-A13 P "p
-A15 P "pp
+A14 P "p
+A17 P "pp
         A12 #I1 :I
- A13 A12 'P :P
- A15 A13 'P :P
- y L17 A13 #P0 =I
- A15 _AT_P @I #I0 :I
-L17
- A13 #P0 :P
+ A14 A12 'P :P
+ A17 A14 'P :P
+ y L19 A14 #P0 =I
+ A17 _AT_P @I #I0 :I
+L19
+ A14 #P0 :P
         h A12
 }
 */
diff --git a/cc1/types.c b/cc1/types.c
index 71d5dcf..167d5a9 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -72,7 +72,7 @@ static struct limits limits[][4] = {
         }
 };
 
-static Type typetab[NR_TYPE_HASH];
+static Type typetab[NR_TYPE_HASH], *localtypes;
 
 void
 itypes()
_AT_@ -333,6 +333,12 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
         h_next->h_prev = bp;
         tbl->h_next = bp;
 
+ if (curctx > GLOBALCTX+1) {
+ /* it is a type defined in the body of a function */
+ bp->next = localtypes;
+ localtypes = bp;
+ }
+
         return bp;
 }
 
_AT_@ -378,3 +384,17 @@ eqtype(Type *tp1, Type *tp2, int equiv)
                 abort();
         }
 }
+
+void
+flushtypes(void)
+{
+ Type *tp, *next;
+
+ for (tp = localtypes; tp; tp = next) {
+ next = tp->next;
+ tp->h_prev->h_next = tp->h_next;
+ tp->h_next->h_prev = tp->h_prev;
+ free(tp);
+ }
+ localtypes = NULL;
+}
Received on Mon Dec 12 2016 - 15:53:03 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 12 2016 - 16:00:48 CET