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 953e1e6f287d8bc00b2ef8d2197a20a549274eb3
parent 89fb4f577655dac61e81bbebd804e8843140a305
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 16 Apr 2019 12:25:00 -0700

Fix offset of initializer following fixed-length string

Diffstat:
Mqbe.c | 1+
Atests/initializer-string-array.c | 3+++
Atests/initializer-string-array.qbe | 23+++++++++++++++++++++++
3 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -929,6 +929,7 @@ funcinit(struct func *func, struct decl *d, struct init *init) return; for (; init; init = init->next) { zero(func, d->value, d->type->align, offset, init->start); + offset = init->start; if (init->expr->kind == EXPRSTRING) { for (i = 0; i < init->expr->string.size && i < init->end - init->start; ++i) { dst = funcinst(func, IADD, &iptr, d->value, mkintconst(&iptr, init->start + i)); diff --git a/tests/initializer-string-array.c b/tests/initializer-string-array.c @@ -0,0 +1,3 @@ +void f(void) { + char x[][4] = {"abc", "xyz"}; +} diff --git a/tests/initializer-string-array.qbe b/tests/initializer-string-array.qbe @@ -0,0 +1,23 @@ +export +function $f() { +@start.1 + %.1 =l alloc4 8 +@body.2 + %.2 =l add %.1, 0 + storeb 97, %.2 + %.3 =l add %.1, 1 + storeb 98, %.3 + %.4 =l add %.1, 2 + storeb 99, %.4 + %.5 =l add %.1, 3 + storeb 0, %.5 + %.6 =l add %.1, 4 + storeb 120, %.6 + %.7 =l add %.1, 5 + storeb 121, %.7 + %.8 =l add %.1, 6 + storeb 122, %.8 + %.9 =l add %.1, 7 + storeb 0, %.9 + ret +}