authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 11:34:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-25 11:34:07-04:00
logfa6c20a02d2ee7648f69d9ba3b19fa600e8dd0e9
tree2453616dd22b5c3fc14c07eea88b0dcc8c158a43
parentd277a1196b85cf51a22f7c6b41ad0df7804c71bd
signaturelock-open Commit is signed but in an unrecognized format.

hook up unions with lazy values

this case works now: ```zig const Expr = union(enum) { Literal: u8, Question: *Expr, }; ```

3 files changed, 112 insertions(+), 78 deletions(-)

src/all_types.hpp+6-3
......@@ -489,10 +489,12 @@ struct TypeEnumField {
489489
490490struct TypeUnionField {
491491 Buf *name;
492 ZigType *type_entry; // available after ResolveStatusSizeKnown
493 ConstExprValue *type_val; // available after ResolveStatusZeroBitsKnown
492494 TypeEnumField *enum_field;
493 ZigType *type_entry;
494495 AstNode *decl_node;
495496 uint32_t gen_index;
497 uint32_t align;
496498};
497499
498500enum NodeType {
......@@ -1247,7 +1249,7 @@ struct ZigTypeUnion {
12471249 HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;
12481250 ZigType *tag_type; // always an enum or null
12491251 LLVMTypeRef union_llvm_type;
1250 ZigType *most_aligned_union_member;
1252 TypeUnionField *most_aligned_union_member;
12511253 size_t gen_union_index;
12521254 size_t gen_tag_index;
12531255 size_t union_abi_size;
......@@ -1262,7 +1264,8 @@ struct ZigTypeUnion {
12621264 // whether any of the fields require comptime
12631265 // the value is not valid until zero_bits_known == true
12641266 bool requires_comptime;
1265 bool resolve_loop_flag;
1267 bool resolve_loop_flag_zero_bits;
1268 bool resolve_loop_flag_other;
12661269};
12671270
12681271struct FnGenParamInfo {
src/analyze.cpp+105-74
......@@ -961,10 +961,12 @@ static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, Zi
961961 Error err;
962962 if (type_val->special != ConstValSpecialLazy) {
963963 assert(type_val->special == ConstValSpecialStatic);
964 if (type_val->data.x_type->id == ZigTypeIdStruct &&
965 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits)
964 if ((type_val->data.x_type->id == ZigTypeIdStruct &&
965 type_val->data.x_type->data.structure.resolve_loop_flag_zero_bits) ||
966 (type_val->data.x_type->id == ZigTypeIdUnion &&
967 type_val->data.x_type->data.unionation.resolve_loop_flag_zero_bits))
966968 {
967 // Does a struct which contains a pointer field to itself have bits? Yes.
969 // Does a struct/union which contains a pointer field to itself have bits? Yes.
968970 *is_zero_bits = false;
969971 return ErrorNone;
970972 }
......@@ -1079,7 +1081,7 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue
10791081 zig_unreachable();
10801082}
10811083
1082static Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, size_t *abi_align) {
1084static Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, uint32_t *abi_align) {
10831085 Error err;
10841086 if (type_val->special != ConstValSpecialLazy) {
10851087 assert(type_val->special == ConstValSpecialStatic);
......@@ -1917,7 +1919,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
19171919
19181920 AstNode *decl_node = union_type->data.structure.decl_node;
19191921
1920 if (union_type->data.unionation.resolve_loop_flag) {
1922 if (union_type->data.unionation.resolve_loop_flag_other) {
19211923 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
19221924 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
19231925 g->trace_err = add_node_error(g, decl_node,
......@@ -1927,9 +1929,9 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
19271929 }
19281930
19291931 // set temporary flag
1930 union_type->data.unionation.resolve_loop_flag = true;
1932 union_type->data.unionation.resolve_loop_flag_other = true;
19311933
1932 ZigType *most_aligned_union_member = nullptr;
1934 TypeUnionField *most_aligned_union_member = nullptr;
19331935 uint32_t field_count = union_type->data.unionation.src_field_count;
19341936 bool packed = union_type->data.unionation.layout == ContainerLayoutPacked;
19351937
......@@ -1938,33 +1940,32 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
19381940 if (field->gen_index == UINT32_MAX)
19391941 continue;
19401942
1941 src_assert(field->type_entry != nullptr, decl_node);
1942
1943 size_t this_field_align;
1944 if (packed) {
1945 // TODO: https://github.com/ziglang/zig/issues/1512
1946 this_field_align = 1;
1943 AstNode *align_expr = field->decl_node->data.struct_field.align_expr;
1944 if (align_expr != nullptr) {
1945 if (!analyze_const_align(g, &union_type->data.unionation.decls_scope->base, align_expr,
1946 &field->align))
1947 {
1948 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
1949 return err;
1950 }
1951 } else if (packed) {
1952 field->align = 1;
19471953 } else {
1948 if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) {
1954 if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
19491955 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
1950 return ErrorSemanticAnalyzeFail;
1956 return err;
19511957 }
1952
19531958 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid)
19541959 return ErrorSemanticAnalyzeFail;
1955
1956 this_field_align = field->type_entry->abi_align;
19571960 }
19581961
1959 if (most_aligned_union_member == nullptr ||
1960 this_field_align > most_aligned_union_member->abi_align)
1961 {
1962 most_aligned_union_member = field->type_entry;
1962 if (most_aligned_union_member == nullptr || field->align > most_aligned_union_member->align) {
1963 most_aligned_union_member = field;
19631964 }
19641965 }
19651966
19661967 // unset temporary flag
1967 union_type->data.unionation.resolve_loop_flag = false;
1968 union_type->data.unionation.resolve_loop_flag_other = false;
19681969 union_type->data.unionation.resolve_status = ResolveStatusAlignmentKnown;
19691970 union_type->data.unionation.most_aligned_union_member = most_aligned_union_member;
19701971
......@@ -1978,18 +1979,18 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
19781979 union_type->abi_align = tag_type->abi_align;
19791980 union_type->data.unionation.gen_tag_index = SIZE_MAX;
19801981 union_type->data.unionation.gen_union_index = SIZE_MAX;
1981 } else if (tag_type->abi_align > most_aligned_union_member->abi_align) {
1982 } else if (tag_type->abi_align > most_aligned_union_member->align) {
19821983 union_type->abi_align = tag_type->abi_align;
19831984 union_type->data.unionation.gen_tag_index = 0;
19841985 union_type->data.unionation.gen_union_index = 1;
19851986 } else {
1986 union_type->abi_align = most_aligned_union_member->abi_align;
1987 union_type->abi_align = most_aligned_union_member->align;
19871988 union_type->data.unionation.gen_union_index = 0;
19881989 union_type->data.unionation.gen_tag_index = 1;
19891990 }
19901991 } else {
19911992 assert(most_aligned_union_member != nullptr);
1992 union_type->abi_align = most_aligned_union_member->abi_align;
1993 union_type->abi_align = most_aligned_union_member->align;
19931994 union_type->data.unionation.gen_union_index = SIZE_MAX;
19941995 union_type->data.unionation.gen_tag_index = SIZE_MAX;
19951996 }
......@@ -2016,14 +2017,14 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
20162017 assert(decl_node->type == NodeTypeContainerDecl);
20172018
20182019 uint32_t field_count = union_type->data.unionation.src_field_count;
2019 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
2020 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
20202021
20212022 assert(union_type->data.unionation.fields);
20222023
20232024 size_t union_abi_size = 0;
20242025 size_t union_size_in_bits = 0;
20252026
2026 if (union_type->data.unionation.resolve_loop_flag) {
2027 if (union_type->data.unionation.resolve_loop_flag_other) {
20272028 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
20282029 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
20292030 g->trace_err = add_node_error(g, decl_node,
......@@ -2033,11 +2034,18 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
20332034 }
20342035
20352036 // set temporary flag
2036 union_type->data.unionation.resolve_loop_flag = true;
2037 union_type->data.unionation.resolve_loop_flag_other = true;
20372038
20382039 for (uint32_t i = 0; i < field_count; i += 1) {
2040 AstNode *field_source_node = decl_node->data.container_decl.fields.at(i);
20392041 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
2040 ZigType *field_type = union_field->type_entry;
2042
2043 if ((err = ir_resolve_lazy(g, field_source_node, union_field->type_val))) {
2044 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2045 return err;
2046 }
2047 ZigType *field_type = union_field->type_val->data.x_type;
2048 union_field->type_entry = field_type;
20412049
20422050 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
20432051 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
......@@ -2057,11 +2065,11 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
20572065 // The union itself for now has to be treated as being independently aligned.
20582066 // See https://github.com/ziglang/zig/issues/2166.
20592067 if (most_aligned_union_member != nullptr) {
2060 union_abi_size = align_forward(union_abi_size, most_aligned_union_member->abi_align);
2068 union_abi_size = align_forward(union_abi_size, most_aligned_union_member->align);
20612069 }
20622070
20632071 // unset temporary flag
2064 union_type->data.unionation.resolve_loop_flag = false;
2072 union_type->data.unionation.resolve_loop_flag_other = false;
20652073 union_type->data.unionation.resolve_status = ResolveStatusSizeKnown;
20662074 union_type->data.unionation.union_abi_size = union_abi_size;
20672075
......@@ -2080,7 +2088,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
20802088 field_sizes[union_type->data.unionation.gen_tag_index] = tag_type->abi_size;
20812089 field_aligns[union_type->data.unionation.gen_tag_index] = tag_type->abi_align;
20822090 field_sizes[union_type->data.unionation.gen_union_index] = union_abi_size;
2083 field_aligns[union_type->data.unionation.gen_union_index] = most_aligned_union_member->abi_align;
2091 field_aligns[union_type->data.unionation.gen_union_index] = most_aligned_union_member->align;
20842092 size_t field2_offset = next_field_offset(0, union_type->abi_align, field_sizes[0], field_aligns[1]);
20852093 union_type->abi_size = next_field_offset(field2_offset, union_type->abi_align, field_sizes[1], union_type->abi_align);
20862094 union_type->size_in_bits = union_type->abi_size * 8;
......@@ -2449,12 +2457,12 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
24492457 } else if (packed) {
24502458 field->align = 1;
24512459 } else {
2452 size_t result_abi_align;
2453 if ((err = type_val_resolve_abi_align(g, field->type_val, &result_abi_align))) {
2460 if ((err = type_val_resolve_abi_align(g, field->type_val, &field->align))) {
24542461 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
24552462 return err;
24562463 }
2457 field->align = result_abi_align;
2464 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid)
2465 return ErrorSemanticAnalyzeFail;
24582466 }
24592467
24602468 if (field->align > struct_type->abi_align) {
......@@ -2486,7 +2494,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
24862494 AstNode *decl_node = union_type->data.unionation.decl_node;
24872495 assert(decl_node->type == NodeTypeContainerDecl);
24882496
2489 if (union_type->data.unionation.resolve_loop_flag) {
2497 if (union_type->data.unionation.resolve_loop_flag_zero_bits) {
24902498 if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) {
24912499 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
24922500 g->trace_err = add_node_error(g, decl_node,
......@@ -2496,7 +2504,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
24962504 return ErrorSemanticAnalyzeFail;
24972505 }
24982506
2499 union_type->data.unionation.resolve_loop_flag = true;
2507 union_type->data.unionation.resolve_loop_flag_zero_bits = true;
25002508
25012509 assert(union_type->data.unionation.fields == nullptr);
25022510 uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length;
......@@ -2605,49 +2613,68 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
26052613 return ErrorSemanticAnalyzeFail;
26062614 }
26072615
2608 ZigType *field_type;
2616 bool field_is_zero_bits;
26092617 if (field_node->data.struct_field.type == nullptr) {
2610 if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) {
2611 field_type = g->builtin_types.entry_void;
2618 if (decl_node->data.container_decl.auto_enum ||
2619 decl_node->data.container_decl.init_arg_expr != nullptr)
2620 {
2621 union_field->type_entry = g->builtin_types.entry_void;
2622 field_is_zero_bits = false;
26122623 } else {
26132624 add_node_error(g, field_node, buf_sprintf("union field missing type"));
26142625 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
26152626 return ErrorSemanticAnalyzeFail;
26162627 }
26172628 } else {
2618 field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
2619 if ((err = type_resolve(g, field_type, ResolveStatusAlignmentKnown))) {
2629 ConstExprValue *field_type_val = analyze_const_value_allow_lazy(g, scope,
2630 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, true);
2631 if (type_is_invalid(field_type_val->type)) {
26202632 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
26212633 return ErrorSemanticAnalyzeFail;
26222634 }
2635 assert(field_type_val->special != ConstValSpecialRuntime);
2636 union_field->type_val = field_type_val;
26232637 if (union_type->data.unionation.resolve_status == ResolveStatusInvalid)
26242638 return ErrorSemanticAnalyzeFail;
2625 }
2626 union_field->type_entry = field_type;
26272639
2628 if (field_type->id == ZigTypeIdOpaque) {
2629 add_node_error(g, field_node->data.struct_field.type,
2630 buf_sprintf("opaque types have unknown size and therefore cannot be directly embedded in unions"));
2631 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2632 return ErrorSemanticAnalyzeFail;
2633 }
2640 bool field_is_opaque_type;
2641 if ((err = type_val_resolve_is_opaque_type(g, field_type_val, &field_is_opaque_type))) {
2642 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2643 return ErrorSemanticAnalyzeFail;
2644 }
2645 if (field_is_opaque_type) {
2646 add_node_error(g, field_node->data.struct_field.type,
2647 buf_create_from_str(
2648 "opaque types have unknown size and therefore cannot be directly embedded in unions"));
2649 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2650 return ErrorSemanticAnalyzeFail;
2651 }
26342652
2635 switch (type_requires_comptime(g, field_type)) {
2636 case ReqCompTimeInvalid:
2653 switch (type_val_resolve_requires_comptime(g, field_type_val)) {
2654 case ReqCompTimeInvalid:
2655 if (g->trace_err != nullptr) {
2656 g->trace_err = add_error_note(g, g->trace_err, field_node,
2657 buf_create_from_str("while checking this field"));
2658 }
2659 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2660 return ErrorSemanticAnalyzeFail;
2661 case ReqCompTimeYes:
2662 union_type->data.unionation.requires_comptime = true;
2663 break;
2664 case ReqCompTimeNo:
2665 break;
2666 }
2667
2668 if ((err = type_val_resolve_zero_bits(g, field_type_val, union_type, nullptr, &field_is_zero_bits))) {
26372669 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
26382670 return ErrorSemanticAnalyzeFail;
2639 case ReqCompTimeYes:
2640 union_type->data.unionation.requires_comptime = true;
2641 break;
2642 case ReqCompTimeNo:
2643 break;
2671 }
26442672 }
26452673
26462674 if (field_node->data.struct_field.value != nullptr && !decl_node->data.container_decl.auto_enum) {
26472675 ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.value,
2648 buf_sprintf("non-enum union field assignment"));
2649 add_error_note(g, msg, decl_node,
2650 buf_sprintf("consider 'union(enum)' here"));
2676 buf_create_from_str("untagged union field assignment"));
2677 add_error_note(g, msg, decl_node, buf_create_from_str("consider 'union(enum)' here"));
26512678 }
26522679
26532680 if (create_enum_type) {
......@@ -2706,7 +2733,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
27062733 }
27072734 assert(union_field->enum_field != nullptr);
27082735
2709 if (!type_has_bits(field_type))
2736 if (field_is_zero_bits)
27102737 continue;
27112738
27122739 union_field->gen_index = gen_field_index;
......@@ -2783,7 +2810,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
27832810 return ErrorSemanticAnalyzeFail;
27842811 }
27852812
2786 union_type->data.unionation.resolve_loop_flag = false;
2813 union_type->data.unionation.resolve_loop_flag_zero_bits = false;
27872814
27882815 union_type->data.unionation.gen_field_count = gen_field_index;
27892816 bool zero_bits = gen_field_index == 0 && (field_count < 2 || !src_have_tag);
......@@ -5002,6 +5029,10 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
50025029 return ReqCompTimeInvalid;
50035030 return ty->data.structure.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
50045031 case ZigTypeIdUnion:
5032 if (ty->data.unionation.resolve_loop_flag_zero_bits) {
5033 // Does a union which contains a pointer field to itself require comptime? No.
5034 return ReqCompTimeNo;
5035 }
50055036 if ((err = type_resolve(g, ty, ResolveStatusZeroBitsKnown)))
50065037 return ReqCompTimeInvalid;
50075038 return ty->data.unionation.requires_comptime ? ReqCompTimeYes : ReqCompTimeNo;
......@@ -7308,7 +7339,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
73087339static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) {
73097340 if (union_type->data.unionation.resolve_status >= wanted_resolve_status) return;
73107341
7311 ZigType *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
7342 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
73127343 ZigType *tag_type = union_type->data.unionation.tag_type;
73137344 if (most_aligned_union_member == nullptr) {
73147345 union_type->llvm_type = get_llvm_type(g, tag_type);
......@@ -7361,17 +7392,17 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
73617392 if (tag_type == nullptr || !type_has_bits(tag_type)) {
73627393 assert(most_aligned_union_member != nullptr);
73637394
7364 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->abi_size;
7395 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->type_entry->abi_size;
73657396 if (padding_bytes > 0) {
73667397 ZigType *u8_type = get_int_type(g, false, 8);
73677398 ZigType *padding_array = get_array_type(g, u8_type, padding_bytes);
73687399 LLVMTypeRef union_element_types[] = {
7369 most_aligned_union_member->llvm_type,
7400 most_aligned_union_member->type_entry->llvm_type,
73707401 get_llvm_type(g, padding_array),
73717402 };
73727403 LLVMStructSetBody(union_type->llvm_type, union_element_types, 2, false);
73737404 } else {
7374 LLVMStructSetBody(union_type->llvm_type, &most_aligned_union_member->llvm_type, 1, false);
7405 LLVMStructSetBody(union_type->llvm_type, &most_aligned_union_member->type_entry->llvm_type, 1, false);
73757406 }
73767407 union_type->data.unionation.union_llvm_type = union_type->llvm_type;
73777408 union_type->data.unionation.gen_tag_index = SIZE_MAX;
......@@ -7382,7 +7413,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
73827413 ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&union_type->name),
73837414 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
73847415 union_type->data.unionation.union_abi_size * 8,
7385 most_aligned_union_member->abi_align * 8,
7416 most_aligned_union_member->align * 8,
73867417 ZigLLVM_DIFlags_Zero, union_inner_di_types,
73877418 gen_field_count, 0, "");
73887419
......@@ -7393,14 +7424,14 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
73937424 }
73947425
73957426 LLVMTypeRef union_type_ref;
7396 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->abi_size;
7427 size_t padding_bytes = union_type->data.unionation.union_abi_size - most_aligned_union_member->type_entry->abi_size;
73977428 if (padding_bytes == 0) {
7398 union_type_ref = get_llvm_type(g, most_aligned_union_member);
7429 union_type_ref = get_llvm_type(g, most_aligned_union_member->type_entry);
73997430 } else {
74007431 ZigType *u8_type = get_int_type(g, false, 8);
74017432 ZigType *padding_array = get_array_type(g, u8_type, padding_bytes);
74027433 LLVMTypeRef union_element_types[] = {
7403 get_llvm_type(g, most_aligned_union_member),
7434 get_llvm_type(g, most_aligned_union_member->type_entry),
74047435 get_llvm_type(g, padding_array),
74057436 };
74067437 union_type_ref = LLVMStructType(union_element_types, 2, false);
......@@ -7416,7 +7447,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
74167447 ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
74177448 ZigLLVMTypeToScope(union_type->llvm_di_type), "AnonUnion",
74187449 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
7419 most_aligned_union_member->size_in_bits, 8*most_aligned_union_member->abi_align,
7450 most_aligned_union_member->type_entry->size_in_bits, 8*most_aligned_union_member->align,
74207451 ZigLLVM_DIFlags_Zero, union_inner_di_types, gen_field_count, 0, "");
74217452
74227453 uint64_t union_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, union_type->llvm_type,
......@@ -7427,8 +7458,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
74277458 ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
74287459 ZigLLVMTypeToScope(union_type->llvm_di_type), "payload",
74297460 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
7430 most_aligned_union_member->size_in_bits,
7431 8*most_aligned_union_member->abi_align,
7461 most_aligned_union_member->type_entry->size_in_bits,
7462 8*most_aligned_union_member->align,
74327463 union_offset_in_bits,
74337464 ZigLLVM_DIFlags_Zero, union_di_type);
74347465
src/codegen.cpp+1-1
......@@ -6568,7 +6568,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
65686568 uint64_t pad_bytes = type_entry->data.unionation.union_abi_size - field_type_bytes;
65696569 LLVMValueRef correctly_typed_value = gen_const_val(g, payload_value, "");
65706570 make_unnamed_struct = is_llvm_value_unnamed_type(g, payload_value->type, correctly_typed_value) ||
6571 payload_value->type != type_entry->data.unionation.most_aligned_union_member;
6571 payload_value->type != type_entry->data.unionation.most_aligned_union_member->type_entry;
65726572
65736573 {
65746574 if (pad_bytes == 0) {