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
76877687 ZigType *tag_type = union_type->data.unionation.tag_type;
76887688 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
76897689 if (gen_field_count == 0) {
7690 union_type->llvm_type = get_llvm_type(g, tag_type);
7691 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
7690 if (tag_type == nullptr) {
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 }
76927697 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;
76937698 return;
76947699 }
src/ir.cpp+7-2
......@@ -17464,7 +17464,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1746417464 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
1746517465 source_instr, container_ptr, container_type);
1746617466 }
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,
1746817473 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1746917474 if (instr_is_comptime(container_ptr)) {
1747017475 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_
1748117486 if (initializing) {
1748217487 ConstExprValue *payload_val = create_const_vals(1);
1748317488 payload_val->special = ConstValSpecialUndef;
17484 payload_val->type = field->type_entry;
17489 payload_val->type = field_type;
1748517490 payload_val->parent.id = ConstParentIdUnion;
1748617491 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" {
457457 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
458458 expect(value.Byte == 2);
459459}
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}