commit 9480b1b86b396cce6a3fdaf5b5737b886b5d6758
parent c29a0ce2e3120db8f5df9b5ba3929aa26feb1ac3
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 24 Jul 2021 14:41:26 +0200
gen: fix calls with indirect primitive params
Say you have the following code:
let x: size = 1234;
foobar(x);
Previously, this would generate the following qbe:
%call.lvalue =l alloc8 8
%load =l loadl %binding
storel %load, %call.lvalue
call $foobar(l %call.lvalue)
This passes a pointer to the object, rather than the object itself. What
we really want is this:
%load =l loadl %binding
%call.lvalue =l copy %load
call $foobar(l %call.lvalue)
This patch makes the appropriate change.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/gen.c b/src/gen.c
@@ -470,7 +470,12 @@ gen_expr_call(struct gen_context *ctx,
while (carg) {
args = *next = xcalloc(1, sizeof(struct qbe_arguments));
struct gen_temp arg = {0};
- alloc_temp(ctx, &arg, carg->value->result, "call.arg.%d");
+ if (type_is_aggregate(carg->value->result)) {
+ alloc_temp(ctx, &arg, carg->value->result, "call.arg.%d");
+ } else {
+ gen_direct(ctx, &arg, carg->value->result, "call.arg.%d");
+ }
+
gen_expr(ctx, carg->value, &arg);
qval_temp(ctx, &args->value, &arg);
carg = carg->next;