diff --git a/src/arch/x86_64/abi.zig b/src/arch/x86_64/abi.zig index 298fc6656f..45c5760540 100644 --- a/src/arch/x86_64/abi.zig +++ b/src/arch/x86_64/abi.zig @@ -388,6 +388,19 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class { } return result; }, + .Array => { + const ty_size = ty.abiSize(target); + if (ty_size <= 64) { + result[0] = .integer; + return result; + } + if (ty_size <= 128) { + result[0] = .integer; + result[1] = .integer; + return result; + } + return memory_class; + }, else => unreachable, } } diff --git a/test/c_abi/cfuncs.c b/test/c_abi/cfuncs.c index 004dc9c406..382840e2aa 100644 --- a/test/c_abi/cfuncs.c +++ b/test/c_abi/cfuncs.c @@ -596,3 +596,18 @@ int32_t c_ret_i32() { int64_t c_ret_i64() { return -1; } + +typedef struct { + uint32_t a; + uint8_t padding[4]; + uint64_t b; +} StructWithArray; + +void c_struct_with_array(StructWithArray x) { + assert_or_panic(x.a == 1); + assert_or_panic(x.b == 2); +} + +StructWithArray c_ret_struct_with_array() { + return (StructWithArray) { 4, {}, 155 }; +} diff --git a/test/c_abi/main.zig b/test/c_abi/main.zig index 9344c2efae..6f1b336b01 100644 --- a/test/c_abi/main.zig +++ b/test/c_abi/main.zig @@ -665,3 +665,19 @@ test "C ABI integer return types" { try expect(c_ret_i32() == -1); try expect(c_ret_i64() == -1); } + +const StructWithArray = extern struct { + a: i32, + padding: [4]u8, + b: i64, +}; +extern fn c_struct_with_array(StructWithArray) void; +extern fn c_ret_struct_with_array() StructWithArray; + +test "Struct with array as padding." { + c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 }); + + var x = c_ret_struct_with_array(); + try std.testing.expect(x.a == 4); + try std.testing.expect(x.b == 155); +}