cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit f96bd3efcb284f5baf2d637240c9cd2ac07ca672
parent 22338bdfd0346e85a0e88ca5470302a4775e9054
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 14 Feb 2019 01:39:33 -0800

Handle compound literals in global initializers

Diffstat:
Meval.c | 9+++++++++
Atests/compound-literal-static.c | 1+
Atests/compound-literal-static.qbe | 2++
3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/eval.c b/eval.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include "util.h" @@ -12,6 +13,7 @@ struct expression * eval(struct expression *expr) { struct expression *l, *r, *c; + struct declaration *d; int op; switch (expr->kind) { @@ -21,6 +23,13 @@ eval(struct expression *expr) expr->kind = EXPRCONST; expr->constant.i = intconstvalue(expr->ident.decl->value); break; + case EXPRCOMPOUND: + d = mkdecl(DECLOBJECT, expr->type, LINKNONE); + d->value = mkglobal(NULL, true); + emitdata(d, expr->compound.init); + expr->kind = EXPRIDENT; + expr->ident.decl = d; + break; case EXPRUNARY: l = eval(expr->unary.base); if (expr->unary.op != TBAND) diff --git a/tests/compound-literal-static.c b/tests/compound-literal-static.c @@ -0,0 +1 @@ +int *x = &(int){2}; diff --git a/tests/compound-literal-static.qbe b/tests/compound-literal-static.qbe @@ -0,0 +1,2 @@ +data $.L.1 = align 4 { w 2, } +export data $x = align 8 { l $.L.1, }