authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-14 00:37:54-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-14 00:38:22-04:00
log3d38feded93cb2ccecf5ecb538c8957a965a891e
tree280a01fb2c02360887e83b43e4a78c1feca0cac9
parent1e03cf1739c9c7407c4b3a56ee5f2705805c6a83
signaturelock-open Commit is signed but in an unrecognized format.

fix tagged union with all void payloads but meaningful tag

closes #1322

3 files changed, 21 insertions(+), 1 deletions(-)

src/codegen.cpp+1-1
...@@ -4715,7 +4715,6 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa...@@ -4715,7 +4715,6 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
47154715
4716static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {4716static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
4717 ZigType *union_type = instruction->value->value.type;4717 ZigType *union_type = instruction->value->value.type;
4718 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
47194718
4720 ZigType *tag_type = union_type->data.unionation.tag_type;4719 ZigType *tag_type = union_type->data.unionation.tag_type;
4721 if (!type_has_bits(tag_type))4720 if (!type_has_bits(tag_type))
...@@ -4725,6 +4724,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir...@@ -4725,6 +4724,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
4725 if (union_type->data.unionation.gen_field_count == 0)4724 if (union_type->data.unionation.gen_field_count == 0)
4726 return union_val;4725 return union_val;
47274726
4727 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
4728 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,4728 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
4729 union_type->data.unionation.gen_tag_index, "");4729 union_type->data.unionation.gen_tag_index, "");
4730 ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);4730 ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);
test/behavior.zig+1
...@@ -10,6 +10,7 @@ comptime {...@@ -10,6 +10,7 @@ comptime {
10 _ = @import("cases/bool.zig");10 _ = @import("cases/bool.zig");
11 _ = @import("cases/bugs/1111.zig");11 _ = @import("cases/bugs/1111.zig");
12 _ = @import("cases/bugs/1277.zig");12 _ = @import("cases/bugs/1277.zig");
13 _ = @import("cases/bugs/1322.zig");
13 _ = @import("cases/bugs/1381.zig");14 _ = @import("cases/bugs/1381.zig");
14 _ = @import("cases/bugs/1421.zig");15 _ = @import("cases/bugs/1421.zig");
15 _ = @import("cases/bugs/1442.zig");16 _ = @import("cases/bugs/1442.zig");
test/cases/bugs/1322.zig created+19
...@@ -0,0 +1,19 @@
1const std = @import("std");
2
3const B = union(enum) {
4 c: C,
5 None,
6};
7
8const A = struct {
9 b: B,
10};
11
12const C = struct {};
13
14test "tagged union with all void fields but a meaningful tag" {
15 var a: A = A{ .b = B{ .c = C{} } };
16 std.debug.assert(@TagType(B)(a.b) == @TagType(B).c);
17 a = A{ .b = B.None };
18 std.debug.assert(@TagType(B)(a.b) == @TagType(B).None);
19}