aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-21 01:34:15 -0700
committerMichael Forney <mforney@mforney.org>2024-04-21 01:34:15 -0700
commit593ca07956c6abc8bffcd2a2c5c06c521952f737 (patch)
treeb65e2eda7afa23e444485cb44db607a13cfbc34e
parent55263d181d28026a176729f7734dcd7558ae60f7 (diff)
expr: Create decl for compound literal during parse
-rw-r--r--cc.h2
-rw-r--r--eval.c2
-rw-r--r--expr.c5
-rw-r--r--qbe.c3
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;