| author | |
| committer | |
| log | d89f39d71949c85b26f2ccd4071c9445aa8b6d7c |
| tree | b770509b52976a23e483eb58f6edadc70da1ca95 |
| parent | f2f698a888afdc8709142912f8394376d28e16ea |
| signature |
This removes the remaining hack in the implementation of anonymous
struct literals, and they can now therefore now have greater than 16
fields/elements.6 files changed, 144 insertions(+), 134 deletions(-)
src/all_types.hpp+1-1| ... | @@ -1279,7 +1279,7 @@ struct RootStruct { | ... | @@ -1279,7 +1279,7 @@ struct RootStruct { |
| 1279 | 1279 | ||
| 1280 | struct ZigTypeStruct { | 1280 | struct ZigTypeStruct { |
| 1281 | AstNode *decl_node; | 1281 | AstNode *decl_node; |
| 1282 | TypeStructField *fields; | 1282 | TypeStructField **fields; |
| 1283 | ScopeDecls *decls_scope; | 1283 | ScopeDecls *decls_scope; |
| 1284 | HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name; | 1284 | HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name; |
| 1285 | RootStruct *root_struct; | 1285 | RootStruct *root_struct; |
src/analyze.cpp+55-40| ... | @@ -803,19 +803,19 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { | ... | @@ -803,19 +803,19 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { |
| 803 | entry->data.structure.is_slice = true; | 803 | entry->data.structure.is_slice = true; |
| 804 | entry->data.structure.src_field_count = element_count; | 804 | entry->data.structure.src_field_count = element_count; |
| 805 | entry->data.structure.gen_field_count = element_count; | 805 | entry->data.structure.gen_field_count = element_count; |
| 806 | entry->data.structure.fields = allocate<TypeStructField>(element_count); | 806 | entry->data.structure.fields = alloc_type_struct_fields(element_count); |
| 807 | entry->data.structure.fields_by_name.init(element_count); | 807 | entry->data.structure.fields_by_name.init(element_count); |
| 808 | entry->data.structure.fields[slice_ptr_index].name = ptr_field_name; | 808 | entry->data.structure.fields[slice_ptr_index]->name = ptr_field_name; |
| 809 | entry->data.structure.fields[slice_ptr_index].type_entry = ptr_type; | 809 | entry->data.structure.fields[slice_ptr_index]->type_entry = ptr_type; |
| 810 | entry->data.structure.fields[slice_ptr_index].src_index = slice_ptr_index; | 810 | entry->data.structure.fields[slice_ptr_index]->src_index = slice_ptr_index; |
| 811 | entry->data.structure.fields[slice_ptr_index].gen_index = 0; | 811 | entry->data.structure.fields[slice_ptr_index]->gen_index = 0; |
| 812 | entry->data.structure.fields[slice_len_index].name = len_field_name; | 812 | entry->data.structure.fields[slice_len_index]->name = len_field_name; |
| 813 | entry->data.structure.fields[slice_len_index].type_entry = g->builtin_types.entry_usize; | 813 | entry->data.structure.fields[slice_len_index]->type_entry = g->builtin_types.entry_usize; |
| 814 | entry->data.structure.fields[slice_len_index].src_index = slice_len_index; | 814 | entry->data.structure.fields[slice_len_index]->src_index = slice_len_index; |
| 815 | entry->data.structure.fields[slice_len_index].gen_index = 1; | 815 | entry->data.structure.fields[slice_len_index]->gen_index = 1; |
| 816 | 816 | ||
| 817 | entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]); | 817 | entry->data.structure.fields_by_name.put(ptr_field_name, entry->data.structure.fields[slice_ptr_index]); |
| 818 | entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]); | 818 | entry->data.structure.fields_by_name.put(len_field_name, entry->data.structure.fields[slice_len_index]); |
| 819 | 819 | ||
| 820 | switch (type_requires_comptime(g, ptr_type)) { | 820 | switch (type_requires_comptime(g, ptr_type)) { |
| 821 | case ReqCompTimeInvalid: | 821 | case ReqCompTimeInvalid: |
| ... | @@ -828,8 +828,8 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { | ... | @@ -828,8 +828,8 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { |
| 828 | 828 | ||
| 829 | if (!type_has_bits(ptr_type)) { | 829 | if (!type_has_bits(ptr_type)) { |
| 830 | entry->data.structure.gen_field_count = 1; | 830 | entry->data.structure.gen_field_count = 1; |
| 831 | entry->data.structure.fields[slice_ptr_index].gen_index = SIZE_MAX; | 831 | entry->data.structure.fields[slice_ptr_index]->gen_index = SIZE_MAX; |
| 832 | entry->data.structure.fields[slice_len_index].gen_index = 0; | 832 | entry->data.structure.fields[slice_len_index]->gen_index = 0; |
| 833 | } | 833 | } |
| 834 | 834 | ||
| 835 | ZigType *child_type = ptr_type->data.pointer.child_type; | 835 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| ... | @@ -1984,12 +1984,12 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel | ... | @@ -1984,12 +1984,12 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel |
| 1984 | struct_type->data.structure.src_field_count = field_count; | 1984 | struct_type->data.structure.src_field_count = field_count; |
| 1985 | struct_type->data.structure.gen_field_count = 0; | 1985 | struct_type->data.structure.gen_field_count = 0; |
| 1986 | struct_type->data.structure.resolve_status = ResolveStatusSizeKnown; | 1986 | struct_type->data.structure.resolve_status = ResolveStatusSizeKnown; |
| 1987 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); | 1987 | struct_type->data.structure.fields = alloc_type_struct_fields(field_count); |
| 1988 | struct_type->data.structure.fields_by_name.init(field_count); | 1988 | struct_type->data.structure.fields_by_name.init(field_count); |
| 1989 | 1989 | ||
| 1990 | size_t abi_align = min_abi_align; | 1990 | size_t abi_align = min_abi_align; |
| 1991 | for (size_t i = 0; i < field_count; i += 1) { | 1991 | for (size_t i = 0; i < field_count; i += 1) { |
| 1992 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 1992 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 1993 | field->name = buf_create_from_str(fields[i].name); | 1993 | field->name = buf_create_from_str(fields[i].name); |
| 1994 | field->type_entry = fields[i].ty; | 1994 | field->type_entry = fields[i].ty; |
| 1995 | field->src_index = i; | 1995 | field->src_index = i; |
| ... | @@ -2009,7 +2009,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel | ... | @@ -2009,7 +2009,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel |
| 2009 | 2009 | ||
| 2010 | size_t next_offset = 0; | 2010 | size_t next_offset = 0; |
| 2011 | for (size_t i = 0; i < field_count; i += 1) { | 2011 | for (size_t i = 0; i < field_count; i += 1) { |
| 2012 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 2012 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 2013 | if (!type_has_bits(field->type_entry)) | 2013 | if (!type_has_bits(field->type_entry)) |
| 2014 | continue; | 2014 | continue; |
| 2015 | 2015 | ||
| ... | @@ -2018,7 +2018,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel | ... | @@ -2018,7 +2018,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel |
| 2018 | // find the next non-zero-byte field for offset calculations | 2018 | // find the next non-zero-byte field for offset calculations |
| 2019 | size_t next_src_field_index = i + 1; | 2019 | size_t next_src_field_index = i + 1; |
| 2020 | for (; next_src_field_index < field_count; next_src_field_index += 1) { | 2020 | for (; next_src_field_index < field_count; next_src_field_index += 1) { |
| 2021 | if (type_has_bits(struct_type->data.structure.fields[next_src_field_index].type_entry)) | 2021 | if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry)) |
| 2022 | break; | 2022 | break; |
| 2023 | } | 2023 | } |
| 2024 | size_t next_abi_align; | 2024 | size_t next_abi_align; |
| ... | @@ -2026,7 +2026,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel | ... | @@ -2026,7 +2026,7 @@ static ZigType *get_struct_type(CodeGen *g, const char *type_name, SrcField fiel |
| 2026 | next_abi_align = abi_align; | 2026 | next_abi_align = abi_align; |
| 2027 | } else { | 2027 | } else { |
| 2028 | next_abi_align = max(fields[next_src_field_index].align, | 2028 | next_abi_align = max(fields[next_src_field_index].align, |
| 2029 | struct_type->data.structure.fields[next_src_field_index].type_entry->abi_align); | 2029 | struct_type->data.structure.fields[next_src_field_index]->type_entry->abi_align); |
| 2030 | } | 2030 | } |
| 2031 | next_offset = next_field_offset(next_offset, abi_align, field->type_entry->abi_size, next_abi_align); | 2031 | next_offset = next_field_offset(next_offset, abi_align, field->type_entry->abi_size, next_abi_align); |
| 2032 | } | 2032 | } |
| ... | @@ -2109,7 +2109,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -2109,7 +2109,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2109 | 2109 | ||
| 2110 | // Calculate offsets | 2110 | // Calculate offsets |
| 2111 | for (size_t i = 0; i < field_count; i += 1) { | 2111 | for (size_t i = 0; i < field_count; i += 1) { |
| 2112 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 2112 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 2113 | if (field->gen_index == SIZE_MAX) | 2113 | if (field->gen_index == SIZE_MAX) |
| 2114 | continue; | 2114 | continue; |
| 2115 | 2115 | ||
| ... | @@ -2178,12 +2178,12 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -2178,12 +2178,12 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2178 | gen_field_index += 1; | 2178 | gen_field_index += 1; |
| 2179 | size_t next_src_field_index = i + 1; | 2179 | size_t next_src_field_index = i + 1; |
| 2180 | for (; next_src_field_index < field_count; next_src_field_index += 1) { | 2180 | for (; next_src_field_index < field_count; next_src_field_index += 1) { |
| 2181 | if (struct_type->data.structure.fields[next_src_field_index].gen_index != SIZE_MAX) { | 2181 | if (struct_type->data.structure.fields[next_src_field_index]->gen_index != SIZE_MAX) { |
| 2182 | break; | 2182 | break; |
| 2183 | } | 2183 | } |
| 2184 | } | 2184 | } |
| 2185 | size_t next_align = (next_src_field_index == field_count) ? | 2185 | size_t next_align = (next_src_field_index == field_count) ? |
| 2186 | abi_align : struct_type->data.structure.fields[next_src_field_index].align; | 2186 | abi_align : struct_type->data.structure.fields[next_src_field_index]->align; |
| 2187 | next_offset = next_field_offset(next_offset, abi_align, field_abi_size, next_align); | 2187 | next_offset = next_field_offset(next_offset, abi_align, field_abi_size, next_align); |
| 2188 | size_in_bits = next_offset * 8; | 2188 | size_in_bits = next_offset * 8; |
| 2189 | } | 2189 | } |
| ... | @@ -2206,7 +2206,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -2206,7 +2206,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2206 | 2206 | ||
| 2207 | // Resolve types for fields | 2207 | // Resolve types for fields |
| 2208 | for (size_t i = 0; i < field_count; i += 1) { | 2208 | for (size_t i = 0; i < field_count; i += 1) { |
| 2209 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 2209 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 2210 | ZigType *field_type = resolve_struct_field_type(g, field); | 2210 | ZigType *field_type = resolve_struct_field_type(g, field); |
| 2211 | if (field_type == nullptr) { | 2211 | if (field_type == nullptr) { |
| 2212 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; | 2212 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| ... | @@ -2697,7 +2697,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { | ... | @@ -2697,7 +2697,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2697 | struct_type->data.structure.src_field_count = (uint32_t)field_count; | 2697 | struct_type->data.structure.src_field_count = (uint32_t)field_count; |
| 2698 | 2698 | ||
| 2699 | src_assert(struct_type->data.structure.fields == nullptr, decl_node); | 2699 | src_assert(struct_type->data.structure.fields == nullptr, decl_node); |
| 2700 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); | 2700 | struct_type->data.structure.fields = alloc_type_struct_fields(field_count); |
| 2701 | } else if (decl_node->type == NodeTypeContainerInitExpr) { | 2701 | } else if (decl_node->type == NodeTypeContainerInitExpr) { |
| 2702 | src_assert(struct_type->data.structure.is_inferred, decl_node); | 2702 | src_assert(struct_type->data.structure.is_inferred, decl_node); |
| 2703 | src_assert(struct_type->data.structure.fields != nullptr, decl_node); | 2703 | src_assert(struct_type->data.structure.fields != nullptr, decl_node); |
| ... | @@ -2711,7 +2711,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { | ... | @@ -2711,7 +2711,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2711 | 2711 | ||
| 2712 | size_t gen_field_index = 0; | 2712 | size_t gen_field_index = 0; |
| 2713 | for (size_t i = 0; i < field_count; i += 1) { | 2713 | for (size_t i = 0; i < field_count; i += 1) { |
| 2714 | TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; | 2714 | TypeStructField *type_struct_field = struct_type->data.structure.fields[i]; |
| 2715 | 2715 | ||
| 2716 | AstNode *field_node; | 2716 | AstNode *field_node; |
| 2717 | if (decl_node->type == NodeTypeContainerDecl) { | 2717 | if (decl_node->type == NodeTypeContainerDecl) { |
| ... | @@ -2843,7 +2843,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { | ... | @@ -2843,7 +2843,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2843 | bool packed = struct_type->data.structure.layout == ContainerLayoutPacked; | 2843 | bool packed = struct_type->data.structure.layout == ContainerLayoutPacked; |
| 2844 | 2844 | ||
| 2845 | for (size_t i = 0; i < field_count; i += 1) { | 2845 | for (size_t i = 0; i < field_count; i += 1) { |
| 2846 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 2846 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 2847 | if (field->gen_index == SIZE_MAX) | 2847 | if (field->gen_index == SIZE_MAX) |
| 2848 | continue; | 2848 | continue; |
| 2849 | 2849 | ||
| ... | @@ -5506,7 +5506,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { | ... | @@ -5506,7 +5506,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 5506 | return type_has_one_possible_value(g, type_entry->data.array.child_type); | 5506 | return type_has_one_possible_value(g, type_entry->data.array.child_type); |
| 5507 | case ZigTypeIdStruct: | 5507 | case ZigTypeIdStruct: |
| 5508 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { | 5508 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { |
| 5509 | TypeStructField *field = &type_entry->data.structure.fields[i]; | 5509 | TypeStructField *field = type_entry->data.structure.fields[i]; |
| 5510 | OnePossibleValue opv = (field->type_entry != nullptr) ? | 5510 | OnePossibleValue opv = (field->type_entry != nullptr) ? |
| 5511 | type_has_one_possible_value(g, field->type_entry) : | 5511 | type_has_one_possible_value(g, field->type_entry) : |
| 5512 | type_val_resolve_has_one_possible_value(g, field->type_val); | 5512 | type_val_resolve_has_one_possible_value(g, field->type_val); |
| ... | @@ -5902,6 +5902,21 @@ ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, | ... | @@ -5902,6 +5902,21 @@ ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, |
| 5902 | return result; | 5902 | return result; |
| 5903 | } | 5903 | } |
| 5904 | 5904 | ||
| 5905 | TypeStructField **alloc_type_struct_fields(size_t count) { | ||
| 5906 | return realloc_type_struct_fields(nullptr, 0, count); | ||
| 5907 | } | ||
| 5908 | |||
| 5909 | TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count) { | ||
| 5910 | assert(new_count >= old_count); | ||
| 5911 | |||
| 5912 | size_t new_item_count = new_count - old_count; | ||
| 5913 | TypeStructField **result = reallocate(ptr, old_count, new_count, "TypeStructField*"); | ||
| 5914 | TypeStructField *vals = allocate<TypeStructField>(new_item_count, "TypeStructField"); | ||
| 5915 | for (size_t i = old_count; i < new_count; i += 1) { | ||
| 5916 | result[i] = &vals[i - old_count]; | ||
| 5917 | } | ||
| 5918 | return result; | ||
| 5919 | } | ||
| 5905 | 5920 | ||
| 5906 | static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { | 5921 | static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { |
| 5907 | if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) | 5922 | if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) |
| ... | @@ -7176,7 +7191,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { | ... | @@ -7176,7 +7191,7 @@ static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 7176 | const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count); | 7191 | const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count); |
| 7177 | for (size_t i = 0; i < field_count; i += 1) { | 7192 | for (size_t i = 0; i < field_count; i += 1) { |
| 7178 | ConstExprValue *field_val = const_val->data.x_struct.fields[i]; | 7193 | ConstExprValue *field_val = const_val->data.x_struct.fields[i]; |
| 7179 | field_val->type = resolve_struct_field_type(g, &wanted_type->data.structure.fields[i]); | 7194 | field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]); |
| 7180 | assert(field_val->type); | 7195 | assert(field_val->type); |
| 7181 | init_const_undefined(g, field_val); | 7196 | init_const_undefined(g, field_val); |
| 7182 | field_val->parent.id = ConstParentIdStruct; | 7197 | field_val->parent.id = ConstParentIdStruct; |
| ... | @@ -7608,7 +7623,7 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size | ... | @@ -7608,7 +7623,7 @@ static X64CABIClass type_system_V_abi_x86_64_class(CodeGen *g, ZigType *ty, size |
| 7608 | } | 7623 | } |
| 7609 | X64CABIClass working_class = X64CABIClass_Unknown; | 7624 | X64CABIClass working_class = X64CABIClass_Unknown; |
| 7610 | for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) { | 7625 | for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) { |
| 7611 | X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry); | 7626 | X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields[0]->type_entry); |
| 7612 | if (field_class == X64CABIClass_Unknown) | 7627 | if (field_class == X64CABIClass_Unknown) |
| 7613 | return X64CABIClass_Unknown; | 7628 | return X64CABIClass_Unknown; |
| 7614 | if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { | 7629 | if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { |
| ... | @@ -7740,7 +7755,7 @@ Buf *type_h_name(ZigType *t) { | ... | @@ -7740,7 +7755,7 @@ Buf *type_h_name(ZigType *t) { |
| 7740 | static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wanted_resolve_status) { | 7755 | static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wanted_resolve_status) { |
| 7741 | if (type->data.structure.resolve_status >= wanted_resolve_status) return; | 7756 | if (type->data.structure.resolve_status >= wanted_resolve_status) return; |
| 7742 | 7757 | ||
| 7743 | ZigType *ptr_type = type->data.structure.fields[slice_ptr_index].type_entry; | 7758 | ZigType *ptr_type = type->data.structure.fields[slice_ptr_index]->type_entry; |
| 7744 | ZigType *child_type = ptr_type->data.pointer.child_type; | 7759 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 7745 | ZigType *usize_type = g->builtin_types.entry_usize; | 7760 | ZigType *usize_type = g->builtin_types.entry_usize; |
| 7746 | 7761 | ||
| ... | @@ -7762,7 +7777,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa | ... | @@ -7762,7 +7777,7 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa |
| 7762 | // If the child type is []const T then we need to make sure the type ref | 7777 | // If the child type is []const T then we need to make sure the type ref |
| 7763 | // and debug info is the same as if the child type were []T. | 7778 | // and debug info is the same as if the child type were []T. |
| 7764 | if (is_slice(child_type)) { | 7779 | if (is_slice(child_type)) { |
| 7765 | ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry; | 7780 | ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 7766 | assert(child_ptr_type->id == ZigTypeIdPointer); | 7781 | assert(child_ptr_type->id == ZigTypeIdPointer); |
| 7767 | if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile || | 7782 | if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile || |
| 7768 | child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero) | 7783 | child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero) |
| ... | @@ -7939,7 +7954,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -7939,7 +7954,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7939 | 7954 | ||
| 7940 | // trigger all the recursive get_llvm_type calls | 7955 | // trigger all the recursive get_llvm_type calls |
| 7941 | for (size_t i = 0; i < field_count; i += 1) { | 7956 | for (size_t i = 0; i < field_count; i += 1) { |
| 7942 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 7957 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 7943 | ZigType *field_type = field->type_entry; | 7958 | ZigType *field_type = field->type_entry; |
| 7944 | if (!type_has_bits(field_type)) | 7959 | if (!type_has_bits(field_type)) |
| 7945 | continue; | 7960 | continue; |
| ... | @@ -7953,7 +7968,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -7953,7 +7968,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7953 | // inserting padding bytes where LLVM would do it automatically. | 7968 | // inserting padding bytes where LLVM would do it automatically. |
| 7954 | size_t llvm_struct_abi_align = 0; | 7969 | size_t llvm_struct_abi_align = 0; |
| 7955 | for (size_t i = 0; i < field_count; i += 1) { | 7970 | for (size_t i = 0; i < field_count; i += 1) { |
| 7956 | ZigType *field_type = struct_type->data.structure.fields[i].type_entry; | 7971 | ZigType *field_type = struct_type->data.structure.fields[i]->type_entry; |
| 7957 | if (!type_has_bits(field_type)) | 7972 | if (!type_has_bits(field_type)) |
| 7958 | continue; | 7973 | continue; |
| 7959 | LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type); | 7974 | LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type); |
| ... | @@ -7962,7 +7977,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -7962,7 +7977,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7962 | } | 7977 | } |
| 7963 | 7978 | ||
| 7964 | for (size_t i = 0; i < field_count; i += 1) { | 7979 | for (size_t i = 0; i < field_count; i += 1) { |
| 7965 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 7980 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 7966 | ZigType *field_type = field->type_entry; | 7981 | ZigType *field_type = field->type_entry; |
| 7967 | 7982 | ||
| 7968 | if (!type_has_bits(field_type)) { | 7983 | if (!type_has_bits(field_type)) { |
| ... | @@ -8012,23 +8027,23 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -8012,23 +8027,23 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 8012 | // find the next non-zero-byte field for offset calculations | 8027 | // find the next non-zero-byte field for offset calculations |
| 8013 | size_t next_src_field_index = i + 1; | 8028 | size_t next_src_field_index = i + 1; |
| 8014 | for (; next_src_field_index < field_count; next_src_field_index += 1) { | 8029 | for (; next_src_field_index < field_count; next_src_field_index += 1) { |
| 8015 | if (type_has_bits(struct_type->data.structure.fields[next_src_field_index].type_entry)) | 8030 | if (type_has_bits(struct_type->data.structure.fields[next_src_field_index]->type_entry)) |
| 8016 | break; | 8031 | break; |
| 8017 | } | 8032 | } |
| 8018 | size_t next_abi_align; | 8033 | size_t next_abi_align; |
| 8019 | if (next_src_field_index == field_count) { | 8034 | if (next_src_field_index == field_count) { |
| 8020 | next_abi_align = struct_type->abi_align; | 8035 | next_abi_align = struct_type->abi_align; |
| 8021 | } else { | 8036 | } else { |
| 8022 | if (struct_type->data.structure.fields[next_src_field_index].align == 0) { | 8037 | if (struct_type->data.structure.fields[next_src_field_index]->align == 0) { |
| 8023 | next_abi_align = struct_type->data.structure.fields[next_src_field_index].type_entry->abi_align; | 8038 | next_abi_align = struct_type->data.structure.fields[next_src_field_index]->type_entry->abi_align; |
| 8024 | } else { | 8039 | } else { |
| 8025 | next_abi_align = struct_type->data.structure.fields[next_src_field_index].align; | 8040 | next_abi_align = struct_type->data.structure.fields[next_src_field_index]->align; |
| 8026 | } | 8041 | } |
| 8027 | } | 8042 | } |
| 8028 | size_t llvm_next_abi_align = (next_src_field_index == field_count) ? | 8043 | size_t llvm_next_abi_align = (next_src_field_index == field_count) ? |
| 8029 | llvm_struct_abi_align : | 8044 | llvm_struct_abi_align : |
| 8030 | LLVMABIAlignmentOfType(g->target_data_ref, | 8045 | LLVMABIAlignmentOfType(g->target_data_ref, |
| 8031 | get_llvm_type(g, struct_type->data.structure.fields[next_src_field_index].type_entry)); | 8046 | get_llvm_type(g, struct_type->data.structure.fields[next_src_field_index]->type_entry)); |
| 8032 | 8047 | ||
| 8033 | size_t next_offset = next_field_offset(field->offset, struct_type->abi_align, | 8048 | size_t next_offset = next_field_offset(field->offset, struct_type->abi_align, |
| 8034 | field_type->abi_size, next_abi_align); | 8049 | field_type->abi_size, next_abi_align); |
| ... | @@ -8067,7 +8082,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -8067,7 +8082,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 8067 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count); | 8082 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count); |
| 8068 | size_t debug_field_index = 0; | 8083 | size_t debug_field_index = 0; |
| 8069 | for (size_t i = 0; i < field_count; i += 1) { | 8084 | for (size_t i = 0; i < field_count; i += 1) { |
| 8070 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 8085 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 8071 | size_t gen_field_index = field->gen_index; | 8086 | size_t gen_field_index = field->gen_index; |
| 8072 | if (gen_field_index == SIZE_MAX) { | 8087 | if (gen_field_index == SIZE_MAX) { |
| 8073 | continue; | 8088 | continue; |
src/analyze.hpp+3| ... | @@ -180,6 +180,9 @@ ConstExprValue *create_const_vals(size_t count); | ... | @@ -180,6 +180,9 @@ ConstExprValue *create_const_vals(size_t count); |
| 180 | ConstExprValue **alloc_const_vals_ptrs(size_t count); | 180 | ConstExprValue **alloc_const_vals_ptrs(size_t count); |
| 181 | ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count); | 181 | ConstExprValue **realloc_const_vals_ptrs(ConstExprValue **ptr, size_t old_count, size_t new_count); |
| 182 | 182 | ||
| 183 | TypeStructField **alloc_type_struct_fields(size_t count); | ||
| 184 | TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count); | ||
| 185 | |||
| 183 | ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); | 186 | ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); |
| 184 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); | 187 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val); |
| 185 | void expand_undef_struct(CodeGen *g, ConstExprValue *const_val); | 188 | void expand_undef_struct(CodeGen *g, ConstExprValue *const_val); |
src/codegen.cpp+44-44| ... | @@ -1108,15 +1108,15 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) { | ... | @@ -1108,15 +1108,15 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) { |
| 1108 | LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0); | 1108 | LLVMValueRef err_ret_trace_ptr = LLVMGetParam(fn_val, 0); |
| 1109 | LLVMValueRef address_value = LLVMGetParam(fn_val, 1); | 1109 | LLVMValueRef address_value = LLVMGetParam(fn_val, 1); |
| 1110 | 1110 | ||
| 1111 | size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index; | 1111 | size_t index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index; |
| 1112 | LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)index_field_index, ""); | 1112 | LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)index_field_index, ""); |
| 1113 | size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index; | 1113 | size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index; |
| 1114 | LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, ""); | 1114 | LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, ""); |
| 1115 | 1115 | ||
| 1116 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; | 1116 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry; |
| 1117 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; | 1117 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 1118 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); | 1118 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); |
| 1119 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; | 1119 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index; |
| 1120 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, ""); | 1120 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, ""); |
| 1121 | 1121 | ||
| 1122 | LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, ""); | 1122 | LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, ""); |
| ... | @@ -2176,16 +2176,16 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { | ... | @@ -2176,16 +2176,16 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { |
| 2176 | LLVMBuildCondBr(g->builder, null_bit, return_block, non_null_block); | 2176 | LLVMBuildCondBr(g->builder, null_bit, return_block, non_null_block); |
| 2177 | 2177 | ||
| 2178 | LLVMPositionBuilderAtEnd(g->builder, non_null_block); | 2178 | LLVMPositionBuilderAtEnd(g->builder, non_null_block); |
| 2179 | size_t src_index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index; | 2179 | size_t src_index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index; |
| 2180 | size_t src_addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index; | 2180 | size_t src_addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index; |
| 2181 | LLVMValueRef src_index_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr, | 2181 | LLVMValueRef src_index_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr, |
| 2182 | (unsigned)src_index_field_index, ""); | 2182 | (unsigned)src_index_field_index, ""); |
| 2183 | LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr, | 2183 | LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr, |
| 2184 | (unsigned)src_addresses_field_index, ""); | 2184 | (unsigned)src_addresses_field_index, ""); |
| 2185 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; | 2185 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry; |
| 2186 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; | 2186 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 2187 | LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, ""); | 2187 | LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, ""); |
| 2188 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; | 2188 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index; |
| 2189 | LLVMValueRef src_len_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)len_field_index, ""); | 2189 | LLVMValueRef src_len_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)len_field_index, ""); |
| 2190 | LLVMValueRef src_index_val = LLVMBuildLoad(g->builder, src_index_field_ptr, ""); | 2190 | LLVMValueRef src_index_val = LLVMBuildLoad(g->builder, src_index_field_ptr, ""); |
| 2191 | LLVMValueRef src_ptr_val = LLVMBuildLoad(g->builder, src_ptr_field_ptr, ""); | 2191 | LLVMValueRef src_ptr_val = LLVMBuildLoad(g->builder, src_ptr_field_ptr, ""); |
| ... | @@ -3010,21 +3010,21 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable, | ... | @@ -3010,21 +3010,21 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable, |
| 3010 | assert(actual_type->id == ZigTypeIdStruct); | 3010 | assert(actual_type->id == ZigTypeIdStruct); |
| 3011 | assert(actual_type->data.structure.is_slice); | 3011 | assert(actual_type->data.structure.is_slice); |
| 3012 | 3012 | ||
| 3013 | ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry; | 3013 | ZigType *actual_pointer_type = actual_type->data.structure.fields[0]->type_entry; |
| 3014 | ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type; | 3014 | ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type; |
| 3015 | ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry; | 3015 | ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0]->type_entry; |
| 3016 | ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type; | 3016 | ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type; |
| 3017 | 3017 | ||
| 3018 | 3018 | ||
| 3019 | size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index; | 3019 | size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 3020 | size_t actual_len_index = actual_type->data.structure.fields[slice_len_index].gen_index; | 3020 | size_t actual_len_index = actual_type->data.structure.fields[slice_len_index]->gen_index; |
| 3021 | size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index].gen_index; | 3021 | size_t wanted_ptr_index = wanted_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 3022 | size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index].gen_index; | 3022 | size_t wanted_len_index = wanted_type->data.structure.fields[slice_len_index]->gen_index; |
| 3023 | 3023 | ||
| 3024 | LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_ptr_index, ""); | 3024 | LLVMValueRef src_ptr_ptr = LLVMBuildStructGEP(g->builder, expr_val, (unsigned)actual_ptr_index, ""); |
| 3025 | LLVMValueRef src_ptr = gen_load_untyped(g, src_ptr_ptr, 0, false, ""); | 3025 | LLVMValueRef src_ptr = gen_load_untyped(g, src_ptr_ptr, 0, false, ""); |
| 3026 | LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, | 3026 | LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, |
| 3027 | get_llvm_type(g, wanted_type->data.structure.fields[0].type_entry), ""); | 3027 | get_llvm_type(g, wanted_type->data.structure.fields[0]->type_entry), ""); |
| 3028 | LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, result_loc, | 3028 | LLVMValueRef dest_ptr_ptr = LLVMBuildStructGEP(g->builder, result_loc, |
| 3029 | (unsigned)wanted_ptr_index, ""); | 3029 | (unsigned)wanted_ptr_index, ""); |
| 3030 | gen_store_untyped(g, src_ptr_casted, dest_ptr_ptr, 0, false); | 3030 | gen_store_untyped(g, src_ptr_casted, dest_ptr_ptr, 0, false); |
| ... | @@ -3140,9 +3140,9 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex | ... | @@ -3140,9 +3140,9 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex |
| 3140 | { | 3140 | { |
| 3141 | ZigType *actual_type = instruction->operand->value.type; | 3141 | ZigType *actual_type = instruction->operand->value.type; |
| 3142 | ZigType *slice_type = instruction->base.value.type; | 3142 | ZigType *slice_type = instruction->base.value.type; |
| 3143 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; | 3143 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 3144 | size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; | 3144 | size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 3145 | size_t len_index = slice_type->data.structure.fields[slice_len_index].gen_index; | 3145 | size_t len_index = slice_type->data.structure.fields[slice_len_index]->gen_index; |
| 3146 | 3146 | ||
| 3147 | LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); | 3147 | LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); |
| 3148 | 3148 | ||
| ... | @@ -3766,14 +3766,14 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI | ... | @@ -3766,14 +3766,14 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 3766 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); | 3766 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 3767 | 3767 | ||
| 3768 | if (safety_check_on) { | 3768 | if (safety_check_on) { |
| 3769 | size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index; | 3769 | size_t len_index = array_type->data.structure.fields[slice_len_index]->gen_index; |
| 3770 | assert(len_index != SIZE_MAX); | 3770 | assert(len_index != SIZE_MAX); |
| 3771 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, ""); | 3771 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, ""); |
| 3772 | LLVMValueRef len = gen_load_untyped(g, len_ptr, 0, false, ""); | 3772 | LLVMValueRef len = gen_load_untyped(g, len_ptr, 0, false, ""); |
| 3773 | add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); | 3773 | add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); |
| 3774 | } | 3774 | } |
| 3775 | 3775 | ||
| 3776 | size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index; | 3776 | size_t ptr_index = array_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 3777 | assert(ptr_index != SIZE_MAX); | 3777 | assert(ptr_index != SIZE_MAX); |
| 3778 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, ""); | 3778 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, ""); |
| 3779 | LLVMValueRef ptr = gen_load_untyped(g, ptr_ptr, 0, false, ""); | 3779 | LLVMValueRef ptr = gen_load_untyped(g, ptr_ptr, 0, false, ""); |
| ... | @@ -3865,7 +3865,7 @@ static void render_async_spills(CodeGen *g) { | ... | @@ -3865,7 +3865,7 @@ static void render_async_spills(CodeGen *g) { |
| 3865 | if (instruction->field_index == SIZE_MAX) | 3865 | if (instruction->field_index == SIZE_MAX) |
| 3866 | continue; | 3866 | continue; |
| 3867 | 3867 | ||
| 3868 | size_t gen_index = frame_type->data.structure.fields[instruction->field_index].gen_index; | 3868 | size_t gen_index = frame_type->data.structure.fields[instruction->field_index]->gen_index; |
| 3869 | instruction->base.llvm_value = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, gen_index, | 3869 | instruction->base.llvm_value = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, gen_index, |
| 3870 | instruction->name_hint); | 3870 | instruction->name_hint); |
| 3871 | } | 3871 | } |
| ... | @@ -4992,10 +4992,10 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I | ... | @@ -4992,10 +4992,10 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I |
| 4992 | align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment; | 4992 | align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment; |
| 4993 | ptr_val = target_val; | 4993 | ptr_val = target_val; |
| 4994 | } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) { | 4994 | } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) { |
| 4995 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; | 4995 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 4996 | align_bytes = get_ptr_align(g, slice_ptr_type); | 4996 | align_bytes = get_ptr_align(g, slice_ptr_type); |
| 4997 | 4997 | ||
| 4998 | size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index; | 4998 | size_t ptr_index = target_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 4999 | LLVMValueRef ptr_val_ptr = LLVMBuildStructGEP(g->builder, target_val, (unsigned)ptr_index, ""); | 4999 | LLVMValueRef ptr_val_ptr = LLVMBuildStructGEP(g->builder, target_val, (unsigned)ptr_index, ""); |
| 5000 | ptr_val = gen_load_untyped(g, ptr_val_ptr, 0, false, ""); | 5000 | ptr_val = gen_load_untyped(g, ptr_val_ptr, 0, false, ""); |
| 5001 | } else { | 5001 | } else { |
| ... | @@ -5240,13 +5240,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst | ... | @@ -5240,13 +5240,13 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst |
| 5240 | } | 5240 | } |
| 5241 | 5241 | ||
| 5242 | if (type_has_bits(array_type)) { | 5242 | if (type_has_bits(array_type)) { |
| 5243 | size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index].gen_index; | 5243 | size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index]->gen_index; |
| 5244 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, ""); | 5244 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, ""); |
| 5245 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); | 5245 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); |
| 5246 | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); | 5246 | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); |
| 5247 | } | 5247 | } |
| 5248 | 5248 | ||
| 5249 | size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index].gen_index; | 5249 | size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index]->gen_index; |
| 5250 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, ""); | 5250 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, ""); |
| 5251 | LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); | 5251 | LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); |
| 5252 | gen_store_untyped(g, len_value, len_field_ptr, 0, false); | 5252 | gen_store_untyped(g, len_value, len_field_ptr, 0, false); |
| ... | @@ -5258,9 +5258,9 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst | ... | @@ -5258,9 +5258,9 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst |
| 5258 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); | 5258 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 5259 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(tmp_struct_ptr))) == LLVMStructTypeKind); | 5259 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(tmp_struct_ptr))) == LLVMStructTypeKind); |
| 5260 | 5260 | ||
| 5261 | size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index; | 5261 | size_t ptr_index = array_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 5262 | assert(ptr_index != SIZE_MAX); | 5262 | assert(ptr_index != SIZE_MAX); |
| 5263 | size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index; | 5263 | size_t len_index = array_type->data.structure.fields[slice_len_index]->gen_index; |
| 5264 | assert(len_index != SIZE_MAX); | 5264 | assert(len_index != SIZE_MAX); |
| 5265 | 5265 | ||
| 5266 | LLVMValueRef prev_end = nullptr; | 5266 | LLVMValueRef prev_end = nullptr; |
| ... | @@ -6568,7 +6568,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con | ... | @@ -6568,7 +6568,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 6568 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); | 6568 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); |
| 6569 | size_t used_bits = 0; | 6569 | size_t used_bits = 0; |
| 6570 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { | 6570 | for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { |
| 6571 | TypeStructField *field = &type_entry->data.structure.fields[i]; | 6571 | TypeStructField *field = type_entry->data.structure.fields[i]; |
| 6572 | if (field->gen_index == SIZE_MAX) { | 6572 | if (field->gen_index == SIZE_MAX) { |
| 6573 | continue; | 6573 | continue; |
| 6574 | } | 6574 | } |
| ... | @@ -6647,7 +6647,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con | ... | @@ -6647,7 +6647,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con |
| 6647 | return const_val->global_refs->llvm_value; | 6647 | return const_val->global_refs->llvm_value; |
| 6648 | } | 6648 | } |
| 6649 | size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index; | 6649 | size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index; |
| 6650 | size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index].gen_index; | 6650 | size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index; |
| 6651 | LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val, | 6651 | LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val, |
| 6652 | gen_field_index); | 6652 | gen_field_index); |
| 6653 | LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type)); | 6653 | LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type)); |
| ... | @@ -6826,7 +6826,7 @@ check: switch (const_val->special) { | ... | @@ -6826,7 +6826,7 @@ check: switch (const_val->special) { |
| 6826 | if (type_entry->data.structure.layout == ContainerLayoutPacked) { | 6826 | if (type_entry->data.structure.layout == ContainerLayoutPacked) { |
| 6827 | size_t src_field_index = 0; | 6827 | size_t src_field_index = 0; |
| 6828 | while (src_field_index < src_field_count) { | 6828 | while (src_field_index < src_field_count) { |
| 6829 | TypeStructField *type_struct_field = &type_entry->data.structure.fields[src_field_index]; | 6829 | TypeStructField *type_struct_field = type_entry->data.structure.fields[src_field_index]; |
| 6830 | if (type_struct_field->gen_index == SIZE_MAX) { | 6830 | if (type_struct_field->gen_index == SIZE_MAX) { |
| 6831 | src_field_index += 1; | 6831 | src_field_index += 1; |
| 6832 | continue; | 6832 | continue; |
| ... | @@ -6834,7 +6834,7 @@ check: switch (const_val->special) { | ... | @@ -6834,7 +6834,7 @@ check: switch (const_val->special) { |
| 6834 | 6834 | ||
| 6835 | size_t src_field_index_end = src_field_index + 1; | 6835 | size_t src_field_index_end = src_field_index + 1; |
| 6836 | for (; src_field_index_end < src_field_count; src_field_index_end += 1) { | 6836 | for (; src_field_index_end < src_field_count; src_field_index_end += 1) { |
| 6837 | TypeStructField *it_field = &type_entry->data.structure.fields[src_field_index_end]; | 6837 | TypeStructField *it_field = type_entry->data.structure.fields[src_field_index_end]; |
| 6838 | if (it_field->gen_index != type_struct_field->gen_index) | 6838 | if (it_field->gen_index != type_struct_field->gen_index) |
| 6839 | break; | 6839 | break; |
| 6840 | } | 6840 | } |
| ... | @@ -6853,7 +6853,7 @@ check: switch (const_val->special) { | ... | @@ -6853,7 +6853,7 @@ check: switch (const_val->special) { |
| 6853 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); | 6853 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); |
| 6854 | size_t used_bits = 0; | 6854 | size_t used_bits = 0; |
| 6855 | for (size_t i = src_field_index; i < src_field_index_end; i += 1) { | 6855 | for (size_t i = src_field_index; i < src_field_index_end; i += 1) { |
| 6856 | TypeStructField *it_field = &type_entry->data.structure.fields[i]; | 6856 | TypeStructField *it_field = type_entry->data.structure.fields[i]; |
| 6857 | if (it_field->gen_index == SIZE_MAX) { | 6857 | if (it_field->gen_index == SIZE_MAX) { |
| 6858 | continue; | 6858 | continue; |
| 6859 | } | 6859 | } |
| ... | @@ -6893,7 +6893,7 @@ check: switch (const_val->special) { | ... | @@ -6893,7 +6893,7 @@ check: switch (const_val->special) { |
| 6893 | } | 6893 | } |
| 6894 | } else { | 6894 | } else { |
| 6895 | for (uint32_t i = 0; i < src_field_count; i += 1) { | 6895 | for (uint32_t i = 0; i < src_field_count; i += 1) { |
| 6896 | TypeStructField *type_struct_field = &type_entry->data.structure.fields[i]; | 6896 | TypeStructField *type_struct_field = type_entry->data.structure.fields[i]; |
| 6897 | if (type_struct_field->gen_index == SIZE_MAX) { | 6897 | if (type_struct_field->gen_index == SIZE_MAX) { |
| 6898 | continue; | 6898 | continue; |
| 6899 | } | 6899 | } |
| ... | @@ -6910,10 +6910,10 @@ check: switch (const_val->special) { | ... | @@ -6910,10 +6910,10 @@ check: switch (const_val->special) { |
| 6910 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val); | 6910 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val); |
| 6911 | 6911 | ||
| 6912 | size_t end_pad_gen_index = (i + 1 < src_field_count) ? | 6912 | size_t end_pad_gen_index = (i + 1 < src_field_count) ? |
| 6913 | type_entry->data.structure.fields[i + 1].gen_index : | 6913 | type_entry->data.structure.fields[i + 1]->gen_index : |
| 6914 | type_entry->data.structure.gen_field_count; | 6914 | type_entry->data.structure.gen_field_count; |
| 6915 | size_t next_offset = (i + 1 < src_field_count) ? | 6915 | size_t next_offset = (i + 1 < src_field_count) ? |
| 6916 | type_entry->data.structure.fields[i + 1].offset : type_entry->abi_size; | 6916 | type_entry->data.structure.fields[i + 1]->offset : type_entry->abi_size; |
| 6917 | if (end_pad_gen_index != SIZE_MAX) { | 6917 | if (end_pad_gen_index != SIZE_MAX) { |
| 6918 | for (size_t gen_i = type_struct_field->gen_index + 1; gen_i < end_pad_gen_index; | 6918 | for (size_t gen_i = type_struct_field->gen_index + 1; gen_i < end_pad_gen_index; |
| 6919 | gen_i += 1) | 6919 | gen_i += 1) |
| ... | @@ -7576,15 +7576,15 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -7576,15 +7576,15 @@ static void do_code_gen(CodeGen *g) { |
| 7576 | // finishing error return trace setup. we have to do this after all the allocas. | 7576 | // finishing error return trace setup. we have to do this after all the allocas. |
| 7577 | if (have_err_ret_trace_stack) { | 7577 | if (have_err_ret_trace_stack) { |
| 7578 | ZigType *usize = g->builtin_types.entry_usize; | 7578 | ZigType *usize = g->builtin_types.entry_usize; |
| 7579 | size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index; | 7579 | size_t index_field_index = g->stack_trace_type->data.structure.fields[0]->gen_index; |
| 7580 | LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, ""); | 7580 | LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, ""); |
| 7581 | gen_store_untyped(g, LLVMConstNull(usize->llvm_type), index_field_ptr, 0, false); | 7581 | gen_store_untyped(g, LLVMConstNull(usize->llvm_type), index_field_ptr, 0, false); |
| 7582 | 7582 | ||
| 7583 | size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index; | 7583 | size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1]->gen_index; |
| 7584 | LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, ""); | 7584 | LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, ""); |
| 7585 | 7585 | ||
| 7586 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; | 7586 | ZigType *slice_type = g->stack_trace_type->data.structure.fields[1]->type_entry; |
| 7587 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; | 7587 | size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index]->gen_index; |
| 7588 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); | 7588 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); |
| 7589 | LLVMValueRef zero = LLVMConstNull(usize->llvm_type); | 7589 | LLVMValueRef zero = LLVMConstNull(usize->llvm_type); |
| 7590 | LLVMValueRef indices[] = {zero, zero}; | 7590 | LLVMValueRef indices[] = {zero, zero}; |
| ... | @@ -7593,7 +7593,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -7593,7 +7593,7 @@ static void do_code_gen(CodeGen *g) { |
| 7593 | ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); | 7593 | ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); |
| 7594 | gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type); | 7594 | gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type); |
| 7595 | 7595 | ||
| 7596 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; | 7596 | size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index; |
| 7597 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, ""); | 7597 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, ""); |
| 7598 | gen_store(g, LLVMConstInt(usize->llvm_type, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false)); | 7598 | gen_store(g, LLVMConstInt(usize->llvm_type, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false)); |
| 7599 | } | 7599 | } |
| ... | @@ -9508,7 +9508,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e | ... | @@ -9508,7 +9508,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e |
| 9508 | return; | 9508 | return; |
| 9509 | case ZigTypeIdStruct: | 9509 | case ZigTypeIdStruct: |
| 9510 | for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { | 9510 | for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { |
| 9511 | TypeStructField *field = &type_entry->data.structure.fields[i]; | 9511 | TypeStructField *field = type_entry->data.structure.fields[i]; |
| 9512 | prepend_c_type_to_decl_list(g, gen_h, field->type_entry); | 9512 | prepend_c_type_to_decl_list(g, gen_h, field->type_entry); |
| 9513 | } | 9513 | } |
| 9514 | gen_h->types_to_declare.append(type_entry); | 9514 | gen_h->types_to_declare.append(type_entry); |
| ... | @@ -9874,7 +9874,7 @@ static void gen_h_file(CodeGen *g) { | ... | @@ -9874,7 +9874,7 @@ static void gen_h_file(CodeGen *g) { |
| 9874 | if (type_entry->data.structure.layout == ContainerLayoutExtern) { | 9874 | if (type_entry->data.structure.layout == ContainerLayoutExtern) { |
| 9875 | fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry))); | 9875 | fprintf(out_h, "struct %s {\n", buf_ptr(type_h_name(type_entry))); |
| 9876 | for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) { | 9876 | for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) { |
| 9877 | TypeStructField *struct_field = &type_entry->data.structure.fields[field_i]; | 9877 | TypeStructField *struct_field = type_entry->data.structure.fields[field_i]; |
| 9878 | 9878 | ||
| 9879 | Buf *type_name_buf = buf_alloc(); | 9879 | Buf *type_name_buf = buf_alloc(); |
| 9880 | get_c_type(g, gen_h, struct_field->type_entry, type_name_buf); | 9880 | get_c_type(g, gen_h, struct_field->type_entry, type_name_buf); |
src/dump_analysis.cpp+3-3| ... | @@ -268,7 +268,7 @@ static void tree_print_struct(FILE *f, ZigType *struct_type, size_t indent) { | ... | @@ -268,7 +268,7 @@ static void tree_print_struct(FILE *f, ZigType *struct_type, size_t indent) { |
| 268 | ZigList<ZigType *> children = {}; | 268 | ZigList<ZigType *> children = {}; |
| 269 | uint64_t sum_from_fields = 0; | 269 | uint64_t sum_from_fields = 0; |
| 270 | for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { | 270 | for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { |
| 271 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 271 | TypeStructField *field = struct_type->data.structure.fields[i]; |
| 272 | children.append(field->type_entry); | 272 | children.append(field->type_entry); |
| 273 | sum_from_fields += field->type_entry->abi_size; | 273 | sum_from_fields += field->type_entry->abi_size; |
| 274 | } | 274 | } |
| ... | @@ -747,7 +747,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { | ... | @@ -747,7 +747,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { |
| 747 | if (ty->data.structure.is_slice) { | 747 | if (ty->data.structure.is_slice) { |
| 748 | jw_object_field(jw, "len"); | 748 | jw_object_field(jw, "len"); |
| 749 | jw_int(jw, 2); | 749 | jw_int(jw, 2); |
| 750 | anal_dump_pointer_attrs(ctx, ty->data.structure.fields[slice_ptr_index].type_entry); | 750 | anal_dump_pointer_attrs(ctx, ty->data.structure.fields[slice_ptr_index]->type_entry); |
| 751 | break; | 751 | break; |
| 752 | } | 752 | } |
| 753 | 753 | ||
| ... | @@ -803,7 +803,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { | ... | @@ -803,7 +803,7 @@ static void anal_dump_type(AnalDumpCtx *ctx, ZigType *ty) { |
| 803 | 803 | ||
| 804 | for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { | 804 | for(size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { |
| 805 | jw_array_elem(jw); | 805 | jw_array_elem(jw); |
| 806 | anal_dump_type_ref(ctx, ty->data.structure.fields[i].type_entry); | 806 | anal_dump_type_ref(ctx, ty->data.structure.fields[i]->type_entry); |
| 807 | } | 807 | } |
| 808 | jw_end_array(jw); | 808 | jw_end_array(jw); |
| 809 | } | 809 | } |
src/ir.cpp+38-46| ... | @@ -277,7 +277,7 @@ static bool is_slice(ZigType *type) { | ... | @@ -277,7 +277,7 @@ static bool is_slice(ZigType *type) { |
| 277 | 277 | ||
| 278 | static bool slice_is_const(ZigType *type) { | 278 | static bool slice_is_const(ZigType *type) { |
| 279 | assert(is_slice(type)); | 279 | assert(is_slice(type)); |
| 280 | return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; | 280 | return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 281 | } | 281 | } |
| 282 | 282 | ||
| 283 | // This function returns true when you can change the type of a ConstExprValue and the | 283 | // This function returns true when you can change the type of a ConstExprValue and the |
| ... | @@ -9858,8 +9858,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -9858,8 +9858,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 9858 | 9858 | ||
| 9859 | // slice const | 9859 | // slice const |
| 9860 | if (is_slice(wanted_type) && is_slice(actual_type)) { | 9860 | if (is_slice(wanted_type) && is_slice(actual_type)) { |
| 9861 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; | 9861 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 9862 | ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 9862 | ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 9863 | if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { | 9863 | if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 9864 | result.id = ConstCastResultIdInvalid; | 9864 | result.id = ConstCastResultIdInvalid; |
| 9865 | return result; | 9865 | return result; |
| ... | @@ -10623,7 +10623,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -10623,7 +10623,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10623 | ZigType *array_type = cur_type->data.pointer.child_type; | 10623 | ZigType *array_type = cur_type->data.pointer.child_type; |
| 10624 | ZigType *slice_type = (prev_type->id == ZigTypeIdErrorUnion) ? | 10624 | ZigType *slice_type = (prev_type->id == ZigTypeIdErrorUnion) ? |
| 10625 | prev_type->data.error_union.payload_type : prev_type; | 10625 | prev_type->data.error_union.payload_type : prev_type; |
| 10626 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; | 10626 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 10627 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 10627 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 10628 | types_match_const_cast_only(ira, | 10628 | types_match_const_cast_only(ira, |
| 10629 | slice_ptr_type->data.pointer.child_type, | 10629 | slice_ptr_type->data.pointer.child_type, |
| ... | @@ -10644,7 +10644,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -10644,7 +10644,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10644 | ZigType *array_type = prev_type->data.pointer.child_type; | 10644 | ZigType *array_type = prev_type->data.pointer.child_type; |
| 10645 | ZigType *slice_type = (cur_type->id == ZigTypeIdErrorUnion) ? | 10645 | ZigType *slice_type = (cur_type->id == ZigTypeIdErrorUnion) ? |
| 10646 | cur_type->data.error_union.payload_type : cur_type; | 10646 | cur_type->data.error_union.payload_type : cur_type; |
| 10647 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; | 10647 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 10648 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && | 10648 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 10649 | types_match_const_cast_only(ira, | 10649 | types_match_const_cast_only(ira, |
| 10650 | slice_ptr_type->data.pointer.child_type, | 10650 | slice_ptr_type->data.pointer.child_type, |
| ... | @@ -10658,10 +10658,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -10658,10 +10658,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10658 | 10658 | ||
| 10659 | // [N]T to []T | 10659 | // [N]T to []T |
| 10660 | if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) && | 10660 | if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) && |
| 10661 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 10661 | (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const || |
| 10662 | cur_type->data.array.len == 0) && | 10662 | cur_type->data.array.len == 0) && |
| 10663 | types_match_const_cast_only(ira, | 10663 | types_match_const_cast_only(ira, |
| 10664 | prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 10664 | prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type, |
| 10665 | cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) | 10665 | cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) |
| 10666 | { | 10666 | { |
| 10667 | convert_to_const_slice = false; | 10667 | convert_to_const_slice = false; |
| ... | @@ -10670,10 +10670,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -10670,10 +10670,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10670 | 10670 | ||
| 10671 | // [N]T to []T | 10671 | // [N]T to []T |
| 10672 | if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) && | 10672 | if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) && |
| 10673 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || | 10673 | (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const || |
| 10674 | prev_type->data.array.len == 0) && | 10674 | prev_type->data.array.len == 0) && |
| 10675 | types_match_const_cast_only(ira, | 10675 | types_match_const_cast_only(ira, |
| 10676 | cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, | 10676 | cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type, |
| 10677 | prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) | 10677 | prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) |
| 10678 | { | 10678 | { |
| 10679 | prev_inst = cur_inst; | 10679 | prev_inst = cur_inst; |
| ... | @@ -10978,7 +10978,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc | ... | @@ -10978,7 +10978,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 10978 | assert(value->value.type->id == ZigTypeIdPointer); | 10978 | assert(value->value.type->id == ZigTypeIdPointer); |
| 10979 | ZigType *array_type = value->value.type->data.pointer.child_type; | 10979 | ZigType *array_type = value->value.type->data.pointer.child_type; |
| 10980 | assert(is_slice(wanted_type)); | 10980 | assert(is_slice(wanted_type)); |
| 10981 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; | 10981 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 10982 | 10982 | ||
| 10983 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); | 10983 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 10984 | init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const); | 10984 | init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const); |
| ... | @@ -12775,7 +12775,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12775,7 +12775,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12775 | // cast from [N]T to []const T | 12775 | // cast from [N]T to []const T |
| 12776 | // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this | 12776 | // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this |
| 12777 | if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { | 12777 | if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { |
| 12778 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 12778 | ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12779 | assert(ptr_type->id == ZigTypeIdPointer); | 12779 | assert(ptr_type->id == ZigTypeIdPointer); |
| 12780 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 12780 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 12781 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 12781 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| ... | @@ -12792,7 +12792,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12792,7 +12792,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12792 | actual_type->id == ZigTypeIdArray) | 12792 | actual_type->id == ZigTypeIdArray) |
| 12793 | { | 12793 | { |
| 12794 | ZigType *ptr_type = | 12794 | ZigType *ptr_type = |
| 12795 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; | 12795 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12796 | assert(ptr_type->id == ZigTypeIdPointer); | 12796 | assert(ptr_type->id == ZigTypeIdPointer); |
| 12797 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 12797 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 12798 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 12798 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| ... | @@ -12841,7 +12841,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12841,7 +12841,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12841 | { | 12841 | { |
| 12842 | ZigType *slice_type = (wanted_type->id == ZigTypeIdErrorUnion) ? | 12842 | ZigType *slice_type = (wanted_type->id == ZigTypeIdErrorUnion) ? |
| 12843 | wanted_type->data.error_union.payload_type : wanted_type; | 12843 | wanted_type->data.error_union.payload_type : wanted_type; |
| 12844 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; | 12844 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12845 | assert(slice_ptr_type->id == ZigTypeIdPointer); | 12845 | assert(slice_ptr_type->id == ZigTypeIdPointer); |
| 12846 | ZigType *array_type = actual_type->data.pointer.child_type; | 12846 | ZigType *array_type = actual_type->data.pointer.child_type; |
| 12847 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 | 12847 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 |
| ... | @@ -12895,7 +12895,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12895,7 +12895,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12895 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) | 12895 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 12896 | { | 12896 | { |
| 12897 | ZigType *slice_type = wanted_type->data.error_union.payload_type; | 12897 | ZigType *slice_type = wanted_type->data.error_union.payload_type; |
| 12898 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; | 12898 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12899 | assert(slice_ptr_type->id == ZigTypeIdPointer); | 12899 | assert(slice_ptr_type->id == ZigTypeIdPointer); |
| 12900 | ZigType *array_type = actual_type->data.pointer.child_type; | 12900 | ZigType *array_type = actual_type->data.pointer.child_type; |
| 12901 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 | 12901 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 |
| ... | @@ -12972,7 +12972,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -12972,7 +12972,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12972 | actual_type->id == ZigTypeIdArray) | 12972 | actual_type->id == ZigTypeIdArray) |
| 12973 | { | 12973 | { |
| 12974 | ZigType *ptr_type = | 12974 | ZigType *ptr_type = |
| 12975 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; | 12975 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12976 | assert(ptr_type->id == ZigTypeIdPointer); | 12976 | assert(ptr_type->id == ZigTypeIdPointer); |
| 12977 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && | 12977 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 12978 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, | 12978 | types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, |
| ... | @@ -14817,7 +14817,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i | ... | @@ -14817,7 +14817,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 14817 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; | 14817 | op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; |
| 14818 | op1_array_end = op1_array_val->type->data.array.len - 1; | 14818 | op1_array_end = op1_array_val->type->data.array.len - 1; |
| 14819 | } else if (is_slice(op1_type)) { | 14819 | } else if (is_slice(op1_type)) { |
| 14820 | ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; | 14820 | ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 14821 | child_type = ptr_type->data.pointer.child_type; | 14821 | child_type = ptr_type->data.pointer.child_type; |
| 14822 | ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; | 14822 | ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; |
| 14823 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); | 14823 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | @@ -14850,7 +14850,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i | ... | @@ -14850,7 +14850,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 14850 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; | 14850 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; |
| 14851 | op2_array_end = op2_array_val->type->data.array.len - 1; | 14851 | op2_array_end = op2_array_val->type->data.array.len - 1; |
| 14852 | } else if (is_slice(op2_type)) { | 14852 | } else if (is_slice(op2_type)) { |
| 14853 | ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; | 14853 | ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 14854 | op2_type_valid = ptr_type->data.pointer.child_type == child_type; | 14854 | op2_type_valid = ptr_type->data.pointer.child_type == child_type; |
| 14855 | ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; | 14855 | ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; |
| 14856 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); | 14856 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | @@ -16458,18 +16458,10 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source | ... | @@ -16458,18 +16458,10 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16458 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; | 16458 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 16459 | uint32_t new_field_count = old_field_count + 1; | 16459 | uint32_t new_field_count = old_field_count + 1; |
| 16460 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; | 16460 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; |
| 16461 | if (new_field_count > 16) { | 16461 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( |
| 16462 | // This thing with 16 is a hack to allow this functionality to work without | 16462 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); |
| 16463 | // modifying the ConstExprValue layout of structs. That reworking needs to be | ||
| 16464 | // done, but this hack lets us do it separately, in the future. | ||
| 16465 | zig_panic("TODO need to rework the layout of ZigTypeStruct. This realloc would have caused invalid pointer references"); | ||
| 16466 | } | ||
| 16467 | if (isf->inferred_struct_type->data.structure.fields == nullptr) { | ||
| 16468 | isf->inferred_struct_type->data.structure.fields = allocate<TypeStructField>(16); | ||
| 16469 | } | ||
| 16470 | 16463 | ||
| 16471 | // This reference can't live long, don't keep it around outside this block. | 16464 | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 16472 | TypeStructField *field = &isf->inferred_struct_type->data.structure.fields[old_field_count]; | ||
| 16473 | field->name = isf->field_name; | 16465 | field->name = isf->field_name; |
| 16474 | field->type_entry = uncasted_value->value.type; | 16466 | field->type_entry = uncasted_value->value.type; |
| 16475 | field->type_val = create_const_type(ira->codegen, field->type_entry); | 16467 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| ... | @@ -17900,7 +17892,7 @@ static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_ali | ... | @@ -17900,7 +17892,7 @@ static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_ali |
| 17900 | 17892 | ||
| 17901 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { | 17893 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { |
| 17902 | assert(is_slice(slice_type)); | 17894 | assert(is_slice(slice_type)); |
| 17903 | ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry, | 17895 | ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index]->type_entry, |
| 17904 | new_align); | 17896 | new_align); |
| 17905 | return get_slice_type(g, ptr_type); | 17897 | return get_slice_type(g, ptr_type); |
| 17906 | } | 17898 | } |
| ... | @@ -17986,7 +17978,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -17986,7 +17978,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 17986 | } | 17978 | } |
| 17987 | return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len); | 17979 | return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len); |
| 17988 | } else if (is_slice(array_type)) { | 17980 | } else if (is_slice(array_type)) { |
| 17989 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry, | 17981 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry, |
| 17990 | elem_ptr_instruction->ptr_len); | 17982 | elem_ptr_instruction->ptr_len); |
| 17991 | } else if (array_type->id == ZigTypeIdArgTuple) { | 17983 | } else if (array_type->id == ZigTypeIdArgTuple) { |
| 17992 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); | 17984 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| ... | @@ -18464,7 +18456,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction | ... | @@ -18464,7 +18456,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18464 | ConstExprValue *field_val = struct_val->data.x_struct.fields[i]; | 18456 | ConstExprValue *field_val = struct_val->data.x_struct.fields[i]; |
| 18465 | field_val->special = ConstValSpecialUndef; | 18457 | field_val->special = ConstValSpecialUndef; |
| 18466 | field_val->type = resolve_struct_field_type(ira->codegen, | 18458 | field_val->type = resolve_struct_field_type(ira->codegen, |
| 18467 | &struct_type->data.structure.fields[i]); | 18459 | struct_type->data.structure.fields[i]); |
| 18468 | field_val->parent.id = ConstParentIdStruct; | 18460 | field_val->parent.id = ConstParentIdStruct; |
| 18469 | field_val->parent.data.p_struct.struct_val = struct_val; | 18461 | field_val->parent.data.p_struct.struct_val = struct_val; |
| 18470 | field_val->parent.data.p_struct.field_index = i; | 18462 | field_val->parent.data.p_struct.field_index = i; |
| ... | @@ -20385,7 +20377,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -20385,7 +20377,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20385 | if (field_assign_nodes[i] != nullptr) continue; | 20377 | if (field_assign_nodes[i] != nullptr) continue; |
| 20386 | 20378 | ||
| 20387 | // look for a default field value | 20379 | // look for a default field value |
| 20388 | TypeStructField *field = &container_type->data.structure.fields[i]; | 20380 | TypeStructField *field = container_type->data.structure.fields[i]; |
| 20389 | if (field->init_val == nullptr) { | 20381 | if (field->init_val == nullptr) { |
| 20390 | // it's not memoized. time to go analyze it | 20382 | // it's not memoized. time to go analyze it |
| 20391 | AstNode *init_node; | 20383 | AstNode *init_node; |
| ... | @@ -20396,7 +20388,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc | ... | @@ -20396,7 +20388,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20396 | } | 20388 | } |
| 20397 | if (init_node == nullptr) { | 20389 | if (init_node == nullptr) { |
| 20398 | ir_add_error_node(ira, instruction->source_node, | 20390 | ir_add_error_node(ira, instruction->source_node, |
| 20399 | buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name))); | 20391 | buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name))); |
| 20400 | any_missing = true; | 20392 | any_missing = true; |
| 20401 | continue; | 20393 | continue; |
| 20402 | } | 20394 | } |
| ... | @@ -21198,7 +21190,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty | ... | @@ -21198,7 +21190,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 21198 | ZigType *attrs_type; | 21190 | ZigType *attrs_type; |
| 21199 | BuiltinPtrSize size_enum_index; | 21191 | BuiltinPtrSize size_enum_index; |
| 21200 | if (is_slice(ptr_type_entry)) { | 21192 | if (is_slice(ptr_type_entry)) { |
| 21201 | attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; | 21193 | attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index]->type_entry; |
| 21202 | size_enum_index = BuiltinPtrSizeSlice; | 21194 | size_enum_index = BuiltinPtrSizeSlice; |
| 21203 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { | 21195 | } else if (ptr_type_entry->id == ZigTypeIdPointer) { |
| 21204 | attrs_type = ptr_type_entry; | 21196 | attrs_type = ptr_type_entry; |
| ... | @@ -21691,7 +21683,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr | ... | @@ -21691,7 +21683,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21691 | init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false); | 21683 | init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false); |
| 21692 | 21684 | ||
| 21693 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { | 21685 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { |
| 21694 | TypeStructField *struct_field = &type_entry->data.structure.fields[struct_field_index]; | 21686 | TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index]; |
| 21695 | ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; | 21687 | ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; |
| 21696 | 21688 | ||
| 21697 | struct_field_val->special = ConstValSpecialStatic; | 21689 | struct_field_val->special = ConstValSpecialStatic; |
| ... | @@ -22647,7 +22639,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru | ... | @@ -22647,7 +22639,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 22647 | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) | 22639 | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) |
| 22648 | return ira->codegen->invalid_instruction; | 22640 | return ira->codegen->invalid_instruction; |
| 22649 | } else if (is_slice(target->value.type)) { | 22641 | } else if (is_slice(target->value.type)) { |
| 22650 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 22642 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 22651 | src_ptr_const = src_ptr_type->data.pointer.is_const; | 22643 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 22652 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; | 22644 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 22653 | 22645 | ||
| ... | @@ -22740,7 +22732,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -22740,7 +22732,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 22740 | return ira->codegen->invalid_instruction; | 22732 | return ira->codegen->invalid_instruction; |
| 22741 | } | 22733 | } |
| 22742 | 22734 | ||
| 22743 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 22735 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 22744 | 22736 | ||
| 22745 | uint32_t alignment; | 22737 | uint32_t alignment; |
| 22746 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) | 22738 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| ... | @@ -23548,7 +23540,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -23548,7 +23540,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 23548 | } | 23540 | } |
| 23549 | } | 23541 | } |
| 23550 | } else if (is_slice(array_type)) { | 23542 | } else if (is_slice(array_type)) { |
| 23551 | ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry; | 23543 | ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23552 | return_type = get_slice_type(ira->codegen, ptr_type); | 23544 | return_type = get_slice_type(ira->codegen, ptr_type); |
| 23553 | } else { | 23545 | } else { |
| 23554 | ir_add_error(ira, &instruction->base, | 23546 | ir_add_error(ira, &instruction->base, |
| ... | @@ -23857,7 +23849,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr | ... | @@ -23857,7 +23849,7 @@ static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstr |
| 23857 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); | 23849 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 23858 | return ira->codegen->invalid_instruction; | 23850 | return ira->codegen->invalid_instruction; |
| 23859 | } | 23851 | } |
| 23860 | TypeStructField *field = &container_type->data.structure.fields[member_index]; | 23852 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 23861 | 23853 | ||
| 23862 | return ir_const_type(ira, &instruction->base, field->type_entry); | 23854 | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 23863 | } else if (container_type->id == ZigTypeIdUnion) { | 23855 | } else if (container_type->id == ZigTypeIdUnion) { |
| ... | @@ -23899,7 +23891,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr | ... | @@ -23899,7 +23891,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 23899 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); | 23891 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 23900 | return ira->codegen->invalid_instruction; | 23892 | return ira->codegen->invalid_instruction; |
| 23901 | } | 23893 | } |
| 23902 | TypeStructField *field = &container_type->data.structure.fields[member_index]; | 23894 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 23903 | 23895 | ||
| 23904 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); | 23896 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23905 | init_const_str_lit(ira->codegen, &result->value, field->name); | 23897 | init_const_str_lit(ira->codegen, &result->value, field->name); |
| ... | @@ -24885,7 +24877,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 | ... | @@ -24885,7 +24877,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 24885 | ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id); | 24877 | ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id); |
| 24886 | result_type = get_optional_type(ira->codegen, fn_type); | 24878 | result_type = get_optional_type(ira->codegen, fn_type); |
| 24887 | } else if (is_slice(target_type)) { | 24879 | } else if (is_slice(target_type)) { |
| 24888 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; | 24880 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 24889 | if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes))) | 24881 | if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes))) |
| 24890 | return ira->codegen->invalid_instruction; | 24882 | return ira->codegen->invalid_instruction; |
| 24891 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); | 24883 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| ... | @@ -25130,7 +25122,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -25130,7 +25122,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 25130 | case ContainerLayoutExtern: { | 25122 | case ContainerLayoutExtern: { |
| 25131 | size_t src_field_count = val->type->data.structure.src_field_count; | 25123 | size_t src_field_count = val->type->data.structure.src_field_count; |
| 25132 | for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { | 25124 | for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { |
| 25133 | TypeStructField *struct_field = &val->type->data.structure.fields[field_i]; | 25125 | TypeStructField *struct_field = val->type->data.structure.fields[field_i]; |
| 25134 | if (struct_field->gen_index == SIZE_MAX) | 25126 | if (struct_field->gen_index == SIZE_MAX) |
| 25135 | continue; | 25127 | continue; |
| 25136 | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; | 25128 | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; |
| ... | @@ -25159,7 +25151,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue | ... | @@ -25159,7 +25151,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 25159 | bigint_init_unsigned(&big_int, 0); | 25151 | bigint_init_unsigned(&big_int, 0); |
| 25160 | size_t used_bits = 0; | 25152 | size_t used_bits = 0; |
| 25161 | while (src_i < src_field_count) { | 25153 | while (src_i < src_field_count) { |
| 25162 | TypeStructField *field = &val->type->data.structure.fields[src_i]; | 25154 | TypeStructField *field = val->type->data.structure.fields[src_i]; |
| 25163 | assert(field->gen_index != SIZE_MAX); | 25155 | assert(field->gen_index != SIZE_MAX); |
| 25164 | if (field->gen_index != gen_i) | 25156 | if (field->gen_index != gen_i) |
| 25165 | break; | 25157 | break; |
| ... | @@ -25306,7 +25298,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou | ... | @@ -25306,7 +25298,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 25306 | for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { | 25298 | for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { |
| 25307 | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; | 25299 | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; |
| 25308 | field_val->special = ConstValSpecialStatic; | 25300 | field_val->special = ConstValSpecialStatic; |
| 25309 | TypeStructField *struct_field = &val->type->data.structure.fields[field_i]; | 25301 | TypeStructField *struct_field = val->type->data.structure.fields[field_i]; |
| 25310 | field_val->type = struct_field->type_entry; | 25302 | field_val->type = struct_field->type_entry; |
| 25311 | if (struct_field->gen_index == SIZE_MAX) | 25303 | if (struct_field->gen_index == SIZE_MAX) |
| 25312 | continue; | 25304 | continue; |
| ... | @@ -25337,7 +25329,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou | ... | @@ -25337,7 +25329,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 25337 | BigInt big_int; | 25329 | BigInt big_int; |
| 25338 | bigint_read_twos_complement(&big_int, buf + offset, big_int_byte_count * 8, is_big_endian, false); | 25330 | bigint_read_twos_complement(&big_int, buf + offset, big_int_byte_count * 8, is_big_endian, false); |
| 25339 | while (src_i < src_field_count) { | 25331 | while (src_i < src_field_count) { |
| 25340 | TypeStructField *field = &val->type->data.structure.fields[src_i]; | 25332 | TypeStructField *field = val->type->data.structure.fields[src_i]; |
| 25341 | src_assert(field->gen_index != SIZE_MAX, source_node); | 25333 | src_assert(field->gen_index != SIZE_MAX, source_node); |
| 25342 | if (field->gen_index != gen_i) | 25334 | if (field->gen_index != gen_i) |
| 25343 | break; | 25335 | break; |
| ... | @@ -25600,7 +25592,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru | ... | @@ -25600,7 +25592,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 25600 | 25592 | ||
| 25601 | ZigType *elem_type = nullptr; | 25593 | ZigType *elem_type = nullptr; |
| 25602 | if (is_slice(target->value.type)) { | 25594 | if (is_slice(target->value.type)) { |
| 25603 | ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 25595 | ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 25604 | elem_type = slice_ptr_type->data.pointer.child_type; | 25596 | elem_type = slice_ptr_type->data.pointer.child_type; |
| 25605 | } else if (target->value.type->id == ZigTypeIdPointer) { | 25597 | } else if (target->value.type->id == ZigTypeIdPointer) { |
| 25606 | elem_type = target->value.type->data.pointer.child_type; | 25598 | elem_type = target->value.type->data.pointer.child_type; |