llvm: add attributes to the arguments of function pointer calls
Closes #13605
This commit is contained in:
@@ -842,3 +842,32 @@ struct ByRef c_modify_by_ref_param(struct ByRef in) {
|
||||
in.val = 42;
|
||||
return in;
|
||||
}
|
||||
|
||||
struct ByVal {
|
||||
struct {
|
||||
unsigned long x;
|
||||
unsigned long y;
|
||||
unsigned long z;
|
||||
} origin;
|
||||
struct {
|
||||
unsigned long width;
|
||||
unsigned long height;
|
||||
unsigned long depth;
|
||||
} size;
|
||||
};
|
||||
|
||||
void c_func_ptr_byval(void *a, void *b, struct ByVal in, unsigned long c, void *d, unsigned long e) {
|
||||
assert_or_panic((intptr_t)a == 1);
|
||||
assert_or_panic((intptr_t)b == 2);
|
||||
|
||||
assert_or_panic(in.origin.x == 9);
|
||||
assert_or_panic(in.origin.y == 10);
|
||||
assert_or_panic(in.origin.z == 11);
|
||||
assert_or_panic(in.size.width == 12);
|
||||
assert_or_panic(in.size.height == 13);
|
||||
assert_or_panic(in.size.depth == 14);
|
||||
|
||||
assert_or_panic(c == 3);
|
||||
assert_or_panic((intptr_t)d == 4);
|
||||
assert_or_panic(e == 5);
|
||||
}
|
||||
|
||||
@@ -1001,3 +1001,34 @@ test "C function modifies by ref param" {
|
||||
const res = c_modify_by_ref_param(.{ .val = 1, .arr = undefined });
|
||||
try expect(res.val == 42);
|
||||
}
|
||||
|
||||
const ByVal = extern struct {
|
||||
origin: extern struct {
|
||||
x: c_ulong,
|
||||
y: c_ulong,
|
||||
z: c_ulong,
|
||||
},
|
||||
size: extern struct {
|
||||
width: c_ulong,
|
||||
height: c_ulong,
|
||||
depth: c_ulong,
|
||||
},
|
||||
};
|
||||
|
||||
extern fn c_func_ptr_byval(*anyopaque, *anyopaque, ByVal, c_ulong, *anyopaque, c_ulong) void;
|
||||
test "C function that takes byval struct called via function pointer" {
|
||||
if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
|
||||
|
||||
var fn_ptr = &c_func_ptr_byval;
|
||||
fn_ptr(
|
||||
@intToPtr(*anyopaque, 1),
|
||||
@intToPtr(*anyopaque, 2),
|
||||
ByVal{
|
||||
.origin = .{ .x = 9, .y = 10, .z = 11 },
|
||||
.size = .{ .width = 12, .height = 13, .depth = 14 },
|
||||
},
|
||||
@as(c_ulong, 3),
|
||||
@intToPtr(*anyopaque, 4),
|
||||
@as(c_ulong, 5),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user