shithub: scc

Download patch

ref: 30281a311c063851cb9b85c72eaff8f3d0473f6a
parent: 7ef0309d40338751616257999bb1456a6d7c481e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue May 10 06:20:03 EDT 2016

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

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -245,10 +245,11 @@
 	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;
@@ -258,8 +259,8 @@
 		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) {
@@ -317,7 +318,7 @@
 	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);
@@ -331,7 +332,7 @@
 	case ODEC:
 		abort();
 	case OASSIG:
-		r = abbrev(np);
+		abbrev(np);
 		switch (tp->size) {
 		case 1:
 			op = ASSTB;
@@ -348,8 +349,8 @@
 		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:
@@ -360,7 +361,7 @@
 		abort();
 	case OBRANCH:
 		next = np->next;
-		l = load(np, LOADL);
+		load(np, LOADL);
 		if (next->label) {
 			sym = getsym(TMPSYM);
 			sym->kind = SLABEL;