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 1df176029efa0d1e971e8835178f254ab8881592
parent cd1c07667495e7dd991cfcd0637eddf2bb65eac9
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 12 Mar 2019 18:59:35 -0700

Allow string literals to initialize any array with character type

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

diff --git a/init.c b/init.c @@ -249,7 +249,8 @@ parseinit(struct scope *s, struct type *t) if (expr->flags & EXPRFLAG_DECAYED && expr->unary.base->kind == EXPRSTRING) { expr = expr->unary.base; base = typeunqual(t->base, NULL); - if (!typecompatible(expr->type->base, base)) + /* XXX: wide string literals */ + if (!(typeprop(base) & PROPCHAR)) error(&tok.loc, "array initializer is string literal with incompatible type"); if (t->incomplete) updatearray(t, expr->string.size); diff --git a/tests/initializer-unsigned-string.c b/tests/initializer-unsigned-string.c @@ -0,0 +1 @@ +unsigned char s[] = "abc"; diff --git a/tests/initializer-unsigned-string.qbe b/tests/initializer-unsigned-string.qbe @@ -0,0 +1 @@ +export data $s = align 1 { b "abc", z 1, }