commit 4904cf8f1fba06f129c73671084f667086ce1751
parent 2f3cee0b0eb8b0567d34639c15c3065fe8bf4a2e
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 10 Jan 2021 17:13:07 -0500
gen: fix implicit dereference issues
Diffstat:
2 files changed, 13 insertions(+), 22 deletions(-)
diff --git a/src/gen.c b/src/gen.c
@@ -291,17 +291,11 @@ address_index(struct gen_context *ctx,
atype = expr->access.array->result;
if (atype->storage == TYPE_STORAGE_POINTER) {
- // We get one dereference for free because the array is stored
- // indirectly
+ // We get one dereference for free for aggregate types
atype = atype->pointer.referent;
}
while (atype->storage == TYPE_STORAGE_POINTER) {
- qval_deref(out);
- struct qbe_value deref;
- gen_loadtemp(ctx, &deref, out,
- qtype_for_type(ctx, atype->pointer.referent, false),
- type_is_signed(atype->pointer.referent));
- *out = deref;
+ pushi(ctx->current, out, Q_LOADL, out, NULL);
atype = atype->pointer.referent;
}
@@ -339,12 +333,7 @@ address_field(struct gen_context *ctx,
stype = stype->pointer.referent;
}
while (stype->storage == TYPE_STORAGE_POINTER) {
- qval_deref(out);
- struct qbe_value deref;
- gen_loadtemp(ctx, &deref, out,
- qtype_for_type(ctx, stype->pointer.referent, false),
- type_is_signed(stype->pointer.referent));
- *out = deref;
+ pushi(ctx->current, out, Q_LOADL, out, NULL);
stype = stype->pointer.referent;
}
diff --git a/tests/06-structs.ha b/tests/06-structs.ha
@@ -40,14 +40,16 @@ fn deref() void = {
let a = &coords;
assert(a.x == 20);
assert(a.y == 30);
- // TODO: Why does this fail?
- //let b = &a;
- //assert(b.x == 20);
- //assert(b.y == 30);
- //b.x = 42;
- //b.y = 96;
- //assert(coords.x == 42);
- //assert(coords.y == 96);
+ let b = &a;
+ assert(b.x == 20);
+ assert(b.y == 30);
+ let c = &b;
+ assert(c.x == 20);
+ assert(c.y == 30);
+ c.x = 42;
+ c.y = 96;
+ assert(coords.x == 42);
+ assert(coords.y == 96);
};
fn nested() void = {