| author | |
| committer | |
| log | 51491186cb045520ace001e005164a97a8695504 |
| tree | 4f1dad21c514bfd59badee340940331e48ce9f13 |
| parent | ce95cc170bfa763d31fc498169ee9e44adca57fa |
Closes #121853 files changed, 44 insertions(+), 0 deletions(-)
src/arch/x86_64/abi.zig+13| ... | ... | @@ -388,6 +388,19 @@ pub fn classifySystemV(ty: Type, target: Target) [8]Class { |
| 388 | 388 | } |
| 389 | 389 | return result; |
| 390 | 390 | }, |
| 391 | .Array => { | |
| 392 | const ty_size = ty.abiSize(target); | |
| 393 | if (ty_size <= 64) { | |
| 394 | result[0] = .integer; | |
| 395 | return result; | |
| 396 | } | |
| 397 | if (ty_size <= 128) { | |
| 398 | result[0] = .integer; | |
| 399 | result[1] = .integer; | |
| 400 | return result; | |
| 401 | } | |
| 402 | return memory_class; | |
| 403 | }, | |
| 391 | 404 | else => unreachable, |
| 392 | 405 | } |
| 393 | 406 | } |
test/c_abi/cfuncs.c+15| ... | ... | @@ -596,3 +596,18 @@ int32_t c_ret_i32() { |
| 596 | 596 | int64_t c_ret_i64() { |
| 597 | 597 | return -1; |
| 598 | 598 | } |
| 599 | ||
| 600 | typedef struct { | |
| 601 | uint32_t a; | |
| 602 | uint8_t padding[4]; | |
| 603 | uint64_t b; | |
| 604 | } StructWithArray; | |
| 605 | ||
| 606 | void c_struct_with_array(StructWithArray x) { | |
| 607 | assert_or_panic(x.a == 1); | |
| 608 | assert_or_panic(x.b == 2); | |
| 609 | } | |
| 610 | ||
| 611 | StructWithArray c_ret_struct_with_array() { | |
| 612 | return (StructWithArray) { 4, {}, 155 }; | |
| 613 | } |
test/c_abi/main.zig+16| ... | ... | @@ -665,3 +665,19 @@ test "C ABI integer return types" { |
| 665 | 665 | try expect(c_ret_i32() == -1); |
| 666 | 666 | try expect(c_ret_i64() == -1); |
| 667 | 667 | } |
| 668 | ||
| 669 | const StructWithArray = extern struct { | |
| 670 | a: i32, | |
| 671 | padding: [4]u8, | |
| 672 | b: i64, | |
| 673 | }; | |
| 674 | extern fn c_struct_with_array(StructWithArray) void; | |
| 675 | extern fn c_ret_struct_with_array() StructWithArray; | |
| 676 | ||
| 677 | test "Struct with array as padding." { | |
| 678 | c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 }); | |
| 679 | ||
| 680 | var x = c_ret_struct_with_array(); | |
| 681 | try std.testing.expect(x.a == 4); | |
| 682 | try std.testing.expect(x.b == 155); | |
| 683 | } |