llvm: aarch64 C ABI: pass byref params as mutable pointers

Closes  #13597
This commit is contained in:
Veikka Tuominen
2022-11-20 13:23:08 +02:00
parent 08a00f0d1c
commit 9e7293619f
3 changed files with 69 additions and 5 deletions

View File

@@ -833,3 +833,12 @@ struct PD zig_ret_PD();
int c_assert_ret_PD(){
return c_assert_PD(zig_ret_PD());
}
struct ByRef {
int val;
int arr[15];
};
struct ByRef c_modify_by_ref_param(struct ByRef in) {
in.val = 42;
return in;
}

View File

@@ -988,3 +988,16 @@ pub export fn zig_assert_PD(lv: PD) c_int {
if (err != 0) std.debug.print("Received {}", .{lv});
return err;
}
const ByRef = extern struct {
val: c_int,
arr: [15]c_int,
};
extern fn c_modify_by_ref_param(ByRef) ByRef;
test "C function modifies by ref param" {
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
const res = c_modify_by_ref_param(.{ .val = 1, .arr = undefined });
try expect(res.val == 42);
}