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
47154715
47164716static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
47174717 ZigType *union_type = instruction->value->value.type;
4718 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
47194718
47204719 ZigType *tag_type = union_type->data.unionation.tag_type;
47214720 if (!type_has_bits(tag_type))
......@@ -4725,6 +4724,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
47254724 if (union_type->data.unionation.gen_field_count == 0)
47264725 return union_val;
47274726
4727 assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
47284728 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
47294729 union_type->data.unionation.gen_tag_index, "");
47304730 ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);
test/behavior.zig+1
......@@ -10,6 +10,7 @@ comptime {
1010 _ = @import("cases/bool.zig");
1111 _ = @import("cases/bugs/1111.zig");
1212 _ = @import("cases/bugs/1277.zig");
13 _ = @import("cases/bugs/1322.zig");
1314 _ = @import("cases/bugs/1381.zig");
1415 _ = @import("cases/bugs/1421.zig");
1516 _ = @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}