Fix issue 3058: zig build segfault

This commit is contained in:
Jonathan Marler 2019-08-24 01:54:44 -06:00
parent ec2f9ef4e8
commit 1b19c28c79
2 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

@ -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();
}