aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qbe.c3
-rw-r--r--tests/initializer-short-string.c3
-rw-r--r--tests/initializer-short-string.qbe27
3 files changed, 32 insertions, 1 deletions
diff --git a/qbe.c b/qbe.c
index 4332b9c..4ff9c28 100644
--- 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
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
+}