commit 205dcaa6299b4d4453c2fafff0630c6b3edde89f
parent 967f31f45e53e7142686bfc1e2c1de21246155b1
Author: Ember Sawady <ecs@d2evs.net>
Date: Mon, 30 Jan 2023 00:37:51 +0000
Fix memcpy size for array to slice assignment
Fixes: https://todo.sr.ht/~sircmpwn/hare/793
Signed-off-by: Ember Sawady <ecs@d2evs.net>
Diffstat:
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -841,6 +841,7 @@ gen_expr_assign_slice_expandable(struct gen_context *ctx, const struct expressio
struct qbe_value rtmemcpy = mkrtfunc(ctx, "rt.memcpy");
struct qbe_value one = constl(1);
pushi(ctx->current, &olen, Q_SUB, &olen, &one, NULL);
+ pushi(ctx->current, &olen, Q_MUL, &olen, &isize, NULL);
pushi(ctx->current, NULL, Q_CALL, &rtmemcpy, &next, &odata, &olen, NULL);
push(&ctx->current->body, &lzero);
diff --git a/tests/08-slices.ha b/tests/08-slices.ha
@@ -175,19 +175,21 @@ fn recursive_structure() void = {
};
fn expandable() void = {
- let s: [6]u16 = [0...];
-
+ let s: [6]u64 = [0...];
+
s[2..2] = [1...];
assert(s[2] == 0);
-
+
s[1..3] = [1...];
assert(s[0] == 0);
assert(s[1] == 1);
assert(s[2] == 1);
assert(s[3] == 0);
-
- s[4..] = [123...];
- assert(s[3] == 0);
+
+ s[2..] = [123...];
+ assert(s[1] == 1);
+ assert(s[2] == 123);
+ assert(s[3] == 123);
assert(s[4] == 123);
assert(s[5] == 123);
};