authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 18:26:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-03 18:26:10-04:00
log42cc4a406bd4d037f4203fa2ebca2853db33c780
tree993389ab3f52fdb62cf48366cc3fcb92737284b5
parentfc0f8d0359777580c771848361166f97a85deddd
parent18620756520d198f581b9a9acbf25c8cbb79ad11
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'marler8997-fixSegfault'


3 files changed, 24 insertions(+), 4 deletions(-)

src/analyze.cpp+7-2
...@@ -7687,8 +7687,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta...@@ -7687,8 +7687,13 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
7687 ZigType *tag_type = union_type->data.unionation.tag_type;7687 ZigType *tag_type = union_type->data.unionation.tag_type;
7688 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;7688 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
7689 if (gen_field_count == 0) {7689 if (gen_field_count == 0) {
7690 union_type->llvm_type = get_llvm_type(g, tag_type);7690 if (tag_type == nullptr) {
7691 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);7691 union_type->llvm_type = g->builtin_types.entry_void->llvm_type;
7692 union_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
7693 } else {
7694 union_type->llvm_type = get_llvm_type(g, tag_type);
7695 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
7696 }
7692 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;7697 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;
7693 return;7698 return;
7694 }7699 }
src/ir.cpp+7-2
...@@ -17464,7 +17464,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -17464,7 +17464,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
17464 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,17464 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
17465 source_instr, container_ptr, container_type);17465 source_instr, container_ptr, container_type);
17466 }17466 }
17467 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,17467
17468 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
17469 if (field_type == nullptr)
17470 return ira->codegen->invalid_instruction;
17471
17472 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
17468 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);17473 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
17469 if (instr_is_comptime(container_ptr)) {17474 if (instr_is_comptime(container_ptr)) {
17470 ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);17475 ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
...@@ -17481,7 +17486,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -17481,7 +17486,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
17481 if (initializing) {17486 if (initializing) {
17482 ConstExprValue *payload_val = create_const_vals(1);17487 ConstExprValue *payload_val = create_const_vals(1);
17483 payload_val->special = ConstValSpecialUndef;17488 payload_val->special = ConstValSpecialUndef;
17484 payload_val->type = field->type_entry;17489 payload_val->type = field_type;
17485 payload_val->parent.id = ConstParentIdUnion;17490 payload_val->parent.id = ConstParentIdUnion;
17486 payload_val->parent.data.p_union.union_val = union_val;17491 payload_val->parent.data.p_union.union_val = union_val;
1748717492
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}