aboutsummaryrefslogtreecommitdiff
path: root/qbe.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-15 20:16:38 -0800
committerMichael Forney <mforney@mforney.org>2019-02-15 20:16:38 -0800
commitf4a3a6504b1cf2bc28a2ad87ac5befcda6b78050 (patch)
treed2b40d9765947f7a3c267cb123e423f7c4c85900 /qbe.c
parent2c7f9d3a0131ca4f2060d05edfa2a67a190cd11f (diff)
Make sure that aggregates and pointers to aggregates are passed/return correctly
Diffstat (limited to 'qbe.c')
-rw-r--r--qbe.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/qbe.c b/qbe.c
index c6986b4..f43aee8 100644
--- a/qbe.c
+++ b/qbe.c
@@ -290,6 +290,7 @@ funcstore(struct function *f, struct type *t, struct value *addr, struct value *
static struct value *
funcload(struct function *f, struct type *t, struct value *addr)
{
+ struct value *v;
enum instructionkind op;
enum typequalifier tq;
@@ -311,7 +312,10 @@ funcload(struct function *f, struct type *t, struct value *addr)
case TYPESTRUCT:
case TYPEUNION:
case TYPEARRAY:
- return addr;
+ v = xmalloc(sizeof(*v));
+ *v = *addr;
+ v->repr = t->repr;
+ return v;
default:
fatal("unimplemented load %d", t->kind);
}
@@ -356,7 +360,9 @@ mkfunc(char *name, struct type *t, struct scope *s)
p->value = xmalloc(sizeof(*p->value));
functemp(f, p->value, p->type->repr);
if (p->type->repr->abi.id) {
- d->value = p->value;
+ d->value = xmalloc(sizeof(*d->value));
+ *d->value = *p->value;
+ d->value->repr = &iptr;
} else {
funcinit(f, d, NULL);
funcstore(f, typeunqual(p->type, NULL), d->value, p->value);