aboutsummaryrefslogtreecommitdiff
path: root/qbe.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-03-15 19:50:28 -0700
committerMichael Forney <mforney@mforney.org>2019-03-15 19:51:06 -0700
commit4acc9078f1572a611e5cf5048ed57ea6498d0bb9 (patch)
tree4f28921b8b405390251727abe1c10e85c245e905 /qbe.c
parent543d67d29296d7c1fab54292ade3a4d73ebac775 (diff)
Start to handle overlapping initializers
Diffstat (limited to 'qbe.c')
-rw-r--r--qbe.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/qbe.c b/qbe.c
index 63e0039..a40540a 100644
--- a/qbe.c
+++ b/qbe.c
@@ -892,7 +892,7 @@ void
funcinit(struct func *func, struct decl *d, struct init *init)
{
struct value *src, *dst;
- uint64_t offset = 0;
+ uint64_t offset = 0, max = 0;
size_t i;
funcalloc(func, d);
@@ -912,8 +912,10 @@ funcinit(struct func *func, struct decl *d, struct init *init)
funcstore(func, init->expr->type, dst, src);
offset = init->end;
}
+ if (max < offset)
+ max = offset;
}
- zero(func, d->value, d->type->align, offset, d->type->size);
+ zero(func, d->value, d->type->align, max, d->type->size);
}
static void
@@ -1203,12 +1205,15 @@ emitdata(struct decl *d, struct init *init)
emitvalue(d->value);
printf(" = align %d { ", d->align);
- for (; init; offset = init->end, init = init->next) {
+ for (; init; init = init->next) {
+ if (init->start < offset) /* XXX: sub-initializer may overlap */
+ continue;
if (offset < init->start)
printf("z %" PRIu64 ", ", init->start - offset);
printf("%c ", init->expr->type->kind == TYPEARRAY ? init->expr->type->base->repr->ext : init->expr->type->repr->ext);
dataitem(init->expr, init->end - init->start);
fputs(", ", stdout);
+ offset = init->end;
}
assert(offset <= d->type->size);
if (offset < d->type->size)