aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-03 18:26:10 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-03 18:26:10 -0400
commit42cc4a406bd4d037f4203fa2ebca2853db33c780 (patch)
tree993389ab3f52fdb62cf48366cc3fcb92737284b5
parentfc0f8d0359777580c771848361166f97a85deddd (diff)
parent18620756520d198f581b9a9acbf25c8cbb79ad11 (diff)
downloadzig-42cc4a406bd4d037f4203fa2ebca2853db33c780.tar.gz
zig-42cc4a406bd4d037f4203fa2ebca2853db33c780.zip
Merge branch 'marler8997-fixSegfault'
-rw-r--r--src/analyze.cpp9
-rw-r--r--src/ir.cpp9
-rw-r--r--test/stage1/behavior/union.zig10
3 files changed, 24 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 9b361baa56..188da18515 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -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;
}
diff --git a/src/ir.cpp b/src/ir.cpp
index e3b440d0f5..abf4f477a8 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -17464,7 +17464,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
source_instr, container_ptr, container_type);
}
- ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
+
+ ZigType *field_type = resolve_union_field_type(ira->codegen, field);
+ if (field_type == nullptr)
+ return ira->codegen->invalid_instruction;
+
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
if (instr_is_comptime(container_ptr)) {
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_
if (initializing) {
ConstExprValue *payload_val = create_const_vals(1);
payload_val->special = ConstValSpecialUndef;
- payload_val->type = field->type_entry;
+ payload_val->type = field_type;
payload_val->parent.id = ConstParentIdUnion;
payload_val->parent.data.p_union.union_val = union_val;
diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig
index 7d6a8154ea..d28a0f8ea4 100644
--- a/test/stage1/behavior/union.zig
+++ b/test/stage1/behavior/union.zig
@@ -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();
+}