diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-09-20 23:53:06 -0400 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2023-09-23 13:04:56 -0400 |
| commit | 2fddd767ba20374e7677003c101e60f470c3804c (patch) | |
| tree | 91ffbed5086771488201cebd82be6e1554ac14b5 /src/codegen/c.zig | |
| parent | ce919ccf45951856a762ffdb8ef850301cd8c588 (diff) | |
| download | zig-2fddd767ba20374e7677003c101e60f470c3804c.tar.gz zig-2fddd767ba20374e7677003c101e60f470c3804c.zip | |
sema: add support for unions in readFromMemory and writeToMemory
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 54e13db9a1..0b634e5038 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1439,7 +1439,10 @@ pub const DeclGen = struct { } const union_obj = mod.typeToUnion(ty).?; - const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?; + const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()) orelse f: { + assert(union_obj.getLayout(ip) == .Extern); + break :f mod.unionLargestField(union_obj).index; + }; const field_ty = union_obj.field_types.get(ip)[field_i].toType(); const field_name = union_obj.field_names.get(ip)[field_i]; if (union_obj.getLayout(ip) == .Packed) { |
