authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-26 05:30:41-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-26 21:45:58-04:00
log48526c0eb6c394b778cba11559a66daf8d5ec3c7
tree768b321dc7e18dfa06ae5784df6b6709633c1ed2
parent98cd3782087d198425cfa19906f43d53b8106837

test: enable `c-abi-tests` for the x86_64 backend

Add testing for `x86_64_v2` and `x86_64_v3` with the x86_64 backend.

4 files changed, 238 insertions(+), 48 deletions(-)

test/behavior/maximum_minimum.zig+1-1
......@@ -282,7 +282,7 @@ test "@min/@max notices bounds from vector types when element of comptime-known
282282 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
283283 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
284284 if (builtin.zig_backend == .stage2_x86_64 and
285 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest;
285 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx)) return error.SkipZigTest;
286286
287287 var x: @Vector(2, u32) = .{ 1_000_000, 12345 };
288288 const y: @Vector(2, u16) = .{ 10, undefined };
test/c_abi/cfuncs.c+7-3
......@@ -73,6 +73,10 @@ static void assert_or_panic(bool ok) {
7373#define ZIG_NO_RAW_F16
7474#endif
7575
76#ifdef ZIG_BACKEND_STAGE2_X86_64
77#define ZIG_NO_COMPLEX
78#endif
79
7680#ifdef __i386__
7781#define ZIG_NO_RAW_F16
7882#endif
......@@ -274,7 +278,7 @@ void run_c_tests(void) {
274278 zig_u32(0xfffffffd);
275279 zig_u64(0xfffffffffffffffc);
276280
277#ifndef ZIG_NO_I128
281#if !defined ZIG_NO_I128 && !defined ZIG_BACKEND_STAGE2_X86_64
278282 {
279283 struct u128 s = {0xfffffffffffffffc};
280284 zig_struct_u128(s);
......@@ -288,7 +292,7 @@ void run_c_tests(void) {
288292 zig_i32(-3);
289293 zig_i64(-4);
290294
291#ifndef ZIG_NO_I128
295#if !defined ZIG_NO_I128 && !defined ZIG_BACKEND_STAGE2_X86_64
292296 {
293297 struct i128 s = {-6};
294298 zig_struct_i128(s);
......@@ -429,7 +433,7 @@ void run_c_tests(void) {
429433 }
430434#endif
431435
432#if !defined __mips__ && !defined ZIG_PPC32
436#if !defined __mips__ && !defined ZIG_PPC32 && !defined ZIG_BACKEND_STAGE2_X86_64
433437 {
434438 struct FloatRect r1 = {1, 21, 16, 4};
435439 struct FloatRect r2 = {178, 189, 21, 15};
test/c_abi/main.zig+86
......@@ -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.zig_backend == .stage2_x86_64) return error.SkipZigTest;
53
5254 c_u8(0xff);
5355 c_u16(0xfffe);
5456 c_u32(0xfffffffd);
......@@ -185,6 +187,8 @@ const complex_abi_compatible = builtin.cpu.arch != .x86 and !builtin.cpu.arch.is
185187 !builtin.cpu.arch.isARM() and !builtin.cpu.arch.isPPC() and !builtin.cpu.arch.isRISCV();
186188
187189test "C ABI complex float" {
190 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
191
188192 if (!complex_abi_compatible) return error.SkipZigTest;
189193 if (builtin.cpu.arch == .x86_64) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/8465
190194
......@@ -197,6 +201,8 @@ test "C ABI complex float" {
197201}
198202
199203test "C ABI complex float by component" {
204 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
205
200206 if (!complex_abi_compatible) return error.SkipZigTest;
201207
202208 const a = ComplexFloat{ .real = 1.25, .imag = 2.6 };
......@@ -208,6 +214,8 @@ test "C ABI complex float by component" {
208214}
209215
210216test "C ABI complex double" {
217 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
218
211219 if (!complex_abi_compatible) return error.SkipZigTest;
212220
213221 const a = ComplexDouble{ .real = 1.25, .imag = 2.6 };
......@@ -219,6 +227,8 @@ test "C ABI complex double" {
219227}
220228
221229test "C ABI complex double by component" {
230 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
231
222232 if (!complex_abi_compatible) return error.SkipZigTest;
223233
224234 const a = ComplexDouble{ .real = 1.25, .imag = 2.6 };
......@@ -230,6 +240,8 @@ test "C ABI complex double by component" {
230240}
231241
232242export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat {
243 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
244
233245 expect(a.real == 1.25) catch @panic("test failure: zig_cmultf 1");
234246 expect(a.imag == 2.6) catch @panic("test failure: zig_cmultf 2");
235247 expect(b.real == 11.3) catch @panic("test failure: zig_cmultf 3");
......@@ -239,6 +251,8 @@ export fn zig_cmultf(a: ComplexFloat, b: ComplexFloat) ComplexFloat {
239251}
240252
241253export fn zig_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble {
254 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
255
242256 expect(a.real == 1.25) catch @panic("test failure: zig_cmultd 1");
243257 expect(a.imag == 2.6) catch @panic("test failure: zig_cmultd 2");
244258 expect(b.real == 11.3) catch @panic("test failure: zig_cmultd 3");
......@@ -248,6 +262,8 @@ export fn zig_cmultd(a: ComplexDouble, b: ComplexDouble) ComplexDouble {
248262}
249263
250264export fn zig_cmultf_comp(a_r: f32, a_i: f32, b_r: f32, b_i: f32) ComplexFloat {
265 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
266
251267 expect(a_r == 1.25) catch @panic("test failure: zig_cmultf_comp 1");
252268 expect(a_i == 2.6) catch @panic("test failure: zig_cmultf_comp 2");
253269 expect(b_r == 11.3) catch @panic("test failure: zig_cmultf_comp 3");
......@@ -257,6 +273,8 @@ export fn zig_cmultf_comp(a_r: f32, a_i: f32, b_r: f32, b_i: f32) ComplexFloat {
257273}
258274
259275export fn zig_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble {
276 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
277
260278 expect(a_r == 1.25) catch @panic("test failure: zig_cmultd_comp 1");
261279 expect(a_i == 2.6) catch @panic("test failure: zig_cmultd_comp 2");
262280 expect(b_r == 11.3) catch @panic("test failure: zig_cmultd_comp 3");
......@@ -334,6 +352,8 @@ extern fn c_med_struct_mixed(MedStructMixed) void;
334352extern fn c_ret_med_struct_mixed() MedStructMixed;
335353
336354test "C ABI medium struct of ints and floats" {
355 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
356
337357 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
338358 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
339359 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -402,6 +422,8 @@ extern fn c_med_struct_ints(MedStructInts) void;
402422extern fn c_ret_med_struct_ints() MedStructInts;
403423
404424test "C ABI medium struct of ints" {
425 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
426
405427 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
406428 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
407429 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -509,6 +531,8 @@ extern fn c_split_struct_mixed(SplitStructMixed) void;
509531extern fn c_ret_split_struct_mixed() SplitStructMixed;
510532
511533test "C ABI split struct of ints and floats" {
534 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
535
512536 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
513537 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
514538 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -590,6 +614,8 @@ const Vector5 = extern struct {
590614extern fn c_big_struct_floats(Vector5) void;
591615
592616test "C ABI structs of floats as parameter" {
617 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
618
593619 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
594620 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
595621 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
......@@ -657,6 +683,8 @@ const FloatRect = extern struct {
657683};
658684
659685export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
686 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
687
660688 expect(x.left == 1) catch @panic("test failure");
661689 expect(x.right == 21) catch @panic("test failure");
662690 expect(x.top == 16) catch @panic("test failure");
......@@ -668,6 +696,8 @@ export fn zig_multiple_struct_floats(x: FloatRect, y: FloatRect) void {
668696}
669697
670698test "C ABI structs of floats as multiple parameters" {
699 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
700
671701 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
672702 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
673703
......@@ -724,6 +754,8 @@ export fn zig_ret_small_struct_ints() SmallStructInts {
724754}
725755
726756export fn zig_ret_med_struct_ints() MedStructInts {
757 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
758
727759 return .{
728760 .x = 1,
729761 .y = 2,
......@@ -732,6 +764,8 @@ export fn zig_ret_med_struct_ints() MedStructInts {
732764}
733765
734766export fn zig_ret_med_struct_mixed() MedStructMixed {
767 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
768
735769 return .{
736770 .a = 1234,
737771 .b = 100.0,
......@@ -740,6 +774,8 @@ export fn zig_ret_med_struct_mixed() MedStructMixed {
740774}
741775
742776export fn zig_ret_split_struct_mixed() SplitStructMixed {
777 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
778
743779 return .{
744780 .a = 1234,
745781 .b = 100,
......@@ -780,6 +816,8 @@ extern fn c_struct_with_array(StructWithArray) void;
780816extern fn c_ret_struct_with_array() StructWithArray;
781817
782818test "Struct with array as padding." {
819 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
820
783821 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
784822 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
785823 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -851,6 +889,8 @@ extern fn c_medium_vec(MediumVec) void;
851889extern fn c_ret_medium_vec() MediumVec;
852890
853891test "medium simd vector" {
892 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
893
854894 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
855895
856896 c_medium_vec(.{ 1, 2, 3, 4 });
......@@ -868,6 +908,8 @@ extern fn c_big_vec(BigVec) void;
868908extern fn c_ret_big_vec() BigVec;
869909
870910test "big simd vector" {
911 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
912
871913 if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
872914 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
873915 if (builtin.cpu.arch == .x86_64 and builtin.os.tag == .macos and builtin.mode != .Debug) return error.SkipZigTest;
......@@ -891,6 +933,8 @@ extern fn c_ptr_size_float_struct(Vector2) void;
891933extern fn c_ret_ptr_size_float_struct() Vector2;
892934
893935test "C ABI pointer sized float struct" {
936 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
937
894938 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
895939 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
896940 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
......@@ -914,6 +958,8 @@ pub inline fn expectOk(c_err: c_int) !void {
914958/// Tests for Double + Char struct
915959const DC = extern struct { v1: f64, v2: u8 };
916960test "DC: Zig passes to C" {
961 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
962
917963 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
918964 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
919965 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -921,6 +967,8 @@ test "DC: Zig passes to C" {
921967 try expectOk(c_assert_DC(.{ .v1 = -0.25, .v2 = 15 }));
922968}
923969test "DC: Zig returns to C" {
970 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
971
924972 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
925973 if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
926974 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
......@@ -929,6 +977,8 @@ test "DC: Zig returns to C" {
929977 try expectOk(c_assert_ret_DC());
930978}
931979test "DC: C passes to Zig" {
980 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
981
932982 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
933983 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
934984 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -936,6 +986,8 @@ test "DC: C passes to Zig" {
936986 try expectOk(c_send_DC());
937987}
938988test "DC: C returns to Zig" {
989 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
990
939991 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
940992 if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
941993 if (comptime builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
......@@ -949,6 +1001,8 @@ pub extern fn c_assert_ret_DC() c_int;
9491001pub extern fn c_send_DC() c_int;
9501002pub extern fn c_ret_DC() DC;
9511003pub export fn zig_assert_DC(lv: DC) c_int {
1004 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1005
9521006 var err: c_int = 0;
9531007 if (lv.v1 != -0.25) err = 1;
9541008 if (lv.v2 != 15) err = 2;
......@@ -956,6 +1010,8 @@ pub export fn zig_assert_DC(lv: DC) c_int {
9561010 return err;
9571011}
9581012pub export fn zig_ret_DC() DC {
1013 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1014
9591015 return .{ .v1 = -0.25, .v2 = 15 };
9601016}
9611017
......@@ -963,6 +1019,8 @@ pub export fn zig_ret_DC() DC {
9631019const CFF = extern struct { v1: u8, v2: f32, v3: f32 };
9641020
9651021test "CFF: Zig passes to C" {
1022 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1023
9661024 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
9671025 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
9681026 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -970,6 +1028,8 @@ test "CFF: Zig passes to C" {
9701028 try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }));
9711029}
9721030test "CFF: Zig returns to C" {
1031 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1032
9731033 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
9741034 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
9751035 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -977,6 +1037,8 @@ test "CFF: Zig returns to C" {
9771037 try expectOk(c_assert_ret_CFF());
9781038}
9791039test "CFF: C passes to Zig" {
1040 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1041
9801042 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
9811043 if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest;
9821044 if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest;
......@@ -987,6 +1049,8 @@ test "CFF: C passes to Zig" {
9871049 try expectOk(c_send_CFF());
9881050}
9891051test "CFF: C returns to Zig" {
1052 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1053
9901054 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
9911055 if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest;
9921056 if (comptime builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest;
......@@ -1000,6 +1064,8 @@ pub extern fn c_assert_ret_CFF() c_int;
10001064pub extern fn c_send_CFF() c_int;
10011065pub extern fn c_ret_CFF() CFF;
10021066pub export fn zig_assert_CFF(lv: CFF) c_int {
1067 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1068
10031069 var err: c_int = 0;
10041070 if (lv.v1 != 39) err = 1;
10051071 if (lv.v2 != 0.875) err = 2;
......@@ -1008,6 +1074,8 @@ pub export fn zig_assert_CFF(lv: CFF) c_int {
10081074 return err;
10091075}
10101076pub export fn zig_ret_CFF() CFF {
1077 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1078
10111079 return .{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 };
10121080}
10131081
......@@ -1015,6 +1083,8 @@ pub export fn zig_ret_CFF() CFF {
10151083const PD = extern struct { v1: ?*anyopaque, v2: f64 };
10161084
10171085test "PD: Zig passes to C" {
1086 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1087
10181088 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
10191089 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
10201090 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -1022,6 +1092,8 @@ test "PD: Zig passes to C" {
10221092 try expectOk(c_assert_PD(.{ .v1 = null, .v2 = 0.5 }));
10231093}
10241094test "PD: Zig returns to C" {
1095 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1096
10251097 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
10261098 if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
10271099 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -1029,6 +1101,8 @@ test "PD: Zig returns to C" {
10291101 try expectOk(c_assert_ret_PD());
10301102}
10311103test "PD: C passes to Zig" {
1104 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1105
10321106 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
10331107 if (comptime builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
10341108 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -1036,6 +1110,8 @@ test "PD: C passes to Zig" {
10361110 try expectOk(c_send_PD());
10371111}
10381112test "PD: C returns to Zig" {
1113 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1114
10391115 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
10401116 if (comptime builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
10411117 if (comptime builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -1047,6 +1123,8 @@ pub extern fn c_assert_ret_PD() c_int;
10471123pub extern fn c_send_PD() c_int;
10481124pub extern fn c_ret_PD() PD;
10491125pub export fn zig_c_assert_PD(lv: PD) c_int {
1126 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1127
10501128 var err: c_int = 0;
10511129 if (lv.v1 != null) err = 1;
10521130 if (lv.v2 != 0.5) err = 2;
......@@ -1054,9 +1132,13 @@ pub export fn zig_c_assert_PD(lv: PD) c_int {
10541132 return err;
10551133}
10561134pub export fn zig_ret_PD() PD {
1135 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1136
10571137 return .{ .v1 = null, .v2 = 0.5 };
10581138}
10591139pub export fn zig_assert_PD(lv: PD) c_int {
1140 if (builtin.zig_backend == .stage2_x86_64) @panic("error.SkipZigTest");
1141
10601142 var err: c_int = 0;
10611143 if (lv.v1 != null) err = 1;
10621144 if (lv.v2 != 0.5) err = 2;
......@@ -1146,6 +1228,8 @@ const f80_struct = extern struct {
11461228};
11471229extern fn c_f80_struct(f80_struct) f80_struct;
11481230test "f80 struct" {
1231 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1232
11491233 if (!has_f80) return error.SkipZigTest;
11501234 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
11511235 if (builtin.mode != .Debug) return error.SkipZigTest;
......@@ -1233,6 +1317,8 @@ test "Stdcall ABI big union" {
12331317
12341318extern fn c_explict_win64(ByRef) callconv(.Win64) ByRef;
12351319test "explicit SysV calling convention" {
1320 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1321
12361322 if (builtin.cpu.arch != .x86_64) return error.SkipZigTest;
12371323
12381324 const res = c_explict_win64(.{ .val = 1, .arr = undefined });
test/tests.zig+144-44
......@@ -94,6 +94,26 @@ const test_targets = blk: {
9494 .use_llvm = false,
9595 .use_lld = false,
9696 },
97 .{
98 .target = .{
99 .cpu_arch = .x86_64,
100 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
101 .os_tag = .linux,
102 .abi = .none,
103 },
104 .use_llvm = false,
105 .use_lld = false,
106 },
107 .{
108 .target = .{
109 .cpu_arch = .x86_64,
110 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
111 .os_tag = .linux,
112 .abi = .none,
113 },
114 .use_llvm = false,
115 .use_lld = false,
116 },
97117 // Doesn't support new liveness
98118 //.{
99119 // .target = .{
......@@ -470,62 +490,123 @@ const test_targets = blk: {
470490 };
471491};
472492
473const c_abi_targets = [_]CrossTarget{
493const CAbiTarget = struct {
494 target: CrossTarget = .{},
495 use_llvm: ?bool = null,
496 use_lld: ?bool = null,
497 c_defines: []const []const u8 = &.{},
498};
499
500const c_abi_targets = [_]CAbiTarget{
474501 .{},
475502 .{
476 .cpu_arch = .x86_64,
477 .os_tag = .linux,
478 .abi = .musl,
503 .target = .{
504 .cpu_arch = .x86_64,
505 .os_tag = .linux,
506 .abi = .musl,
507 },
479508 },
480509 .{
481 .cpu_arch = .x86,
482 .os_tag = .linux,
483 .abi = .musl,
510 .target = .{
511 .cpu_arch = .x86_64,
512 .os_tag = .linux,
513 .abi = .musl,
514 },
515 .use_llvm = false,
516 .use_lld = false,
517 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
484518 },
485519 .{
486 .cpu_arch = .aarch64,
487 .os_tag = .linux,
488 .abi = .musl,
520 .target = .{
521 .cpu_arch = .x86_64,
522 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v2 },
523 .os_tag = .linux,
524 .abi = .musl,
525 },
526 .use_llvm = false,
527 .use_lld = false,
528 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
489529 },
490530 .{
491 .cpu_arch = .arm,
492 .os_tag = .linux,
493 .abi = .musleabihf,
531 .target = .{
532 .cpu_arch = .x86_64,
533 .cpu_model = .{ .explicit = &std.Target.x86.cpu.x86_64_v3 },
534 .os_tag = .linux,
535 .abi = .musl,
536 },
537 .use_llvm = false,
538 .use_lld = false,
539 .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"},
494540 },
495541 .{
496 .cpu_arch = .mips,
497 .os_tag = .linux,
498 .abi = .musl,
542 .target = .{
543 .cpu_arch = .x86,
544 .os_tag = .linux,
545 .abi = .musl,
546 },
499547 },
500548 .{
501 .cpu_arch = .riscv64,
502 .os_tag = .linux,
503 .abi = .musl,
549 .target = .{
550 .cpu_arch = .aarch64,
551 .os_tag = .linux,
552 .abi = .musl,
553 },
504554 },
505555 .{
506 .cpu_arch = .wasm32,
507 .os_tag = .wasi,
508 .abi = .musl,
556 .target = .{
557 .cpu_arch = .arm,
558 .os_tag = .linux,
559 .abi = .musleabihf,
560 },
509561 },
510562 .{
511 .cpu_arch = .powerpc,
512 .os_tag = .linux,
513 .abi = .musl,
563 .target = .{
564 .cpu_arch = .mips,
565 .os_tag = .linux,
566 .abi = .musl,
567 },
514568 },
515569 .{
516 .cpu_arch = .powerpc64le,
517 .os_tag = .linux,
518 .abi = .musl,
570 .target = .{
571 .cpu_arch = .riscv64,
572 .os_tag = .linux,
573 .abi = .musl,
574 },
519575 },
520576 .{
521 .cpu_arch = .x86,
522 .os_tag = .windows,
523 .abi = .gnu,
577 .target = .{
578 .cpu_arch = .wasm32,
579 .os_tag = .wasi,
580 .abi = .musl,
581 },
524582 },
525583 .{
526 .cpu_arch = .x86_64,
527 .os_tag = .windows,
528 .abi = .gnu,
584 .target = .{
585 .cpu_arch = .powerpc,
586 .os_tag = .linux,
587 .abi = .musl,
588 },
589 },
590 .{
591 .target = .{
592 .cpu_arch = .powerpc64le,
593 .os_tag = .linux,
594 .abi = .musl,
595 },
596 },
597 .{
598 .target = .{
599 .cpu_arch = .x86,
600 .os_tag = .windows,
601 .abi = .gnu,
602 },
603 },
604 .{
605 .target = .{
606 .cpu_arch = .x86_64,
607 .os_tag = .windows,
608 .abi = .gnu,
609 },
529610 },
530611};
531612
......@@ -1017,6 +1098,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10171098
10181099 const libc_suffix = if (test_target.link_libc == true) "-libc" else "";
10191100 const triple_txt = test_target.target.zigTriple(b.allocator) catch @panic("OOM");
1101 const model_txt = test_target.target.getCpuModel().name;
10201102
10211103 // wasm32-wasi builds need more RAM, idk why
10221104 const max_rss = if (test_target.target.getOs().tag == .wasi)
......@@ -1054,9 +1136,10 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10541136 these_tests.stack_size = 2 * 1024 * 1024;
10551137 }
10561138
1057 const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}{s}", .{
1139 const qualified_name = b.fmt("{s}-{s}-{s}-{s}{s}{s}{s}{s}", .{
10581140 options.name,
10591141 triple_txt,
1142 model_txt,
10601143 @tagName(test_target.optimize_mode),
10611144 libc_suffix,
10621145 single_threaded_suffix,
......@@ -1144,33 +1227,50 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
11441227 if (optimize_mode != .Debug and skip_release) continue;
11451228
11461229 for (c_abi_targets) |c_abi_target| {
1147 if (skip_non_native and !c_abi_target.isNative()) continue;
1230 if (skip_non_native and !c_abi_target.target.isNative()) continue;
11481231
1149 if (c_abi_target.isWindows() and c_abi_target.getCpuArch() == .aarch64) {
1232 if (c_abi_target.target.isWindows() and c_abi_target.target.getCpuArch() == .aarch64) {
11501233 // https://github.com/ziglang/zig/issues/14908
11511234 continue;
11521235 }
11531236
1154 const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
1237 if (c_abi_target.use_llvm == false and optimize_mode == .ReleaseFast) {
1238 // panic: unrecognized command line argument
1239 continue;
1240 }
11551241
11561242 const test_step = b.addTest(.{
1243 .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}", .{
1244 c_abi_target.target.zigTriple(b.allocator) catch @panic("OOM"),
1245 c_abi_target.target.getCpuModel().name,
1246 @tagName(optimize_mode),
1247 if (c_abi_target.use_llvm == true)
1248 "-llvm"
1249 else if (c_abi_target.target.ofmt == std.Target.ObjectFormat.c)
1250 "-cbe"
1251 else if (c_abi_target.use_llvm == false)
1252 "-selfhosted"
1253 else
1254 "",
1255 if (c_abi_target.use_lld == false) "-no-lld" else "",
1256 }),
11571257 .root_source_file = .{ .path = "test/c_abi/main.zig" },
1258 .target = c_abi_target.target,
11581259 .optimize = optimize_mode,
1159 .target = c_abi_target,
1160 .name = b.fmt("test-c-abi-{s}-{s}", .{
1161 triple_prefix, @tagName(optimize_mode),
1162 }),
1260 .link_libc = true,
1261 .use_llvm = c_abi_target.use_llvm,
1262 .use_lld = c_abi_target.use_lld,
11631263 });
1164 if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
1264 if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) {
11651265 // TODO NativeTargetInfo insists on dynamically linking musl
11661266 // for some reason?
11671267 test_step.target_info.dynamic_linker.max_byte = null;
11681268 }
1169 test_step.linkLibC();
11701269 test_step.addCSourceFile(.{
11711270 .file = .{ .path = "test/c_abi/cfuncs.c" },
11721271 .flags = &.{"-std=c99"},
11731272 });
1273 for (c_abi_target.c_defines) |define| test_step.defineCMacro(define, null);
11741274
11751275 // This test is intentionally trying to check if the external ABI is
11761276 // done properly. LTO would be a hindrance to this.