aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-08-21 12:25:19 +0300
committerVeikka Tuominen <git@vexu.eu>2022-08-21 12:51:40 +0300
commitd48af541c7aa235948621cdbc250d983af303977 (patch)
tree8dbe65a62e708f182371b207896ebe33cf1586b4 /src/codegen
parente8102d8738eafb969e03b0609c60be73326610eb (diff)
downloadzig-d48af541c7aa235948621cdbc250d983af303977.tar.gz
zig-d48af541c7aa235948621cdbc250d983af303977.zip
Sema: handle union and enum field order being different
Closes #12543
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig3
-rw-r--r--src/codegen/llvm.zig2
2 files changed, 2 insertions, 3 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 81a892183f..4a09c09cc9 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -835,7 +835,6 @@ pub const DeclGen = struct {
},
.Union => {
const union_obj = val.castTag(.@"union").?.data;
- const union_ty = ty.cast(Type.Payload.Union).?.data;
const layout = ty.unionGetLayout(target);
try writer.writeAll("(");
@@ -851,7 +850,7 @@ pub const DeclGen = struct {
try writer.writeAll(".payload = {");
}
- const index = union_ty.tag_ty.enumTagFieldIndex(union_obj.tag, dg.module).?;
+ const index = ty.unionTagFieldIndex(union_obj.tag, dg.module).?;
const field_ty = ty.unionFields().values()[index].ty;
const field_name = ty.unionFields().keys()[index];
if (field_ty.hasRuntimeBits()) {
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index d50b463606..5c537cd5bc 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -3502,7 +3502,7 @@ pub const DeclGen = struct {
});
}
const union_obj = tv.ty.cast(Type.Payload.Union).?.data;
- const field_index = union_obj.tag_ty.enumTagFieldIndex(tag_and_val.tag, dg.module).?;
+ const field_index = tv.ty.unionTagFieldIndex(tag_and_val.tag, dg.module).?;
assert(union_obj.haveFieldTypes());
// Sometimes we must make an unnamed struct because LLVM does