commit 98bca555e925528996607579e5d1e6c6ca806f1e
parent 3f5277da3d8e02829ef6f5f00003a8e8781ad9cc
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 2 Aug 2021 15:57:16 +0200
gen: skip final adds on gen_copy_struct
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -60,17 +60,19 @@ gen_copy_struct(struct gen_context *ctx,
struct qbe_value temp = {
.kind = QV_TEMPORARY,
.type = ctx->arch.ptr,
- .name = gen_name(ctx, "item.%d"),
+ .name = gen_name(ctx, ".%d"),
};
- struct qbe_value destp = mkcopy(ctx, &dest, "dest.%d");
- struct qbe_value srcp = mkcopy(ctx, &src, "src.%d");
+ struct qbe_value destp = mkcopy(ctx, &dest, ".%d");
+ struct qbe_value srcp = mkcopy(ctx, &src, ".%d");
struct qbe_value align = constl(dest.type->align);
for (size_t offset = 0; offset < dest.type->size;
offset += dest.type->align) {
pushi(ctx->current, &temp, load, &srcp, NULL);
pushi(ctx->current, NULL, store, &temp, &destp, NULL);
- pushi(ctx->current, &srcp, Q_ADD, &srcp, &align, NULL);
- pushi(ctx->current, &destp, Q_ADD, &destp, &align, NULL);
+ if (offset + dest.type->align < dest.type->size) {
+ pushi(ctx->current, &srcp, Q_ADD, &srcp, &align, NULL);
+ pushi(ctx->current, &destp, Q_ADD, &destp, &align, NULL);
+ }
}
}