[hackers] [scc] [cc2-qbe] Remove l and r variables in cgen() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 10 May 2016 10:41:15 +0200 (CEST)

commit bc0bf0027ba8d82e645ee0b7099fa958be2eded3
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue May 10 10:20:03 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue May 10 10:20:03 2016 +0200

    [cc2-qbe] Remove l and r variables in cgen()
    
    These variables are not useful anymore after the last change
    to load, because we don't keep them updated. The actuar left
    and right are in np.
    This way of working is generating some "memory leaks", because
    some nodes become unlinked from the root, and it means that
    they will not be freed until cleaning the arena.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index c3facc3..c6cf007 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -245,10 +245,11 @@ abbrev(Node *np)
         return np->right = cgen(tmp);
 }
 
+/* TODO: Fix "memory leaks" */
 Node *
 cgen(Node *np)
 {
- Node *l, *r, *ifyes, *ifno, *next;
+ Node *ifyes, *ifno, *next;
         Symbol *sym;
         Type *tp;
         int op, off;
_AT_@ -258,8 +259,8 @@ cgen(Node *np)
                 return NULL;
 
         setlabel(np->label);
- l = cgen(np->left);
- r = cgen(np->right);
+ np->left = cgen(np->left);
+ np->right = cgen(np->right);
         tp = &np->type;
 
         switch (np->op) {
_AT_@ -317,7 +318,7 @@ cgen(Node *np)
         case OADDR:
                 np->flags |= ISTMP;
                 np->op = OTMP;
- np->u.sym = l->u.sym;
+ np->u.sym = np->left->u.sym;
                 return np;
         case OPTR:
                 load(np, LOADL);
_AT_@ -331,7 +332,7 @@ cgen(Node *np)
         case ODEC:
                 abort();
         case OASSIG:
- r = abbrev(np);
+ abbrev(np);
                 switch (tp->size) {
                 case 1:
                         op = ASSTB;
_AT_@ -348,8 +349,8 @@ cgen(Node *np)
                 default:
                         abort();
                 }
- code(op, l, r, NULL);
- return r;
+ code(op, np->left, load(np, LOADR), NULL);
+ return np->right;
         case OCALL:
         case OFIELD:
         case OCOMMA:
_AT_@ -360,7 +361,7 @@ cgen(Node *np)
                 abort();
         case OBRANCH:
                 next = np->next;
- l = load(np, LOADL);
+ load(np, LOADL);
                 if (next->label) {
                         sym = getsym(TMPSYM);
                         sym->kind = SLABEL;
Received on Tue May 10 2016 - 10:41:15 CEST

This archive was generated by hypermail 2.3.0 : Tue May 10 2016 - 10:48:14 CEST