Merge branch 'fixSegfault' of https://github.com/marler8997/zig into marler8997-fixSegfault

master
Andrew Kelley 2019-09-03 18:15:01 -04:00
commit a81e4351a2
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 17 additions and 2 deletions

View File

@ -7687,8 +7687,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
ZigType *tag_type = union_type->data.unionation.tag_type;
uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
if (gen_field_count == 0) {
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();
}