authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2019-08-24 01:54:44-06:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2019-08-24 10:47:27-06:00
log1b19c28c79ac20c4b8880742172834f881b47dea
tree186b6855d65fc05816652b50859d4c609d825e2e
parentec2f9ef4e8be5995ab652dde59b12ee340a9e28d

Fix issue 3058: zig build segfault


2 files changed, 17 insertions(+), 2 deletions(-)

src/analyze.cpp+7-2
...@@ -7198,8 +7198,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta...@@ -7198,8 +7198,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
7198 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;7198 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
7199 ZigType *tag_type = union_type->data.unionation.tag_type;7199 ZigType *tag_type = union_type->data.unionation.tag_type;
7200 if (most_aligned_union_member == nullptr) {7200 if (most_aligned_union_member == nullptr) {
7201 union_type->llvm_type = get_llvm_type(g, tag_type);7201 if (tag_type == nullptr) {
7202 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);7202 union_type->llvm_type = g->builtin_types.entry_void->llvm_type;
7203 union_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
7204 } else {
7205 union_type->llvm_type = get_llvm_type(g, tag_type);
7206 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
7207 }
7203 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;7208 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;
7204 return;7209 return;
7205 }7210 }
test/stage1/behavior/union.zig+10
...@@ -457,3 +457,13 @@ test "@unionInit can modify a pointer value" {...@@ -457,3 +457,13 @@ test "@unionInit can modify a pointer value" {
457 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);457 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
458 expect(value.Byte == 2);458 expect(value.Byte == 2);
459}459}
460
461test "union no tag with struct member" {
462 const Struct = struct { };
463 const Union = union {
464 s : Struct,
465 pub fn foo(self: *@This()) void { }
466 };
467 var u = Union { .s = Struct {} };
468 u.foo();
469}