authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-29 18:21:38-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-08-29 18:21:38-04:00
logd2d42cf7ba5d965786d4bfb2fdc61dbd9a0d2ae5
treef5134d76c873b485f831881c3b28ef897a21f4b3
parente8edc4cf831229f9acfa07001f385bac7fec89b0
parent1eb22e7ad6f700a72d34cdb36e614c95bdab0464
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #12641 from Luukdegram/wasm-c-types

stage2: fix size of c_longdouble for Wasm target

4 files changed, 22 insertions(+), 0 deletions(-)

src/type.zig+4
...@@ -6593,6 +6593,8 @@ pub const CType = enum {...@@ -6593,6 +6593,8 @@ pub const CType = enum {
6593 .powerpcle,6593 .powerpcle,
6594 .powerpc64,6594 .powerpc64,
6595 .powerpc64le,6595 .powerpc64le,
6596 .wasm32,
6597 .wasm64,
6596 => return 128,6598 => return 128,
65976599
6598 else => return 64,6600 else => return 64,
...@@ -6641,6 +6643,8 @@ pub const CType = enum {...@@ -6641,6 +6643,8 @@ pub const CType = enum {
6641 .powerpcle,6643 .powerpcle,
6642 .powerpc64,6644 .powerpc64,
6643 .powerpc64le,6645 .powerpc64le,
6646 .wasm32,
6647 .wasm64,
6644 => return 128,6648 => return 128,
66456649
6646 else => return 64,6650 else => return 64,
test/behavior/cast.zig+1
...@@ -1430,6 +1430,7 @@ test "coerce between pointers of compatible differently-named floats" {...@@ -1430,6 +1430,7 @@ test "coerce between pointers of compatible differently-named floats" {
1430 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1430 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1431 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1431 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1432 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO1432 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1433 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
14331434
1434 if (builtin.os.tag == .windows) {1435 if (builtin.os.tag == .windows) {
1435 // https://github.com/ziglang/zig/issues/123961436 // https://github.com/ziglang/zig/issues/12396
test/c_abi/cfuncs.c+6
...@@ -33,6 +33,7 @@ void zig_five_integers(int32_t, int32_t, int32_t, int32_t, int32_t);...@@ -33,6 +33,7 @@ void zig_five_integers(int32_t, int32_t, int32_t, int32_t, int32_t);
3333
34void zig_f32(float);34void zig_f32(float);
35void zig_f64(double);35void zig_f64(double);
36void zig_longdouble(long double);
36void zig_five_floats(float, float, float, float, float);37void zig_five_floats(float, float, float, float, float);
3738
38bool zig_ret_bool();39bool zig_ret_bool();
...@@ -157,6 +158,7 @@ void run_c_tests(void) {...@@ -157,6 +158,7 @@ void run_c_tests(void) {
157158
158 zig_f32(12.34f);159 zig_f32(12.34f);
159 zig_f64(56.78);160 zig_f64(56.78);
161 zig_longdouble(12.34l);
160 zig_five_floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f);162 zig_five_floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f);
161163
162 zig_ptr((void*)0xdeadbeefL);164 zig_ptr((void*)0xdeadbeefL);
...@@ -271,6 +273,10 @@ void c_f64(double x) {...@@ -271,6 +273,10 @@ void c_f64(double x) {
271 assert_or_panic(x == 56.78);273 assert_or_panic(x == 56.78);
272}274}
273275
276void c_long_double(long double x) {
277 assert_or_panic(x == 12.34l);
278}
279
274void c_ptr(void *x) {280void c_ptr(void *x) {
275 assert_or_panic(x == (void*)0xdeadbeefL);281 assert_or_panic(x == (void*)0xdeadbeefL);
276}282}
test/c_abi/main.zig+11
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const print = std.debug.print;3const print = std.debug.print;
3const expect = std.testing.expect;4const expect = std.testing.expect;
45
...@@ -89,6 +90,7 @@ export fn zig_struct_u128(a: U128) void {...@@ -89,6 +90,7 @@ export fn zig_struct_u128(a: U128) void {
8990
90extern fn c_f32(f32) void;91extern fn c_f32(f32) void;
91extern fn c_f64(f64) void;92extern fn c_f64(f64) void;
93extern fn c_long_double(c_longdouble) void;
9294
93// On windows x64, the first 4 are passed via registers, others on the stack.95// On windows x64, the first 4 are passed via registers, others on the stack.
94extern fn c_five_floats(f32, f32, f32, f32, f32) void;96extern fn c_five_floats(f32, f32, f32, f32, f32) void;
...@@ -107,12 +109,21 @@ test "C ABI floats" {...@@ -107,12 +109,21 @@ test "C ABI floats" {
107 c_five_floats(1.0, 2.0, 3.0, 4.0, 5.0);109 c_five_floats(1.0, 2.0, 3.0, 4.0, 5.0);
108}110}
109111
112test "C ABI long double" {
113 if (!builtin.cpu.arch.isWasm()) return error.SkipZigTest;
114 c_long_double(12.34);
115}
116
110export fn zig_f32(x: f32) void {117export fn zig_f32(x: f32) void {
111 expect(x == 12.34) catch @panic("test failure: zig_f32");118 expect(x == 12.34) catch @panic("test failure: zig_f32");
112}119}
113export fn zig_f64(x: f64) void {120export fn zig_f64(x: f64) void {
114 expect(x == 56.78) catch @panic("test failure: zig_f64");121 expect(x == 56.78) catch @panic("test failure: zig_f64");
115}122}
123export fn zig_longdouble(x: c_longdouble) void {
124 if (!builtin.cpu.arch.isWasm()) return; // waiting for #1481
125 expect(x == 12.34) catch @panic("test failure: zig_longdouble");
126}
116127
117extern fn c_ptr(*anyopaque) void;128extern fn c_ptr(*anyopaque) void;
118129