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 96fa8b352148f3843abe4f95958d765e40089f9b
parent e8863971221faba91357310b0c8be0fb2951ef22
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 22 Feb 2019 21:43:32 -0800

Make sure to zero the rest of an array initialized with a string

Diffstat:
Mqbe.c | 3++-
Atests/initializer-short-string.c | 3+++
Atests/initializer-short-string.qbe | 27+++++++++++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/qbe.c b/qbe.c @@ -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 @@ -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 @@ -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 +}