~mcf/cproc

1df176029efa0d1e971e8835178f254ab8881592 — Michael Forney 2 years ago cd1c076
Allow string literals to initialize any array with character type
3 files changed, 4 insertions(+), 1 deletions(-)

M init.c
A tests/initializer-unsigned-string.c
A tests/initializer-unsigned-string.qbe
M init.c => init.c +2 -1
@@ 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);

A tests/initializer-unsigned-string.c => tests/initializer-unsigned-string.c +1 -0
@@ 0,0 1,1 @@
unsigned char s[] = "abc";

A tests/initializer-unsigned-string.qbe => tests/initializer-unsigned-string.qbe +1 -0
@@ 0,0 1,1 @@
export data $s = align 1 { b "abc", z 1, }