diff --git a/src/analyze.cpp b/src/analyze.cpp index b3684021aa..9afd4cedc8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1242,16 +1242,16 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { case TypeTableEntryIdPointer: return type_allowed_in_extern(g, type_entry->data.pointer.child_type); case TypeTableEntryIdStruct: - return type_entry->data.structure.layout == ContainerLayoutExtern; + return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked; case TypeTableEntryIdMaybe: { TypeTableEntry *child_type = type_entry->data.maybe.child_type; return child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn; } case TypeTableEntryIdEnum: - return type_entry->data.enumeration.layout == ContainerLayoutExtern; + return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked; case TypeTableEntryIdUnion: - return type_entry->data.unionation.layout == ContainerLayoutExtern; + return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked; } zig_unreachable(); } diff --git a/test/cases/misc.zig b/test/cases/misc.zig index cfc3456738..85757efbb8 100644 --- a/test/cases/misc.zig +++ b/test/cases/misc.zig @@ -617,3 +617,19 @@ test "cold function" { fn thisIsAColdFn() void { @setCold(true); } + + +const PackedStruct = packed struct { a: u8, b: u8, }; +const PackedUnion = packed union { a: u8, b: u32, }; +const PackedEnum = packed enum { A, B, }; + +test "packed struct, enum, union parameters in extern function" { + testPackedStuff( + PackedStruct{.a = 1, .b = 2}, + PackedUnion{.a = 1}, + PackedEnum.A, + ); +} + +export fn testPackedStuff(a: &const PackedStruct, b: &const PackedUnion, c: PackedEnum) void { +} diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 64ee69ba18..fe167c472c 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -5,12 +5,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { \\export fn foo() boid {} , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'"); - cases.add("function with non-extern enum parameter", + cases.add("function with non-extern non-packed enum parameter", \\const Foo = enum { A, B, C }; \\export fn entry(foo: Foo) void { } , ".tmp_source.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); - cases.add("function with non-extern struct parameter", + cases.add("function with non-extern non-packed struct parameter", \\const Foo = struct { \\ A: i32, \\ B: f32, @@ -19,7 +19,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { \\export fn entry(foo: Foo) void { } , ".tmp_source.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'"); - cases.add("function with non-extern union parameter", + cases.add("function with non-extern non-packed union parameter", \\const Foo = union { \\ A: i32, \\ B: f32,