| author | |
| committer | |
| log | c0e90312fcb8a7919cd5be992acbfc00a6810931 |
| tree | 6c850ad74a30ba539d3067f1043afa1312af7383 |
| parent | 97ef8f1f8e693733e4f208a01b298dfb334fa719 |
3 files changed, 246 insertions(+), 17 deletions(-)
test/c_abi/cfuncs.c+124-9| ... | @@ -24,11 +24,6 @@ static void assert_or_panic(bool ok) { | ... | @@ -24,11 +24,6 @@ static void assert_or_panic(bool ok) { |
| 24 | # endif | 24 | # endif |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | #if defined(__aarch64__) && defined(__linux__) | ||
| 28 | // TODO: https://github.com/ziglang/zig/issues/14908 | ||
| 29 | #define ZIG_BUG_14908 | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #ifdef __i386__ | 27 | #ifdef __i386__ |
| 33 | # define ZIG_NO_I128 | 28 | # define ZIG_NO_I128 |
| 34 | #endif | 29 | #endif |
| ... | @@ -205,6 +200,74 @@ double complex zig_cmultd_comp(double a_r, double a_i, double b_r, double b_i); | ... | @@ -205,6 +200,74 @@ double complex zig_cmultd_comp(double a_r, double a_i, double b_r, double b_i); |
| 205 | float complex zig_cmultf(float complex a, float complex b); | 200 | float complex zig_cmultf(float complex a, float complex b); |
| 206 | double complex zig_cmultd(double complex a, double complex b); | 201 | double complex zig_cmultd(double complex a, double complex b); |
| 207 | 202 | ||
| 203 | struct Struct_u8 { | ||
| 204 | uint8_t a; | ||
| 205 | }; | ||
| 206 | |||
| 207 | struct Struct_u8 zig_ret_struct_u8(void); | ||
| 208 | |||
| 209 | void zig_struct_u8(struct Struct_u8, size_t); | ||
| 210 | |||
| 211 | struct Struct_u8 c_ret_struct_u8(void) { | ||
| 212 | return (struct Struct_u8){ 4 }; | ||
| 213 | } | ||
| 214 | |||
| 215 | void c_struct_u8(struct Struct_u8 s, size_t i) { | ||
| 216 | assert_or_panic(s.a == 5); | ||
| 217 | assert_or_panic(i == 6); | ||
| 218 | } | ||
| 219 | |||
| 220 | struct Struct_u16 { | ||
| 221 | uint16_t a; | ||
| 222 | }; | ||
| 223 | |||
| 224 | struct Struct_u16 zig_ret_struct_u16(void); | ||
| 225 | |||
| 226 | void zig_struct_u16(struct Struct_u16, size_t); | ||
| 227 | |||
| 228 | struct Struct_u16 c_ret_struct_u16(void) { | ||
| 229 | return (struct Struct_u16){ 10 }; | ||
| 230 | } | ||
| 231 | |||
| 232 | void c_struct_u16(struct Struct_u16 s, size_t i) { | ||
| 233 | assert_or_panic(s.a == 11); | ||
| 234 | assert_or_panic(i == 12); | ||
| 235 | } | ||
| 236 | |||
| 237 | struct Struct_u32 { | ||
| 238 | uint32_t a; | ||
| 239 | }; | ||
| 240 | |||
| 241 | struct Struct_u32 zig_ret_struct_u32(void); | ||
| 242 | |||
| 243 | void zig_struct_u32(struct Struct_u32, size_t); | ||
| 244 | |||
| 245 | struct Struct_u32 c_ret_struct_u32(void) { | ||
| 246 | return (struct Struct_u32){ 16 }; | ||
| 247 | } | ||
| 248 | |||
| 249 | void c_struct_u32(struct Struct_u32 s, size_t i) { | ||
| 250 | assert_or_panic(s.a == 17); | ||
| 251 | assert_or_panic(i == 18); | ||
| 252 | } | ||
| 253 | |||
| 254 | struct Struct_u64 { | ||
| 255 | uint64_t a; | ||
| 256 | }; | ||
| 257 | |||
| 258 | struct Struct_u64 zig_ret_struct_u64(void); | ||
| 259 | |||
| 260 | void zig_struct_u64(struct Struct_u64, size_t); | ||
| 261 | |||
| 262 | struct Struct_u64 c_ret_struct_u64(void) { | ||
| 263 | return (struct Struct_u64){ 22 }; | ||
| 264 | } | ||
| 265 | |||
| 266 | void c_struct_u64(struct Struct_u64 s, size_t i) { | ||
| 267 | assert_or_panic(s.a == 23); | ||
| 268 | assert_or_panic(i == 24); | ||
| 269 | } | ||
| 270 | |||
| 208 | struct Struct_u64_u64 { | 271 | struct Struct_u64_u64 { |
| 209 | uint64_t a; | 272 | uint64_t a; |
| 210 | uint64_t b; | 273 | uint64_t b; |
| ... | @@ -2677,10 +2740,8 @@ void run_c_tests(void) { | ... | @@ -2677,10 +2740,8 @@ void run_c_tests(void) { |
| 2677 | } | 2740 | } |
| 2678 | #endif | 2741 | #endif |
| 2679 | 2742 | ||
| 2680 | #ifndef ZIG_BUG_14908 | ||
| 2681 | zig_i8(-1); | 2743 | zig_i8(-1); |
| 2682 | zig_i16(-2); | 2744 | zig_i16(-2); |
| 2683 | #endif | ||
| 2684 | zig_i32(-3); | 2745 | zig_i32(-3); |
| 2685 | zig_i64(-4); | 2746 | zig_i64(-4); |
| 2686 | 2747 | ||
| ... | @@ -2741,6 +2802,60 @@ void run_c_tests(void) { | ... | @@ -2741,6 +2802,60 @@ void run_c_tests(void) { |
| 2741 | } | 2802 | } |
| 2742 | #endif | 2803 | #endif |
| 2743 | 2804 | ||
| 2805 | #if !defined(__AARCH_BIG_ENDIAN) | ||
| 2806 | #if !defined(__mips64) | ||
| 2807 | #if !defined(ZIG_PPC32) | ||
| 2808 | #if !defined(__s390x__) | ||
| 2809 | { | ||
| 2810 | struct Struct_u8 s = zig_ret_struct_u8(); | ||
| 2811 | assert_or_panic(s.a == 1); | ||
| 2812 | zig_struct_u8((struct Struct_u8){ .a = 2 }, 3); | ||
| 2813 | } | ||
| 2814 | #endif | ||
| 2815 | #endif | ||
| 2816 | #endif | ||
| 2817 | #endif | ||
| 2818 | |||
| 2819 | #if !defined(__AARCH_BIG_ENDIAN) | ||
| 2820 | #if !defined(__mips64) | ||
| 2821 | #if !defined(ZIG_PPC32) | ||
| 2822 | #if !defined(__s390x__) | ||
| 2823 | { | ||
| 2824 | struct Struct_u16 s = zig_ret_struct_u16(); | ||
| 2825 | assert_or_panic(s.a == 7); | ||
| 2826 | zig_struct_u16((struct Struct_u16){ .a = 8 }, 9); | ||
| 2827 | } | ||
| 2828 | #endif | ||
| 2829 | #endif | ||
| 2830 | #endif | ||
| 2831 | #endif | ||
| 2832 | |||
| 2833 | #if !defined(__AARCH_BIG_ENDIAN) | ||
| 2834 | #if !defined(__mips64) | ||
| 2835 | #if !defined(ZIG_PPC32) | ||
| 2836 | #if !defined(__s390x__) | ||
| 2837 | { | ||
| 2838 | struct Struct_u32 s = zig_ret_struct_u32(); | ||
| 2839 | assert_or_panic(s.a == 13); | ||
| 2840 | zig_struct_u32((struct Struct_u32){ .a = 14 }, 15); | ||
| 2841 | } | ||
| 2842 | #endif | ||
| 2843 | #endif | ||
| 2844 | #endif | ||
| 2845 | #endif | ||
| 2846 | |||
| 2847 | #if !defined(ZIG_PPC32) | ||
| 2848 | #if !defined(ZIG_RISCV32) | ||
| 2849 | #if !defined(__s390x__) | ||
| 2850 | { | ||
| 2851 | struct Struct_u64 s = zig_ret_struct_u64(); | ||
| 2852 | assert_or_panic(s.a == 19); | ||
| 2853 | zig_struct_u64((struct Struct_u64){ .a = 20 }, 21); | ||
| 2854 | } | ||
| 2855 | #endif | ||
| 2856 | #endif | ||
| 2857 | #endif | ||
| 2858 | |||
| 2744 | #if !defined(ZIG_PPC32) && !defined(__hexagon__) && !defined(__s390x__) | 2859 | #if !defined(ZIG_PPC32) && !defined(__hexagon__) && !defined(__s390x__) |
| 2745 | { | 2860 | { |
| 2746 | struct Struct_u64_u64 s = zig_ret_struct_u64_u64(); | 2861 | struct Struct_u64_u64 s = zig_ret_struct_u64_u64(); |
| ... | @@ -2818,7 +2933,7 @@ void run_c_tests(void) { | ... | @@ -2818,7 +2933,7 @@ void run_c_tests(void) { |
| 2818 | #endif | 2933 | #endif |
| 2819 | #endif | 2934 | #endif |
| 2820 | 2935 | ||
| 2821 | #if !defined __i386__ && !defined __arm__ && !defined __aarch64__ && \ | 2936 | #if !defined __i386__ && !defined __arm__ && !defined(__AARCH_BIG_ENDIAN) && \ |
| 2822 | !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \ | 2937 | !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \ |
| 2823 | !defined(__mips64__) && !defined(__hexagon__) && !defined(__s390x__) | 2938 | !defined(__mips64__) && !defined(__hexagon__) && !defined(__s390x__) |
| 2824 | { | 2939 | { |
| ... | @@ -2827,7 +2942,7 @@ void run_c_tests(void) { | ... | @@ -2827,7 +2942,7 @@ void run_c_tests(void) { |
| 2827 | } | 2942 | } |
| 2828 | #endif | 2943 | #endif |
| 2829 | 2944 | ||
| 2830 | #if !defined __arm__ && !defined __aarch64__ && \ | 2945 | #if !defined __arm__ && !defined(__AARCH_BIG_ENDIAN) && \ |
| 2831 | !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \ | 2946 | !defined __powerpc__ && !defined ZIG_RISCV64 && !defined(__loongarch__) && \ |
| 2832 | !defined(__mips64__) && !defined(__hexagon__) && !defined(__s390x__) | 2947 | !defined(__mips64__) && !defined(__hexagon__) && !defined(__s390x__) |
| 2833 | { | 2948 | { |
test/c_abi/main.zig+122-3| ... | @@ -269,6 +269,117 @@ export fn zig_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble | ... | @@ -269,6 +269,117 @@ export fn zig_cmultd_comp(a_r: f64, a_i: f64, b_r: f64, b_i: f64) ComplexDouble |
| 269 | return .{ .real = 1.5, .imag = 13.5 }; | 269 | return .{ .real = 1.5, .imag = 13.5 }; |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | const Struct_u8 = extern struct { | ||
| 273 | a: u8, | ||
| 274 | }; | ||
| 275 | |||
| 276 | export fn zig_ret_struct_u8() Struct_u8 { | ||
| 277 | return .{ .a = 1 }; | ||
| 278 | } | ||
| 279 | |||
| 280 | export fn zig_struct_u8(s: Struct_u8, i: usize) void { | ||
| 281 | expect(s.a == 2) catch @panic("test failure"); | ||
| 282 | expect(i == 3) catch @panic("test failure"); | ||
| 283 | } | ||
| 284 | |||
| 285 | extern fn c_ret_struct_u8() Struct_u8; | ||
| 286 | |||
| 287 | extern fn c_struct_u8(Struct_u8, usize) void; | ||
| 288 | |||
| 289 | test "C ABI struct u8" { | ||
| 290 | if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; | ||
| 291 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; | ||
| 292 | if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; | ||
| 293 | if (builtin.cpu.arch == .s390x) return error.SkipZigTest; | ||
| 294 | |||
| 295 | const s = c_ret_struct_u8(); | ||
| 296 | try expect(s.a == 4); | ||
| 297 | c_struct_u8(.{ .a = 5 }, 6); | ||
| 298 | } | ||
| 299 | |||
| 300 | const Struct_u16 = extern struct { | ||
| 301 | a: u16, | ||
| 302 | }; | ||
| 303 | |||
| 304 | export fn zig_ret_struct_u16() Struct_u16 { | ||
| 305 | return .{ .a = 7 }; | ||
| 306 | } | ||
| 307 | |||
| 308 | export fn zig_struct_u16(s: Struct_u16, i: usize) void { | ||
| 309 | expect(s.a == 8) catch @panic("test failure"); | ||
| 310 | expect(i == 9) catch @panic("test failure"); | ||
| 311 | } | ||
| 312 | |||
| 313 | extern fn c_ret_struct_u16() Struct_u16; | ||
| 314 | |||
| 315 | extern fn c_struct_u16(Struct_u16, usize) void; | ||
| 316 | |||
| 317 | test "C ABI struct u16" { | ||
| 318 | if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; | ||
| 319 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; | ||
| 320 | if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; | ||
| 321 | if (builtin.cpu.arch == .s390x) return error.SkipZigTest; | ||
| 322 | |||
| 323 | const s = c_ret_struct_u16(); | ||
| 324 | try expect(s.a == 10); | ||
| 325 | c_struct_u16(.{ .a = 11 }, 12); | ||
| 326 | } | ||
| 327 | |||
| 328 | const Struct_u32 = extern struct { | ||
| 329 | a: u32, | ||
| 330 | }; | ||
| 331 | |||
| 332 | export fn zig_ret_struct_u32() Struct_u32 { | ||
| 333 | return .{ .a = 13 }; | ||
| 334 | } | ||
| 335 | |||
| 336 | export fn zig_struct_u32(s: Struct_u32, i: usize) void { | ||
| 337 | expect(s.a == 14) catch @panic("test failure"); | ||
| 338 | expect(i == 15) catch @panic("test failure"); | ||
| 339 | } | ||
| 340 | |||
| 341 | extern fn c_ret_struct_u32() Struct_u32; | ||
| 342 | |||
| 343 | extern fn c_struct_u32(Struct_u32, usize) void; | ||
| 344 | |||
| 345 | test "C ABI struct u32" { | ||
| 346 | if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; | ||
| 347 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; | ||
| 348 | if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; | ||
| 349 | if (builtin.cpu.arch == .s390x) return error.SkipZigTest; | ||
| 350 | |||
| 351 | const s = c_ret_struct_u32(); | ||
| 352 | try expect(s.a == 16); | ||
| 353 | c_struct_u32(.{ .a = 17 }, 18); | ||
| 354 | } | ||
| 355 | |||
| 356 | const Struct_u64 = extern struct { | ||
| 357 | a: u64, | ||
| 358 | }; | ||
| 359 | |||
| 360 | export fn zig_ret_struct_u64() Struct_u64 { | ||
| 361 | return .{ .a = 19 }; | ||
| 362 | } | ||
| 363 | |||
| 364 | export fn zig_struct_u64(s: Struct_u64, i: usize) void { | ||
| 365 | expect(s.a == 20) catch @panic("test failure"); | ||
| 366 | expect(i == 21) catch @panic("test failure"); | ||
| 367 | } | ||
| 368 | |||
| 369 | extern fn c_ret_struct_u64() Struct_u64; | ||
| 370 | |||
| 371 | extern fn c_struct_u64(Struct_u64, usize) void; | ||
| 372 | |||
| 373 | test "C ABI struct u64" { | ||
| 374 | if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; | ||
| 375 | if (builtin.cpu.arch == .riscv32) return error.SkipZigTest; | ||
| 376 | if (builtin.cpu.arch == .s390x) return error.SkipZigTest; | ||
| 377 | |||
| 378 | const s = c_ret_struct_u64(); | ||
| 379 | try expect(s.a == 22); | ||
| 380 | c_struct_u64(.{ .a = 23 }, 24); | ||
| 381 | } | ||
| 382 | |||
| 272 | const Struct_u64_u64 = extern struct { | 383 | const Struct_u64_u64 = extern struct { |
| 273 | a: u64, | 384 | a: u64, |
| 274 | b: u64, | 385 | b: u64, |
| ... | @@ -5596,7 +5707,6 @@ test "CFF: Zig returns to C" { | ... | @@ -5596,7 +5707,6 @@ test "CFF: Zig returns to C" { |
| 5596 | test "CFF: C passes to Zig" { | 5707 | test "CFF: C passes to Zig" { |
| 5597 | if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; | 5708 | if (builtin.target.cpu.arch == .x86) return error.SkipZigTest; |
| 5598 | if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; | 5709 | if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; |
| 5599 | if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; | ||
| 5600 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; | 5710 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; |
| 5601 | if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; | 5711 | if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; |
| 5602 | if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; | 5712 | if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; |
| ... | @@ -5606,7 +5716,6 @@ test "CFF: C passes to Zig" { | ... | @@ -5606,7 +5716,6 @@ test "CFF: C passes to Zig" { |
| 5606 | try expectOk(c_send_CFF()); | 5716 | try expectOk(c_send_CFF()); |
| 5607 | } | 5717 | } |
| 5608 | test "CFF: C returns to Zig" { | 5718 | test "CFF: C returns to Zig" { |
| 5609 | if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest; | ||
| 5610 | if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; | 5719 | if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest; |
| 5611 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; | 5720 | if (builtin.cpu.arch.isMIPS64()) return error.SkipZigTest; |
| 5612 | if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; | 5721 | if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; |
| ... | @@ -5738,7 +5847,17 @@ test "C function that takes byval struct called via function pointer" { | ... | @@ -5738,7 +5847,17 @@ test "C function that takes byval struct called via function pointer" { |
| 5738 | 5847 | ||
| 5739 | extern fn c_f16(f16) f16; | 5848 | extern fn c_f16(f16) f16; |
| 5740 | test "f16 bare" { | 5849 | test "f16 bare" { |
| 5741 | if (!builtin.cpu.arch.isAARCH64()) return error.SkipZigTest; | 5850 | if (builtin.cpu.arch == .x86_64) return error.SkipZigTest; |
| 5851 | if (builtin.cpu.arch == .x86) return error.SkipZigTest; | ||
| 5852 | if (builtin.cpu.arch == .hexagon) return error.SkipZigTest; | ||
| 5853 | if (builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; | ||
| 5854 | if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest; | ||
| 5855 | if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest; | ||
| 5856 | if (builtin.cpu.arch == .s390x) return error.SkipZigTest; | ||
| 5857 | if (builtin.cpu.arch.isWasm()) return error.SkipZigTest; | ||
| 5858 | if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; | ||
| 5859 | |||
| 5860 | if (builtin.cpu.arch.isArm()) return error.SkipZigTest; | ||
| 5742 | 5861 | ||
| 5743 | const a = c_f16(12); | 5862 | const a = c_f16(12); |
| 5744 | try expect(a == 34); | 5863 | try expect(a == 34); |
test/tests.zig-5| ... | @@ -2795,11 +2795,6 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { | ... | @@ -2795,11 +2795,6 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { |
| 2795 | } else continue; | 2795 | } else continue; |
| 2796 | } | 2796 | } |
| 2797 | 2797 | ||
| 2798 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { | ||
| 2799 | // https://github.com/ziglang/zig/issues/14908 | ||
| 2800 | continue; | ||
| 2801 | } | ||
| 2802 | |||
| 2803 | const test_mod = b.createModule(.{ | 2798 | const test_mod = b.createModule(.{ |
| 2804 | .root_source_file = b.path("test/c_abi/main.zig"), | 2799 | .root_source_file = b.path("test/c_abi/main.zig"), |
| 2805 | .target = resolved_target, | 2800 | .target = resolved_target, |