| ... | ... | @@ -579,3 +579,29 @@ test "runtime init of unnamed packed struct type" { |
| 579 | 579 | } |
| 580 | 580 | }{ .x = z }).m(); |
| 581 | 581 | } |
| 582 | |
| 583 | test "packed struct passed to callconv(.C) function" { |
| 584 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 585 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 586 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 587 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 588 | |
| 589 | const S = struct { |
| 590 | const Packed = packed struct { |
| 591 | a: u16, |
| 592 | b: bool = true, |
| 593 | c: bool = true, |
| 594 | d: u46 = 0, |
| 595 | }; |
| 596 | |
| 597 | fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.C) bool { |
| 598 | return p.a == 12345 and p.b == true and p.c == true and p.d == 0 and a1 == 5 and a2 == 4 and a3 == 3 and a4 == 2 and a5 == 1; |
| 599 | } |
| 600 | }; |
| 601 | const result = S.foo(S.Packed{ |
| 602 | .a = 12345, |
| 603 | .b = true, |
| 604 | .c = true, |
| 605 | }, 5, 4, 3, 2, 1); |
| 606 | try expect(result); |
| 607 | } |