scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 3f775a9d7d5405a555e5746f3314884ace516a4c
parent b163099eeca09217177482d7502bf8d6703dad76
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 18 Jan 2016 17:48:32 +0100

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.

Diffstat:
cc1/init.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cc1/init.c b/cc1/init.c @@ -169,12 +169,12 @@ initializer(Symbol *sym, Type *tp, int nelem) 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 @@ initializer(Symbol *sym, Type *tp, int nelem) 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); } }