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 7e5d1aca647f13c0ae3a7cb0d4aff602e6bf7bea
parent f96bd3efcb284f5baf2d637240c9cd2ac07ca672
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 14 Feb 2019 01:41:25 -0800

Allow initializing array with longer strings

Diffstat:
Mdecl.c | 2+-
Minit.c | 8++++----
Minit.h | 2+-
Atests/initializer-long-string.c | 1+
Atests/initializer-long-string.qbe | 1+
5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/decl.c b/decl.c @@ -885,7 +885,7 @@ struct declaration *stringdecl(struct expression *expr) if (!d) { d = mkdecl(DECLOBJECT, expr->type, LINKNONE); d->value = mkglobal("string", true); - emitdata(d, mkinit(0, expr)); + emitdata(d, mkinit(0, expr->type->size, expr)); *entry = d; } return d; diff --git a/init.c b/init.c @@ -31,13 +31,13 @@ struct initparser { }; struct initializer * -mkinit(uint64_t offset, struct expression *expr) +mkinit(uint64_t start, uint64_t end, struct expression *expr) { struct initializer *init; init = xmalloc(sizeof(*init)); - init->start = offset; - init->end = offset + expr->type->size; + init->start = start; + init->end = end; init->expr = expr; init->next = NULL; @@ -257,7 +257,7 @@ parseinit(struct scope *s, struct type *t) focus(&p); } add: - initadd(&init, mkinit(p.sub->offset, expr)); + initadd(&init, mkinit(p.sub->offset, p.sub->offset + p.sub->type->size, expr)); for (;;) { if (p.sub->type->kind == TYPEARRAY && p.sub->type->incomplete) p.sub->type->incomplete = false; diff --git a/init.h b/init.h @@ -9,5 +9,5 @@ struct type; struct function; struct declaration; -struct initializer *mkinit(uint64_t, struct expression *); +struct initializer *mkinit(uint64_t, uint64_t, struct expression *); struct initializer *parseinit(struct scope *, struct type *); diff --git a/tests/initializer-long-string.c b/tests/initializer-long-string.c @@ -0,0 +1 @@ +char s[4] = "hello"; diff --git a/tests/initializer-long-string.qbe b/tests/initializer-long-string.qbe @@ -0,0 +1 @@ +export data $s = align 1 { b "hell", }