commit 4ffc230ee9c60066127b59d0b207934739fcdaac
parent c25e3bc97b73d9f450f8453954b180a6b02d8250
Author: Armin Weigl <tb46305@gmail.com>
Date: Tue, 6 Apr 2021 17:48:39 +0000
fix slicing of array double pointer
Diffstat:
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -2298,8 +2298,7 @@ gen_expr_slice(struct gen_context *ctx,
otype = type_dealias(otype);
while (otype->storage == STORAGE_POINTER) {
pushi(ctx->current, &object, Q_LOADL, &object, NULL);
- otype = type_dereference(otype->pointer.referent);
- otype = type_dealias(otype);
+ otype = type_dealias(otype->pointer.referent);
}
gen_temp(ctx, &start, &qbe_long, "start.%d");
diff --git a/tests/07-aliases.ha b/tests/07-aliases.ha
@@ -13,12 +13,14 @@ fn unwrap() void = {
type my_array = [3]int;
type my_array_ptr = *my_array;
type my_array_ptr_ptr = *my_array_ptr;
+type my_slice = []int;
fn alias_array() void = {
let a: my_array = [1, 2, 3];
let i: my_int = 0;
let b: my_array_ptr = &a;
let c: my_array_ptr_ptr = &b;
+ let d: my_slice = c[..];
assert(a[i] == 1, "array alias");
assert(a[1] == 2, "array alias");
assert(a[2] == 3, "array alias");
@@ -28,6 +30,9 @@ fn alias_array() void = {
assert(c[i] == 1, "array ptr ptr alias");
assert(c[1] == 2, "array ptr ptr alias");
assert(c[2] == 3, "array ptr ptr alias");
+ assert(d[i] == 1, "array ptr ptr slice alias");
+ assert(d[1] == 2, "array ptr ptr slice alias");
+ assert(d[2] == 3, "array ptr ptr slice alias");
};
type my_fn = *const fn(_: int) int;