Commit 616f74ba20

Andrew Kelley <andrew@ziglang.org>
2024-02-11 22:14:59
add behavior test for recently fixed wasm backend bug
Adds the corresponding behavior test for the fix in 320c4d68f5f40794ae31d5535de9c3a8ff5cb471.
1 parent d40b71a
Changed files (1)
test
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);
+    }
+}