authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-06-05 14:35:45+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-06-05 21:50:56+02:00
log98cf81d51c7c5b5cd6b6840007ce05cd0cc94143
treecb87c382c46c02d1cdabd2d757b36506ec875833
parentadc4418bae54e51921cde937d96faebf576f6d0c

test: Expand target coverage for C ABI tests.


3 files changed, 396 insertions(+), 123 deletions(-)

test/c_abi/cfuncs.c+53-9
......@@ -37,6 +37,10 @@ static void assert_or_panic(bool ok) {
3737# define ZIG_NO_I128
3838#endif
3939
40#ifdef __hexagon__
41# define ZIG_NO_I128
42#endif
43
4044#ifdef __mips__
4145# define ZIG_NO_I128
4246#endif
......@@ -77,6 +81,14 @@ static void assert_or_panic(bool ok) {
7781#define ZIG_NO_RAW_F16
7882#endif
7983
84#ifdef __hexagon__
85#define ZIG_NO_RAW_F16
86#endif
87
88#ifdef __loongarch__
89#define ZIG_NO_RAW_F16
90#endif
91
8092#ifdef __mips__
8193#define ZIG_NO_RAW_F16
8294#endif
......@@ -85,6 +97,10 @@ static void assert_or_panic(bool ok) {
8597#define ZIG_NO_RAW_F16
8698#endif
8799
100#ifdef __s390x__
101#define ZIG_NO_RAW_F16
102#endif
103
88104#ifdef __wasm__
89105#define ZIG_NO_RAW_F16
90106#endif
......@@ -101,6 +117,14 @@ static void assert_or_panic(bool ok) {
101117#define ZIG_NO_F128
102118#endif
103119
120#ifdef __hexagon__
121#define ZIG_NO_F128
122#endif
123
124#ifdef __loongarch__
125#define ZIG_NO_F128
126#endif
127
104128#ifdef __mips__
105129#define ZIG_NO_F128
106130#endif
......@@ -113,6 +137,10 @@ static void assert_or_panic(bool ok) {
113137#define ZIG_NO_F128
114138#endif
115139
140#ifdef __s390x__
141#define ZIG_NO_F128
142#endif
143
116144#ifdef __APPLE__
117145#define ZIG_NO_F128
118146#endif
......@@ -2713,18 +2741,24 @@ void run_c_tests(void) {
27132741 }
27142742
27152743#if !defined(ZIG_RISCV64)
2744#if !defined(__mips64__)
27162745 {
27172746 struct Struct_f32 s = zig_ret_struct_f32();
27182747 assert_or_panic(s.a == 2.5f);
27192748 zig_struct_f32((struct Struct_f32){ 2.5f });
27202749 }
2750#endif
27212751
2752#if !(defined(__arm__) && defined(__SOFTFP__))
2753#if !defined(ZIG_RISCV32)
27222754 {
27232755 struct Struct_f64 s = zig_ret_struct_f64();
27242756 assert_or_panic(s.a == 2.5);
27252757 zig_struct_f64((struct Struct_f64){ 2.5 });
27262758 }
2759#endif
27272760
2761#if !defined(__loongarch__) && !defined(__mips64__)
27282762 {
27292763 struct Struct_f32f32_f32 s = zig_ret_struct_f32f32_f32();
27302764 assert_or_panic(s.a.b == 1.0f);
......@@ -2741,8 +2775,10 @@ void run_c_tests(void) {
27412775 zig_struct_f32_f32f32((struct Struct_f32_f32f32){ 1.0f, { 2.0f, 3.0f } });
27422776 }
27432777#endif
2778#endif
2779#endif
27442780
2745#if !defined(__powerpc__)
2781#if !defined(__powerpc__) && !defined(__loongarch__) && !defined(__mips64__)
27462782 {
27472783 struct Struct_u32_Union_u32_u32u32 s = zig_ret_struct_u32_union_u32_u32u32();
27482784 assert_or_panic(s.a == 1);
......@@ -2750,20 +2786,24 @@ void run_c_tests(void) {
27502786 assert_or_panic(s.b.c.e == 3);
27512787 zig_struct_u32_union_u32_u32u32(s);
27522788 }
2789
27532790 {
27542791 struct Struct_i32_i32 s = {1, 2};
27552792 zig_struct_i32_i32(s);
27562793 }
27572794#endif
27582795
2796#if !defined(__powerpc64__) && !defined(__loongarch__) && !defined(__mips64__)
27592797 {
27602798 struct BigStruct s = {1, 2, 3, 4, 5};
27612799 zig_big_struct(s);
27622800 }
27632801#endif
2802#endif
27642803
27652804#if !defined __i386__ && !defined __arm__ && !defined __aarch64__ && \
2766 !defined __powerpc__ && !defined ZIG_RISCV64
2805 !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \
2806 !defined(__mips64__)
27672807 {
27682808 struct SmallStructInts s = {1, 2, 3, 4};
27692809 zig_small_struct_ints(s);
......@@ -2771,7 +2811,8 @@ void run_c_tests(void) {
27712811#endif
27722812
27732813#if !defined __arm__ && !defined __aarch64__ && \
2774 !defined __powerpc__ && !defined ZIG_RISCV64
2814 !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \
2815 !defined(__mips64__)
27752816 {
27762817 struct MedStructInts s = {1, 2, 3};
27772818 zig_med_struct_ints(s);
......@@ -2797,14 +2838,16 @@ void run_c_tests(void) {
27972838 }
27982839
27992840#if !defined __i386__ && !defined __arm__ && \
2800 !defined ZIG_PPC32 && !defined _ARCH_PPC64
2841 !defined ZIG_PPC32 && !defined _ARCH_PPC64 && !defined(__loongarch__) && \
2842 !defined(__mips64__)
28012843 {
28022844 struct SplitStructInts s = {1234, 100, 1337};
28032845 zig_split_struct_ints(s);
28042846 }
28052847#endif
28062848
2807#if !defined __arm__ && !defined ZIG_PPC32 && !defined _ARCH_PPC64
2849#if !defined __arm__ && !defined ZIG_PPC32 && !defined _ARCH_PPC64 && !defined(__loongarch__) && \
2850 !defined(__mips64__)
28082851 {
28092852 struct MedStructMixed s = {1234, 100.0f, 1337.0f};
28102853 zig_med_struct_mixed(s);
......@@ -2812,14 +2855,15 @@ void run_c_tests(void) {
28122855#endif
28132856
28142857#if !defined __i386__ && !defined __arm__ && \
2815 !defined ZIG_PPC32 && !defined _ARCH_PPC64
2858 !defined ZIG_PPC32 && !defined _ARCH_PPC64 && !defined(__loongarch__) && \
2859 !defined(__mips64__)
28162860 {
28172861 struct SplitStructMixed s = {1234, 100, 1337.0f};
28182862 zig_split_struct_mixed(s);
28192863 }
28202864#endif
28212865
2822#if !defined ZIG_PPC32
2866#if !defined(__powerpc__) && !defined(__loongarch__) && !defined(__mips64__)
28232867 {
28242868 struct BigStruct s = {30, 31, 32, 33, 34};
28252869 struct BigStruct res = zig_big_struct_both(s);
......@@ -2831,7 +2875,7 @@ void run_c_tests(void) {
28312875 }
28322876#endif
28332877
2834#if !defined ZIG_PPC32 && !defined _ARCH_PPC64
2878#if !defined ZIG_PPC32 && !defined _ARCH_PPC64 && !defined(__loongarch__) && !defined(__mips64__)
28352879 {
28362880 struct Rect r1 = {1, 21, 16, 4};
28372881 struct Rect r2 = {178, 189, 21, 15};
......@@ -2839,7 +2883,7 @@ void run_c_tests(void) {
28392883 }
28402884#endif
28412885
2842#if !defined ZIG_PPC32
2886#if !defined ZIG_PPC32 && !defined(__loongarch__) && !defined(__mips64__)
28432887 {
28442888 struct FloatRect r1 = {1, 21, 16, 4};
28452889 struct FloatRect r2 = {178, 189, 21, 15};
test/c_abi/main.zig+56-9
......@@ -11,7 +11,7 @@ const print = std.debug.print;
1111const expect = std.testing.expect;
1212const expectEqual = std.testing.expectEqual;
1313const have_i128 = builtin.cpu.arch != .x86 and !builtin.cpu.arch.isArm() and
14 !builtin.cpu.arch.isMIPS() and !builtin.cpu.arch.isPowerPC32();
14 !builtin.cpu.arch.isMIPS() and !builtin.cpu.arch.isPowerPC32() and builtin.cpu.arch != .riscv32;
1515
1616const have_f128 = builtin.cpu.arch.isWasm() or (builtin.cpu.arch.isX86() and !builtin.os.tag.isDarwin());
1717const have_f80 = builtin.cpu.arch.isX86();
......@@ -49,6 +49,8 @@ export fn zig_five_integers(a: i32, b: i32, c: i32, d: i32, e: i32) void {
4949}
5050
5151test "C ABI integers" {
52 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
53
5254 c_u8(0xff);
5355 c_u16(0xfffe);
5456 c_u32(0xfffffffd);
......@@ -383,6 +385,8 @@ extern fn c_struct_f64(Struct_f64) void;
383385test "C ABI struct f64" {
384386 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
385387 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
388 if (builtin.cpu.arch.isArm() and builtin.abi.float() == .soft) return error.SkipZigTest;
389 if (builtin.cpu.arch == .riscv32) return error.SkipZigTest;
386390
387391 const s = c_ret_struct_f64();
388392 try expect(s.a == 2.5);
......@@ -411,6 +415,8 @@ extern fn c_struct_f32f32_f32(Struct_f32f32_f32) void;
411415test "C ABI struct {f32,f32} f32" {
412416 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
413417 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
418 if (builtin.cpu.arch.isArm() and builtin.abi.float() == .soft) return error.SkipZigTest;
419 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
414420
415421 const s = c_ret_struct_f32f32_f32();
416422 try expect(s.a.b == 1.0);
......@@ -441,6 +447,8 @@ extern fn c_struct_f32_f32f32(Struct_f32_f32f32) void;
441447test "C ABI struct f32 {f32,f32}" {
442448 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
443449 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
450 if (builtin.cpu.arch.isArm() and builtin.abi.float() == .soft) return error.SkipZigTest;
451 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
444452
445453 const s = c_ret_struct_f32_f32f32();
446454 try expect(s.a == 1.0);
......@@ -476,6 +484,7 @@ extern fn c_struct_u32_union_u32_u32u32(Struct_u32_Union_u32_u32u32) void;
476484test "C ABI struct{u32,union{u32,struct{u32,u32}}}" {
477485 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
478486 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
487 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
479488
480489 const s = c_ret_struct_u32_union_u32_u32u32();
481490 try expect(s.a == 1);
......@@ -494,6 +503,8 @@ extern fn c_struct_i32_i32(Struct_i32_i32) void;
494503test "C ABI struct i32 i32" {
495504 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
496505 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
506 if (builtin.cpu.arch == .riscv32) return error.SkipZigTest;
507 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
497508
498509 const s: Struct_i32_i32 = .{
499510 .a = 1,
......@@ -523,7 +534,8 @@ extern fn c_big_struct(BigStruct) void;
523534
524535test "C ABI big struct" {
525536 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
526 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
537 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
538 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
527539
528540 const s = BigStruct{
529541 .a = 1,
......@@ -550,6 +562,7 @@ extern fn c_big_union(BigUnion) void;
550562
551563test "C ABI big union" {
552564 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
565 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
553566
554567 const x = BigUnion{
555568 .a = BigStruct{
......@@ -583,6 +596,7 @@ extern fn c_ret_med_struct_mixed() MedStructMixed;
583596test "C ABI medium struct of ints and floats" {
584597 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
585598 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
599 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
586600
587601 const s = MedStructMixed{
588602 .a = 1234,
......@@ -615,6 +629,8 @@ test "C ABI small struct of ints" {
615629 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
616630 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
617631 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
632 if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest;
633 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
618634
619635 const s = SmallStructInts{
620636 .a = 1,
......@@ -648,6 +664,7 @@ extern fn c_ret_med_struct_ints() MedStructInts;
648664test "C ABI medium struct of ints" {
649665 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
650666 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
667 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
651668
652669 const s = MedStructInts{
653670 .x = 1,
......@@ -726,6 +743,7 @@ test "C ABI split struct of ints" {
726743 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
727744 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
728745 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
746 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
729747
730748 const s = SplitStructInt{
731749 .a = 1234,
......@@ -753,6 +771,7 @@ test "C ABI split struct of ints and floats" {
753771 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
754772 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
755773 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
774 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
756775
757776 const s = SplitStructMixed{
758777 .a = 1234,
......@@ -779,7 +798,8 @@ extern fn c_multiple_struct_floats(FloatRect, FloatRect) void;
779798
780799test "C ABI sret and byval together" {
781800 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
782 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
801 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
802 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
783803
784804 const s = BigStruct{
785805 .a = 1,
......@@ -832,6 +852,7 @@ extern fn c_big_struct_floats(Vector5) void;
832852test "C ABI structs of floats as parameter" {
833853 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
834854 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
855 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
835856
836857 const v3 = Vector3{
837858 .x = 3.0,
......@@ -871,6 +892,8 @@ export fn zig_multiple_struct_ints(x: Rect, y: Rect) void {
871892
872893test "C ABI structs of ints as multiple parameters" {
873894 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
895 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
896 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
874897
875898 const r1 = Rect{
876899 .left = 1,
......@@ -908,6 +931,7 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
908931test "C ABI structs of floats as multiple parameters" {
909932 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
910933 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
934 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
911935
912936 const r1 = FloatRect{
913937 .left = 1,
......@@ -1021,6 +1045,7 @@ test "Struct with array as padding." {
10211045 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
10221046 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
10231047 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
1048 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
10241049
10251050 c_struct_with_array(.{ .a = 1, .padding = undefined, .b = 2 });
10261051
......@@ -1046,6 +1071,7 @@ extern fn c_ret_float_array_struct() FloatArrayStruct;
10461071test "Float array like struct" {
10471072 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
10481073 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
1074 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
10491075
10501076 c_float_array_struct(.{
10511077 .origin = .{
......@@ -1073,6 +1099,7 @@ extern fn c_ret_small_vec() SmallVec;
10731099test "small simd vector" {
10741100 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
10751101 if (builtin.cpu.arch.isPowerPC64()) return error.SkipZigTest;
1102 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
10761103
10771104 c_small_vec(.{ 1, 2 });
10781105
......@@ -1134,7 +1161,8 @@ extern fn c_ret_vector_2_float() Vector2Float;
11341161extern fn c_ret_vector_4_float() Vector4Float;
11351162
11361163test "float simd vectors" {
1137 if (builtin.cpu.arch == .powerpc or builtin.cpu.arch == .powerpc64le) return error.SkipZigTest;
1164 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
1165 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
11381166
11391167 {
11401168 c_vector_2_float(.{ 1.0, 2.0 });
......@@ -5419,6 +5447,7 @@ test "C ABI pointer sized float struct" {
54195447 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54205448 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
54215449 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
5450 if (builtin.cpu.arch.isArm() and builtin.abi.float() == .soft) return error.SkipZigTest;
54225451
54235452 c_ptr_size_float_struct(.{ .x = 1, .y = 2 });
54245453
......@@ -5441,24 +5470,28 @@ test "DC: Zig passes to C" {
54415470 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54425471 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
54435472 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5473 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54445474 try expectOk(c_assert_DC(.{ .v1 = -0.25, .v2 = 15 }));
54455475}
54465476test "DC: Zig returns to C" {
5447 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
5477 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54485478 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
54495479 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5480 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54505481 try expectOk(c_assert_ret_DC());
54515482}
54525483test "DC: C passes to Zig" {
54535484 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54545485 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
54555486 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5487 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54565488 try expectOk(c_send_DC());
54575489}
54585490test "DC: C returns to Zig" {
5459 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
5491 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54605492 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
54615493 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5494 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54625495 try expectEqual(DC{ .v1 = -0.25, .v2 = 15 }, c_ret_DC());
54635496}
54645497
......@@ -5484,11 +5517,13 @@ test "CFF: Zig passes to C" {
54845517 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
54855518 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54865519 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5520 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54875521 try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }));
54885522}
54895523test "CFF: Zig returns to C" {
54905524 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54915525 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5526 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
54925527 try expectOk(c_assert_ret_CFF());
54935528}
54945529test "CFF: C passes to Zig" {
......@@ -5497,6 +5532,7 @@ test "CFF: C passes to Zig" {
54975532 if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest;
54985533 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
54995534 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5535 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55005536
55015537 try expectOk(c_send_CFF());
55025538}
......@@ -5505,6 +5541,7 @@ test "CFF: C returns to Zig" {
55055541 if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest;
55065542 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
55075543 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5544 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55085545 try expectEqual(CFF{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }, c_ret_CFF());
55095546}
55105547pub extern fn c_assert_CFF(lv: CFF) c_int;
......@@ -5529,21 +5566,25 @@ const PD = extern struct { v1: ?*anyopaque, v2: f64 };
55295566test "PD: Zig passes to C" {
55305567 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
55315568 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5569 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55325570 try expectOk(c_assert_PD(.{ .v1 = null, .v2 = 0.5 }));
55335571}
55345572test "PD: Zig returns to C" {
5535 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
5573 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
55365574 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5575 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55375576 try expectOk(c_assert_ret_PD());
55385577}
55395578test "PD: C passes to Zig" {
55405579 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
55415580 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5581 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55425582 try expectOk(c_send_PD());
55435583}
55445584test "PD: C returns to Zig" {
5545 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
5585 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
55465586 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5587 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55475588 try expectEqual(PD{ .v1 = null, .v2 = 0.5 }, c_ret_PD());
55485589}
55495590pub extern fn c_assert_PD(lv: PD) c_int;
......@@ -5576,6 +5617,7 @@ extern fn c_modify_by_ref_param(ByRef) ByRef;
55765617
55775618test "C function modifies by ref param" {
55785619 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
5620 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
55795621
55805622 const res = c_modify_by_ref_param(.{ .val = 1, .arr = undefined });
55815623 try expect(res.val == 42);
......@@ -5596,8 +5638,9 @@ const ByVal = extern struct {
55965638
55975639extern fn c_func_ptr_byval(*anyopaque, *anyopaque, ByVal, c_ulong, *anyopaque, c_ulong) void;
55985640test "C function that takes byval struct called via function pointer" {
5599 if (builtin.cpu.arch.isMIPS64() and builtin.mode != .Debug) return error.SkipZigTest;
5641 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
56005642 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
5643 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
56015644
56025645 var fn_ptr = &c_func_ptr_byval;
56035646 _ = &fn_ptr;
......@@ -5736,6 +5779,8 @@ extern fn stdcall_coord2(Coord2, Coord2, Coord2) callconv(stdcall_callconv) Coor
57365779test "Stdcall ABI structs" {
57375780 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
57385781 if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest;
5782 if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest;
5783 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
57395784
57405785 const res = stdcall_coord2(
57415786 .{ .x = 0x1111, .y = 0x2222 },
......@@ -5749,6 +5794,7 @@ test "Stdcall ABI structs" {
57495794extern fn stdcall_big_union(BigUnion) callconv(stdcall_callconv) void;
57505795test "Stdcall ABI big union" {
57515796 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
5797 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
57525798
57535799 const x = BigUnion{
57545800 .a = BigStruct{
......@@ -5821,6 +5867,7 @@ const byval_tail_callsite_attr = struct {
58215867test "byval tail callsite attribute" {
58225868 if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest;
58235869 if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest;
5870 if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest;
58245871
58255872 // Originally reported at https://github.com/ziglang/zig/issues/16290
58265873 // the bug was that the extern function had the byval attribute, but
test/tests.zig+287-105
......@@ -1597,137 +1597,319 @@ const CAbiTarget = struct {
15971597 c_defines: []const []const u8 = &.{},
15981598};
15991599
1600const c_abi_targets = [_]CAbiTarget{
1601 // Native Targets
1600const c_abi_targets = blk: {
1601 @setEvalBranchQuota(20000);
1602 break :blk [_]CAbiTarget{
1603 // Native Targets
16021604
1603 .{},
1605 .{},
16041606
1605 // Linux Targets
1607 // Linux Targets
16061608
1607 .{
1608 .target = .{
1609 .cpu_arch = .aarch64,
1610 .os_tag = .linux,
1611 .abi = .musl,
1609 .{
1610 .target = .{
1611 .cpu_arch = .aarch64,
1612 .os_tag = .linux,
1613 .abi = .musl,
1614 },
16121615 },
1613 },
16141616
1615 .{
1616 .target = .{
1617 .cpu_arch = .arm,
1618 .os_tag = .linux,
1619 .abi = .musleabihf,
1617 .{
1618 .target = .{
1619 .cpu_arch = .aarch64_be,
1620 .os_tag = .linux,
1621 .abi = .musl,
1622 },
16201623 },
1621 },
16221624
1623 .{
1624 .target = .{
1625 .cpu_arch = .mips,
1626 .os_tag = .linux,
1627 .abi = .musleabihf,
1625 .{
1626 .target = .{
1627 .cpu_arch = .arm,
1628 .os_tag = .linux,
1629 .abi = .musleabi,
1630 },
1631 },
1632 .{
1633 .target = .{
1634 .cpu_arch = .arm,
1635 .os_tag = .linux,
1636 .abi = .musleabihf,
1637 },
16281638 },
1629 },
16301639
1631 .{
1632 .target = .{
1633 .cpu_arch = .powerpc,
1634 .os_tag = .linux,
1635 .abi = .musleabihf,
1640 .{
1641 .target = .{
1642 .cpu_arch = .armeb,
1643 .os_tag = .linux,
1644 .abi = .musleabi,
1645 },
1646 },
1647 .{
1648 .target = .{
1649 .cpu_arch = .armeb,
1650 .os_tag = .linux,
1651 .abi = .musleabihf,
1652 },
16361653 },
1637 },
16381654
1639 .{
1640 .target = .{
1641 .cpu_arch = .powerpc64le,
1642 .os_tag = .linux,
1643 .abi = .musl,
1655 // Crashes in LLVM instruction selection.
1656 // .{
1657 // .target = .{
1658 // .cpu_arch = .hexagon,
1659 // .os_tag = .linux,
1660 // .abi = .musl,
1661 // },
1662 // },
1663
1664 .{
1665 .target = .{
1666 .cpu_arch = .loongarch64,
1667 .os_tag = .linux,
1668 .abi = .musl,
1669 },
16441670 },
1645 },
16461671
1647 .{
1648 .target = .{
1649 .cpu_arch = .riscv64,
1650 .os_tag = .linux,
1651 .abi = .musl,
1672 .{
1673 .target = .{
1674 .cpu_arch = .mips,
1675 .os_tag = .linux,
1676 .abi = .musleabi,
1677 },
1678 },
1679 .{
1680 .target = .{
1681 .cpu_arch = .mips,
1682 .os_tag = .linux,
1683 .abi = .musleabihf,
1684 },
16521685 },
1653 },
16541686
1655 .{
1656 .target = .{
1657 .cpu_arch = .x86,
1658 .os_tag = .linux,
1659 .abi = .musl,
1687 .{
1688 .target = .{
1689 .cpu_arch = .mipsel,
1690 .os_tag = .linux,
1691 .abi = .musleabi,
1692 },
1693 },
1694 .{
1695 .target = .{
1696 .cpu_arch = .mipsel,
1697 .os_tag = .linux,
1698 .abi = .musleabihf,
1699 },
16601700 },
1661 },
16621701
1663 .{
1664 .target = .{
1665 .cpu_arch = .x86_64,
1666 .os_tag = .linux,
1667 .abi = .musl,
1668 },
1669 .use_llvm = false,
1670 .use_lld = false,
1671 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1672 },
1673 .{
1674 .target = .{
1675 .cpu_arch = .x86_64,
1676 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
1677 .os_tag = .linux,
1678 .abi = .musl,
1679 },
1680 .use_llvm = false,
1681 .use_lld = false,
1682 .strip = true,
1683 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1684 },
1685 .{
1686 .target = .{
1687 .cpu_arch = .x86_64,
1688 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
1689 .os_tag = .linux,
1690 .abi = .musl,
1702 .{
1703 .target = .{
1704 .cpu_arch = .mips64,
1705 .os_tag = .linux,
1706 .abi = .muslabi64,
1707 },
16911708 },
1692 .use_llvm = false,
1693 .use_lld = false,
1694 .pic = true,
1695 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1696 },
1697 .{
1698 .target = .{
1699 .cpu_arch = .x86_64,
1700 .os_tag = .linux,
1701 .abi = .musl,
1709 .{
1710 .target = .{
1711 .cpu_arch = .mips64,
1712 .os_tag = .linux,
1713 .abi = .muslabin32,
1714 },
1715 },
1716
1717 .{
1718 .target = .{
1719 .cpu_arch = .mips64el,
1720 .os_tag = .linux,
1721 .abi = .muslabi64,
1722 },
1723 },
1724 .{
1725 .target = .{
1726 .cpu_arch = .mips64el,
1727 .os_tag = .linux,
1728 .abi = .muslabin32,
1729 },
1730 },
1731
1732 .{
1733 .target = .{
1734 .cpu_arch = .powerpc,
1735 .os_tag = .linux,
1736 .abi = .musleabi,
1737 },
1738 },
1739 .{
1740 .target = .{
1741 .cpu_arch = .powerpc,
1742 .os_tag = .linux,
1743 .abi = .musleabihf,
1744 },
1745 },
1746
1747 .{
1748 .target = .{
1749 .cpu_arch = .powerpc64,
1750 .os_tag = .linux,
1751 .abi = .musl,
1752 },
1753 },
1754 .{
1755 .target = .{
1756 .cpu_arch = .powerpc64le,
1757 .os_tag = .linux,
1758 .abi = .musl,
1759 },
17021760 },
1703 },
17041761
1705 // WASI Targets
1762 .{
1763 .target = std.Target.Query.parse(.{
1764 .arch_os_abi = "riscv32-linux-musl",
1765 .cpu_features = "baseline-d-f",
1766 }) catch unreachable,
1767 },
1768 .{
1769 .target = .{
1770 .cpu_arch = .riscv32,
1771 .os_tag = .linux,
1772 .abi = .musl,
1773 },
1774 },
17061775
1707 .{
1708 .target = .{
1709 .cpu_arch = .wasm32,
1710 .os_tag = .wasi,
1711 .abi = .musl,
1776 .{
1777 .target = std.Target.Query.parse(.{
1778 .arch_os_abi = "riscv64-linux-musl",
1779 .cpu_features = "baseline-d-f",
1780 }) catch unreachable,
1781 },
1782 .{
1783 .target = .{
1784 .cpu_arch = .riscv64,
1785 .os_tag = .linux,
1786 .abi = .musl,
1787 },
17121788 },
1713 },
17141789
1715 // Windows Targets
1790 // Clang explodes when parsing `cfuncs.c`.
1791 // .{
1792 // .target = .{
1793 // .cpu_arch = .s390x,
1794 // .os_tag = .linux,
1795 // .abi = .musl,
1796 // },
1797 // },
1798
1799 .{
1800 .target = std.Target.Query.parse(.{
1801 .arch_os_abi = "thumb-linux-musleabi",
1802 .cpu_features = "baseline+long_calls",
1803 }) catch unreachable,
1804 .pic = false, // Long calls don't work with PIC.
1805 },
1806 .{
1807 .target = std.Target.Query.parse(.{
1808 .arch_os_abi = "thumb-linux-musleabihf",
1809 .cpu_features = "baseline+long_calls",
1810 }) catch unreachable,
1811 .pic = false, // Long calls don't work with PIC.
1812 },
17161813
1717 .{
1718 .target = .{
1719 .cpu_arch = .x86,
1720 .os_tag = .windows,
1721 .abi = .gnu,
1814 .{
1815 .target = std.Target.Query.parse(.{
1816 .arch_os_abi = "thumbeb-linux-musleabi",
1817 .cpu_features = "baseline+long_calls",
1818 }) catch unreachable,
1819 .pic = false, // Long calls don't work with PIC.
17221820 },
1723 },
1724 .{
1725 .target = .{
1726 .cpu_arch = .x86_64,
1727 .os_tag = .windows,
1728 .abi = .gnu,
1821 .{
1822 .target = std.Target.Query.parse(.{
1823 .arch_os_abi = "thumbeb-linux-musleabihf",
1824 .cpu_features = "baseline+long_calls",
1825 }) catch unreachable,
1826 .pic = false, // Long calls don't work with PIC.
1827 },
1828
1829 .{
1830 .target = .{
1831 .cpu_arch = .x86,
1832 .os_tag = .linux,
1833 .abi = .musl,
1834 },
17291835 },
1730 },
1836
1837 .{
1838 .target = .{
1839 .cpu_arch = .x86_64,
1840 .os_tag = .linux,
1841 .abi = .musl,
1842 },
1843 .use_llvm = false,
1844 .use_lld = false,
1845 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1846 },
1847 .{
1848 .target = .{
1849 .cpu_arch = .x86_64,
1850 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
1851 .os_tag = .linux,
1852 .abi = .musl,
1853 },
1854 .use_llvm = false,
1855 .use_lld = false,
1856 .strip = true,
1857 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1858 },
1859 .{
1860 .target = .{
1861 .cpu_arch = .x86_64,
1862 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
1863 .os_tag = .linux,
1864 .abi = .musl,
1865 },
1866 .use_llvm = false,
1867 .use_lld = false,
1868 .pic = true,
1869 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
1870 },
1871 .{
1872 .target = .{
1873 .cpu_arch = .x86_64,
1874 .os_tag = .linux,
1875 .abi = .musl,
1876 },
1877 },
1878 .{
1879 .target = .{
1880 .cpu_arch = .x86_64,
1881 .os_tag = .linux,
1882 .abi = .muslx32,
1883 },
1884 },
1885
1886 // WASI Targets
1887
1888 .{
1889 .target = .{
1890 .cpu_arch = .wasm32,
1891 .os_tag = .wasi,
1892 .abi = .musl,
1893 },
1894 },
1895
1896 // Windows Targets
1897
1898 .{
1899 .target = .{
1900 .cpu_arch = .x86,
1901 .os_tag = .windows,
1902 .abi = .gnu,
1903 },
1904 },
1905 .{
1906 .target = .{
1907 .cpu_arch = .x86_64,
1908 .os_tag = .windows,
1909 .abi = .gnu,
1910 },
1911 },
1912 };
17311913};
17321914
17331915pub fn addCompareOutputTests(