| ... | ... | @@ -1872,8 +1872,6 @@ static void resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { |
| 1872 | 1872 | |
| 1873 | 1873 | bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto); |
| 1874 | 1874 | ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count); |
| 1875 | | auto distinct_types = &union_type->data.unionation.distinct_types; |
| 1876 | | distinct_types->init(4); |
| 1877 | 1875 | |
| 1878 | 1876 | Scope *scope = &union_type->data.unionation.decls_scope->base; |
| 1879 | 1877 | ImportTableEntry *import = get_scope_import(scope); |
| ... | ... | @@ -1895,10 +1893,7 @@ static void resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { |
| 1895 | 1893 | if (!type_has_bits(field_type)) |
| 1896 | 1894 | continue; |
| 1897 | 1895 | |
| 1898 | | size_t distinct_type_index = distinct_types->size(); |
| 1899 | | if (distinct_types->put_unique(field_type, distinct_type_index) == nullptr) { |
| 1900 | | di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(&field_type->name), distinct_type_index); |
| 1901 | | } |
| 1896 | di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(type_union_field->name), i); |
| 1902 | 1897 | |
| 1903 | 1898 | uint64_t store_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref); |
| 1904 | 1899 | uint64_t abi_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref); |
| ... | ... | @@ -1954,7 +1949,7 @@ static void resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { |
| 1954 | 1949 | |
| 1955 | 1950 | assert(most_aligned_union_member != nullptr); |
| 1956 | 1951 | |
| 1957 | | bool want_safety = (distinct_types->size() > 1) && auto_layout; |
| 1952 | bool want_safety = auto_layout && (field_count >= 2); |
| 1958 | 1953 | uint64_t padding_in_bits = biggest_size_in_bits - size_of_most_aligned_member_in_bits; |
| 1959 | 1954 | |
| 1960 | 1955 | |
| ... | ... | @@ -2007,7 +2002,7 @@ static void resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { |
| 2007 | 2002 | assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits); |
| 2008 | 2003 | |
| 2009 | 2004 | // create llvm type for root struct |
| 2010 | | TypeTableEntry *tag_int_type = get_smallest_unsigned_int_type(g, distinct_types->size() - 1); |
| 2005 | TypeTableEntry *tag_int_type = get_smallest_unsigned_int_type(g, field_count - 1); |
| 2011 | 2006 | TypeTableEntry *tag_type_entry = tag_int_type; |
| 2012 | 2007 | union_type->data.unionation.tag_type = tag_type_entry; |
| 2013 | 2008 | uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref); |
| ... | ... | @@ -2034,7 +2029,7 @@ static void resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { |
| 2034 | 2029 | ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder, |
| 2035 | 2030 | ZigLLVMTypeToScope(union_type->di_type), "AnonEnum", |
| 2036 | 2031 | import->di_file, (unsigned)(decl_node->line + 1), |
| 2037 | | tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, distinct_types->size(), |
| 2032 | tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count, |
| 2038 | 2033 | tag_type_entry->di_type, ""); |
| 2039 | 2034 | |
| 2040 | 2035 | // create debug type for union |
| ... | ... | @@ -2257,6 +2252,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { |
| 2257 | 2252 | type_union_field->name = field_node->data.struct_field.name; |
| 2258 | 2253 | TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type); |
| 2259 | 2254 | type_union_field->type_entry = field_type; |
| 2255 | type_union_field->value = i; |
| 2260 | 2256 | |
| 2261 | 2257 | type_ensure_zero_bits_known(g, field_type); |
| 2262 | 2258 | if (type_is_invalid(field_type)) { |
| ... | ... | @@ -2276,9 +2272,11 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { |
| 2276 | 2272 | } |
| 2277 | 2273 | } |
| 2278 | 2274 | |
| 2275 | bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto); |
| 2276 | |
| 2279 | 2277 | union_type->data.unionation.zero_bits_loop_flag = false; |
| 2280 | 2278 | union_type->data.unionation.gen_field_count = gen_field_index; |
| 2281 | | union_type->zero_bits = (gen_field_index == 0); |
| 2279 | union_type->zero_bits = (gen_field_index == 0 && (field_count < 2 || !auto_layout)); |
| 2282 | 2280 | union_type->data.unionation.zero_bits_known = true; |
| 2283 | 2281 | |
| 2284 | 2282 | // also compute abi_alignment |