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

Fix size of incomplete array types initialized with strings

updatearray takes an index, so was allocating an extra byte.

Diffstat:
Minit.c | 2+-
Atests/initializer-string.c | 4++++
Atests/initializer-string.qbe | 20++++++++++++++++++++
3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/init.c b/init.c @@ -249,7 +249,7 @@ parseinit(struct scope *s, struct type *t) if (!typecompatible(expr->type->base, base)) error(&tok.loc, "array initializer is string literal with incompatible type"); if (t->incomplete) - updatearray(t, expr->string.size + 1); + updatearray(t, expr->string.size); goto add; } break; diff --git a/tests/initializer-string.c b/tests/initializer-string.c @@ -0,0 +1,4 @@ +char x[] = "hello"; +void f(void) { + char y[] = "hello"; +} diff --git a/tests/initializer-string.qbe b/tests/initializer-string.qbe @@ -0,0 +1,20 @@ +export data $x = align 1 { b "hello", z 1, } +export +function $f() { +@start.1 + %.1 =l alloc4 6 +@body.2 + %.2 =l add %.1, 0 + storeb 104, %.2 + %.3 =l add %.1, 1 + storeb 101, %.3 + %.4 =l add %.1, 2 + storeb 108, %.4 + %.5 =l add %.1, 3 + storeb 108, %.5 + %.6 =l add %.1, 4 + storeb 111, %.6 + %.7 =l add %.1, 5 + storeb 0, %.7 + ret +}