shithub: scc

Download patch

ref: 3f775a9d7d5405a555e5746f3314884ace516a4c
parent: b163099eeca09217177482d7502bf8d6703dad76
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jan 18 12:48:32 EST 2016

Do not create unneded node in initialization

We were dealing initializers in the same way that we dealt
assignations, and this was an error, because in the case
of ibnitializers we do not need any node to mark the kind
of operation.

--- a/cc1/init.c
+++ b/cc1/init.c
@@ -169,12 +169,12 @@
 	if (tp->op == FTN)
 		errorp("function '%s' is initialized like a variable", sym->name);
 
-	np = node(OINIT, tp, varnode(sym), initialize(tp));
+	np = initialize(tp);
 
 	if (flags & ISDEFINED) {
 		errorp("redeclaration of '%s'", sym->name);
 	} else if ((flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) != 0) {
-		if (!np->right->constant)
+		if (!np->constant)
 			errorp("initializer element is not constant");
 		emit(OINIT, np);
 		sym->flags |= ISDEFINED;
@@ -182,7 +182,7 @@
 		errorp("'%s' has both '%s' and initializer",
 		       sym->name, (flags&ISEXTERN) ? "extern" : "typedef");
 	} else {
-		np->op = OASSIGN;
+		np = node(OASSIGN, tp, varnode(sym), np);
 		emit(OEXPR, np);
 	}
 }