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 {
65936593 .powerpcle,
65946594 .powerpc64,
65956595 .powerpc64le,
6596 .wasm32,
6597 .wasm64,
65966598 => return 128,
65976599
65986600 else => return 64,
......@@ -6641,6 +6643,8 @@ pub const CType = enum {
66416643 .powerpcle,
66426644 .powerpc64,
66436645 .powerpc64le,
6646 .wasm32,
6647 .wasm64,
66446648 => return 128,
66456649
66466650 else => return 64,
test/behavior/cast.zig+1
......@@ -1430,6 +1430,7 @@ test "coerce between pointers of compatible differently-named floats" {
14301430 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
14311431 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
14321432 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
1433 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
14331434
14341435 if (builtin.os.tag == .windows) {
14351436 // 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);
3333
3434void zig_f32(float);
3535void zig_f64(double);
36void zig_longdouble(long double);
3637void zig_five_floats(float, float, float, float, float);
3738
3839bool zig_ret_bool();
......@@ -157,6 +158,7 @@ void run_c_tests(void) {
157158
158159 zig_f32(12.34f);
159160 zig_f64(56.78);
161 zig_longdouble(12.34l);
160162 zig_five_floats(1.0f, 2.0f, 3.0f, 4.0f, 5.0f);
161163
162164 zig_ptr((void*)0xdeadbeefL);
......@@ -271,6 +273,10 @@ void c_f64(double x) {
271273 assert_or_panic(x == 56.78);
272274}
273275
276void c_long_double(long double x) {
277 assert_or_panic(x == 12.34l);
278}
279
274280void c_ptr(void *x) {
275281 assert_or_panic(x == (void*)0xdeadbeefL);
276282}
test/c_abi/main.zig+11
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const print = std.debug.print;
34const expect = std.testing.expect;
45
......@@ -89,6 +90,7 @@ export fn zig_struct_u128(a: U128) void {
8990
9091extern fn c_f32(f32) void;
9192extern fn c_f64(f64) void;
93extern fn c_long_double(c_longdouble) void;
9294
9395// On windows x64, the first 4 are passed via registers, others on the stack.
9496extern fn c_five_floats(f32, f32, f32, f32, f32) void;
......@@ -107,12 +109,21 @@ test "C ABI floats" {
107109 c_five_floats(1.0, 2.0, 3.0, 4.0, 5.0);
108110}
109111
112test "C ABI long double" {
113 if (!builtin.cpu.arch.isWasm()) return error.SkipZigTest;
114 c_long_double(12.34);
115}
116
110117export fn zig_f32(x: f32) void {
111118 expect(x == 12.34) catch @panic("test failure: zig_f32");
112119}
113120export fn zig_f64(x: f64) void {
114121 expect(x == 56.78) catch @panic("test failure: zig_f64");
115122}
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
117128extern fn c_ptr(*anyopaque) void;
118129