From 1b19c28c79ac20c4b8880742172834f881b47dea Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Sat, 24 Aug 2019 01:54:44 -0600 Subject: [PATCH] Fix issue 3058: zig build segfault --- src/analyze.cpp | 9 +++++++-- test/stage1/behavior/union.zig | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 35c598ab9..fa239808f 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -7198,8 +7198,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member; ZigType *tag_type = union_type->data.unionation.tag_type; if (most_aligned_union_member == nullptr) { - union_type->llvm_type = get_llvm_type(g, tag_type); - union_type->llvm_di_type = get_llvm_di_type(g, tag_type); + if (tag_type == nullptr) { + union_type->llvm_type = g->builtin_types.entry_void->llvm_type; + union_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type; + } else { + union_type->llvm_type = get_llvm_type(g, tag_type); + union_type->llvm_di_type = get_llvm_di_type(g, tag_type); + } union_type->data.unionation.resolve_status = ResolveStatusLLVMFull; return; } diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index 7d6a8154e..3df8aef3b 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -457,3 +457,13 @@ test "@unionInit can modify a pointer value" { value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2); expect(value.Byte == 2); } + +test "union no tag with struct member" { + const Struct = struct { }; + const Union = union { + s : Struct, + pub fn foo(self: *@This()) void { } + }; + var u = Union { .s = Struct {} }; + u.foo(); +}