authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-11 14:14:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-11 14:14:59-07:00
log616f74ba2098297fbe430651930f9e784909263f
tree48d0295374ad0b69edb164e7e9ec61a1a1e01253
parentd40b71a39fa3f7275ab5123d741e12c58366860e

add behavior test for recently fixed wasm backend bug

Adds the corresponding behavior test for the fix in 320c4d68f5f40794ae31d5535de9c3a8ff5cb471.

1 files changed, 29 insertions(+), 0 deletions(-)

test/behavior/packed-struct.zig+29
......@@ -1248,3 +1248,32 @@ test "bitcasting a packed struct at comptime and using the result" {
12481248 _ = Struct.bitcast(@as(u64, 0)).cannotReach();
12491249 }
12501250}
1251
1252test "2-byte packed struct argument in C calling convention" {
1253 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1254 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
1255 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1256 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1257
1258 const S = packed struct(u16) {
1259 x: u15 = 0,
1260 y: u1 = 0,
1261
1262 fn foo(s: @This()) callconv(.C) i32 {
1263 return s.x;
1264 }
1265 fn bar(s: @This()) !void {
1266 try expect(foo(s) == 1);
1267 }
1268 };
1269 {
1270 var s: S = .{};
1271 s.x += 1;
1272 try S.bar(s);
1273 }
1274 comptime {
1275 var s: S = .{};
1276 s.x += 1;
1277 try S.bar(s);
1278 }
1279}