From 616f74ba2098297fbe430651930f9e784909263f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 11 Feb 2024 14:14:59 -0700 Subject: [PATCH] add behavior test for recently fixed wasm backend bug Adds the corresponding behavior test for the fix in 320c4d68f5f40794ae31d5535de9c3a8ff5cb471. --- test/behavior/packed-struct.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 48e75706cd..27f460e175 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -1248,3 +1248,32 @@ test "bitcasting a packed struct at comptime and using the result" { _ = Struct.bitcast(@as(u64, 0)).cannotReach(); } } + +test "2-byte packed struct argument in C calling convention" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + + const S = packed struct(u16) { + x: u15 = 0, + y: u1 = 0, + + fn foo(s: @This()) callconv(.C) i32 { + return s.x; + } + fn bar(s: @This()) !void { + try expect(foo(s) == 1); + } + }; + { + var s: S = .{}; + s.x += 1; + try S.bar(s); + } + comptime { + var s: S = .{}; + s.x += 1; + try S.bar(s); + } +}