M decl.c => decl.c +1 -1
@@ 885,7 885,7 @@ struct declaration *stringdecl(struct expression *expr)
if (!d) {
d = mkdecl(DECLOBJECT, expr->type, LINKNONE);
d->value = mkglobal("string", true);
- emitdata(d, mkinit(0, expr));
+ emitdata(d, mkinit(0, expr->type->size, expr));
*entry = d;
}
return d;
M init.c => init.c +4 -4
@@ 31,13 31,13 @@ struct initparser {
};
struct initializer *
-mkinit(uint64_t offset, struct expression *expr)
+mkinit(uint64_t start, uint64_t end, struct expression *expr)
{
struct initializer *init;
init = xmalloc(sizeof(*init));
- init->start = offset;
- init->end = offset + expr->type->size;
+ init->start = start;
+ init->end = end;
init->expr = expr;
init->next = NULL;
@@ 257,7 257,7 @@ parseinit(struct scope *s, struct type *t)
focus(&p);
}
add:
- initadd(&init, mkinit(p.sub->offset, expr));
+ initadd(&init, mkinit(p.sub->offset, p.sub->offset + p.sub->type->size, expr));
for (;;) {
if (p.sub->type->kind == TYPEARRAY && p.sub->type->incomplete)
p.sub->type->incomplete = false;
M init.h => init.h +1 -1
@@ 9,5 9,5 @@ struct type;
struct function;
struct declaration;
-struct initializer *mkinit(uint64_t, struct expression *);
+struct initializer *mkinit(uint64_t, uint64_t, struct expression *);
struct initializer *parseinit(struct scope *, struct type *);
A tests/initializer-long-string.c => tests/initializer-long-string.c +1 -0
@@ 0,0 1,1 @@
+char s[4] = "hello";
A tests/initializer-long-string.qbe => tests/initializer-long-string.qbe +1 -0
@@ 0,0 1,1 @@
+export data $s = align 1 { b "hell", }