From 593ca07956c6abc8bffcd2a2c5c06c521952f737 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 21 Apr 2024 01:34:15 -0700 Subject: expr: Create decl for compound literal during parse --- cc.h | 2 +- eval.c | 2 +- expr.c | 5 ++++- qbe.c | 3 +-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cc.h b/cc.h index fef4bca..3f4a026 100644 --- a/cc.h +++ b/cc.h @@ -358,7 +358,7 @@ struct expr { struct bitfield bits; } bitfield; struct { - enum storageduration storage; + struct decl *decl; struct init *init; } compound; struct { diff --git a/eval.c b/eval.c index 7fe0fd9..7b3a576 100644 --- a/eval.c +++ b/eval.c @@ -116,7 +116,7 @@ eval(struct expr *expr) expr->u.constant.u = intconstvalue(expr->u.ident.decl->value); break; case EXPRCOMPOUND: - if (expr->u.compound.storage != SDSTATIC) + if (expr->u.compound.decl->u.obj.storage != SDSTATIC) break; d = mkdecl(NULL, DECLOBJECT, t, expr->qual, LINKNONE); d->value = mkglobal(d); diff --git a/expr.c b/expr.c index fb6c144..f686da2 100644 --- a/expr.c +++ b/expr.c @@ -1107,6 +1107,7 @@ static struct expr * castexpr(struct scope *s) { struct type *t, *ct; + struct decl *d; enum typequal tq; struct expr *r, *e, **end; @@ -1126,8 +1127,10 @@ castexpr(struct scope *s) e = mkexpr(EXPRCOMPOUND, t, NULL); e->qual = tq; e->lvalue = true; + d = mkdecl(NULL, DECLOBJECT, t, tq, LINKNONE); + d->u.obj.storage = s == &filescope ? SDSTATIC : SDAUTO; + e->u.compound.decl = d; e->u.compound.init = parseinit(s, t); - e->u.compound.storage = s == &filescope ? SDSTATIC : SDAUTO; e = postfixexpr(s, decay(e)); goto done; } diff --git a/qbe.c b/qbe.c index c930972..f76f792 100644 --- a/qbe.c +++ b/qbe.c @@ -645,8 +645,7 @@ funclval(struct func *f, struct expr *e) lval.addr = d->value; break; case EXPRCOMPOUND: - d = mkdecl(NULL, DECLOBJECT, e->type, e->qual, LINKNONE); - d->u.obj.storage = SDAUTO; + d = e->u.compound.decl; funcinit(f, d, e->u.compound.init, true); lval.addr = d->value; break; -- cgit v1.2.3