aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-09-01 13:48:36 +0300
committerVeikka Tuominen <git@vexu.eu>2022-09-02 17:57:10 +0300
commit4462d082240d71e671a8d3d5fb3da81e70c4760e (patch)
tree197bd8c2b1e7d79ce4ddcbb6a94a9a1196e63f78
parent2cd3989cb32d97c8a60d9cf4154e049815259b46 (diff)
downloadzig-4462d082240d71e671a8d3d5fb3da81e70c4760e.tar.gz
zig-4462d082240d71e671a8d3d5fb3da81e70c4760e.zip
stage2 llvm: fix passing packed structs to callconv(.C) functions
Closes #12704
-rw-r--r--src/codegen/llvm.zig2
-rw-r--r--test/behavior/packed-struct.zig26
2 files changed, 28 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 45426c5ee0..6c138df060 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -9853,6 +9853,8 @@ const ParamTypeIterator = struct {
.AnyFrame,
.Vector,
=> true,
+ .Struct => ty.containerLayout() == .Packed,
+ .Union => ty.containerLayout() == .Packed,
else => false,
};
diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig
index bd312e9cda..9834ba5f3d 100644
--- a/test/behavior/packed-struct.zig
+++ b/test/behavior/packed-struct.zig
@@ -579,3 +579,29 @@ test "runtime init of unnamed packed struct type" {
}
}{ .x = z }).m();
}
+
+test "packed struct passed to callconv(.C) function" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+
+ const S = struct {
+ const Packed = packed struct {
+ a: u16,
+ b: bool = true,
+ c: bool = true,
+ d: u46 = 0,
+ };
+
+ fn foo(p: Packed, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) callconv(.C) bool {
+ return p.a == 12345 and p.b == true and p.c == true and p.d == 0 and a1 == 5 and a2 == 4 and a3 == 3 and a4 == 2 and a5 == 1;
+ }
+ };
+ const result = S.foo(S.Packed{
+ .a = 12345,
+ .b = true,
+ .c = true,
+ }, 5, 4, 3, 2, 1);
+ try expect(result);
+}