diff options
author | Michael Forney <mforney@mforney.org> | 2019-04-16 12:25:00 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-04-16 12:25:00 -0700 |
commit | 953e1e6f287d8bc00b2ef8d2197a20a549274eb3 (patch) | |
tree | e8f8face3213b1a50761712441d43ac88fe0b663 | |
parent | 89fb4f577655dac61e81bbebd804e8843140a305 (diff) |
Fix offset of initializer following fixed-length string
-rw-r--r-- | qbe.c | 1 | ||||
-rw-r--r-- | tests/initializer-string-array.c | 3 | ||||
-rw-r--r-- | tests/initializer-string-array.qbe | 23 |
3 files changed, 27 insertions, 0 deletions
@@ -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 new file mode 100644 index 0000000..9ccc9d0 --- /dev/null +++ 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 new file mode 100644 index 0000000..87a03fd --- /dev/null +++ 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 +} |