diff options
author | Michael Forney <mforney@mforney.org> | 2019-02-22 21:43:32 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-02-22 21:45:00 -0800 |
commit | 96fa8b352148f3843abe4f95958d765e40089f9b (patch) | |
tree | 1e7df3193920535f6df8ab6d31812a2a1a430d6d | |
parent | e8863971221faba91357310b0c8be0fb2951ef22 (diff) |
Make sure to zero the rest of an array initialized with a string
-rw-r--r-- | qbe.c | 3 | ||||
-rw-r--r-- | tests/initializer-short-string.c | 3 | ||||
-rw-r--r-- | tests/initializer-short-string.qbe | 27 |
3 files changed, 32 insertions, 1 deletions
@@ -886,12 +886,13 @@ funcinit(struct function *func, struct declaration *d, struct initializer *init) dst = funcinst(func, IADD, &iptr, (struct value *[]){d->value, mkintconst(&iptr, init->start + i)}); funcinst(func, ISTOREB, NULL, (struct value *[]){mkintconst(&i8, init->expr->string.data[i]), dst}); } + offset += i; } else { dst = funcinst(func, IADD, &iptr, (struct value *[]){d->value, mkintconst(&iptr, init->start)}); src = funcexpr(func, init->expr); funcstore(func, init->expr->type, dst, src); + offset = init->end; } - offset = init->end; } zero(func, d->value, d->type->align, offset, d->type->size); } diff --git a/tests/initializer-short-string.c b/tests/initializer-short-string.c new file mode 100644 index 0000000..32e2aec --- /dev/null +++ b/tests/initializer-short-string.c @@ -0,0 +1,3 @@ +void f(void) { + char s[10] = "abc"; +} diff --git a/tests/initializer-short-string.qbe b/tests/initializer-short-string.qbe new file mode 100644 index 0000000..5b95ea1 --- /dev/null +++ b/tests/initializer-short-string.qbe @@ -0,0 +1,27 @@ +export +function $f() { +@start.1 + %.1 =l alloc4 10 +@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 0, %.6 + %.7 =l add %.1, 5 + storeb 0, %.7 + %.8 =l add %.1, 6 + storeb 0, %.8 + %.9 =l add %.1, 7 + storeb 0, %.9 + %.10 =l add %.1, 8 + storeb 0, %.10 + %.11 =l add %.1, 9 + storeb 0, %.11 + ret +} |