| ... | ... | @@ -1350,18 +1350,17 @@ static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_ |
| 1350 | 1350 | |
| 1351 | 1351 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1352 | 1352 | IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len, |
| 1353 | | IrInstruction *init_array_type) |
| 1353 | AstNode *init_array_type_source_node) |
| 1354 | 1354 | { |
| 1355 | 1355 | IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node); |
| 1356 | 1356 | instruction->array_ptr = array_ptr; |
| 1357 | 1357 | instruction->elem_index = elem_index; |
| 1358 | 1358 | instruction->safety_check_on = safety_check_on; |
| 1359 | 1359 | instruction->ptr_len = ptr_len; |
| 1360 | | instruction->init_array_type = init_array_type; |
| 1360 | instruction->init_array_type_source_node = init_array_type_source_node; |
| 1361 | 1361 | |
| 1362 | 1362 | ir_ref_instruction(array_ptr, irb->current_basic_block); |
| 1363 | 1363 | ir_ref_instruction(elem_index, irb->current_basic_block); |
| 1364 | | if (init_array_type != nullptr) ir_ref_instruction(init_array_type, irb->current_basic_block); |
| 1365 | 1364 | |
| 1366 | 1365 | return &instruction->base; |
| 1367 | 1366 | } |
| ... | ... | @@ -1575,17 +1574,16 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1575 | 1574 | } |
| 1576 | 1575 | |
| 1577 | 1576 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1578 | | IrInstruction *container_type, size_t item_count, IrInstruction **elem_result_loc_list, |
| 1579 | | IrInstruction *result_loc) |
| 1577 | size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc, |
| 1578 | AstNode *init_array_type_source_node) |
| 1580 | 1579 | { |
| 1581 | 1580 | IrInstructionContainerInitList *container_init_list_instruction = |
| 1582 | 1581 | ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node); |
| 1583 | | container_init_list_instruction->container_type = container_type; |
| 1584 | 1582 | container_init_list_instruction->item_count = item_count; |
| 1585 | 1583 | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; |
| 1586 | 1584 | container_init_list_instruction->result_loc = result_loc; |
| 1585 | container_init_list_instruction->init_array_type_source_node = init_array_type_source_node; |
| 1587 | 1586 | |
| 1588 | | ir_ref_instruction(container_type, irb->current_basic_block); |
| 1589 | 1587 | for (size_t i = 0; i < item_count; i += 1) { |
| 1590 | 1588 | ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block); |
| 1591 | 1589 | } |
| ... | ... | @@ -1595,17 +1593,14 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, |
| 1595 | 1593 | } |
| 1596 | 1594 | |
| 1597 | 1595 | static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1598 | | IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields, |
| 1599 | | IrInstruction *result_loc) |
| 1596 | size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc) |
| 1600 | 1597 | { |
| 1601 | 1598 | IrInstructionContainerInitFields *container_init_fields_instruction = |
| 1602 | 1599 | ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node); |
| 1603 | | container_init_fields_instruction->container_type = container_type; |
| 1604 | 1600 | container_init_fields_instruction->field_count = field_count; |
| 1605 | 1601 | container_init_fields_instruction->fields = fields; |
| 1606 | 1602 | container_init_fields_instruction->result_loc = result_loc; |
| 1607 | 1603 | |
| 1608 | | ir_ref_instruction(container_type, irb->current_basic_block); |
| 1609 | 1604 | for (size_t i = 0; i < field_count; i += 1) { |
| 1610 | 1605 | ir_ref_instruction(fields[i].result_loc, irb->current_basic_block); |
| 1611 | 1606 | } |
| ... | ... | @@ -3084,7 +3079,7 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN |
| 3084 | 3079 | instruction->result_loc = result_loc; |
| 3085 | 3080 | instruction->ty = ty; |
| 3086 | 3081 | |
| 3087 | | ir_ref_instruction(ty, irb->current_basic_block); |
| 3082 | if (ty != nullptr) ir_ref_instruction(ty, irb->current_basic_block); |
| 3088 | 3083 | |
| 3089 | 3084 | return &instruction->base; |
| 3090 | 3085 | } |
| ... | ... | @@ -6127,28 +6122,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6127 | 6122 | AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr; |
| 6128 | 6123 | ContainerInitKind kind = container_init_expr->kind; |
| 6129 | 6124 | |
| 6130 | | IrInstruction *container_type = nullptr; |
| 6131 | | IrInstruction *elem_type = nullptr; |
| 6132 | | if (container_init_expr->type->type == NodeTypeInferredArrayType) { |
| 6133 | | elem_type = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.child_type, scope); |
| 6134 | | if (elem_type == irb->codegen->invalid_instruction) |
| 6135 | | return elem_type; |
| 6136 | | } else { |
| 6137 | | container_type = ir_gen_node(irb, container_init_expr->type, scope); |
| 6138 | | if (container_type == irb->codegen->invalid_instruction) |
| 6139 | | return container_type; |
| 6140 | | } |
| 6141 | | |
| 6142 | | switch (kind) { |
| 6143 | | case ContainerInitKindStruct: { |
| 6144 | | if (elem_type != nullptr) { |
| 6125 | ResultLocCast *result_loc_cast = nullptr; |
| 6126 | ResultLoc *child_result_loc; |
| 6127 | AstNode *init_array_type_source_node; |
| 6128 | if (container_init_expr->type != nullptr) { |
| 6129 | IrInstruction *container_type; |
| 6130 | if (container_init_expr->type->type == NodeTypeInferredArrayType) { |
| 6131 | if (kind == ContainerInitKindStruct) { |
| 6145 | 6132 | add_node_error(irb->codegen, container_init_expr->type, |
| 6146 | 6133 | buf_sprintf("initializing array with struct syntax")); |
| 6147 | 6134 | return irb->codegen->invalid_instruction; |
| 6148 | 6135 | } |
| 6136 | IrInstruction *elem_type = ir_gen_node(irb, |
| 6137 | container_init_expr->type->data.inferred_array_type.child_type, scope); |
| 6138 | if (elem_type == irb->codegen->invalid_instruction) |
| 6139 | return elem_type; |
| 6140 | size_t item_count = container_init_expr->entries.length; |
| 6141 | IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 6142 | container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type); |
| 6143 | } else { |
| 6144 | container_type = ir_gen_node(irb, container_init_expr->type, scope); |
| 6145 | if (container_type == irb->codegen->invalid_instruction) |
| 6146 | return container_type; |
| 6147 | } |
| 6148 | |
| 6149 | result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc); |
| 6150 | child_result_loc = &result_loc_cast->base; |
| 6151 | init_array_type_source_node = container_type->source_node; |
| 6152 | } else { |
| 6153 | child_result_loc = parent_result_loc; |
| 6154 | init_array_type_source_node = parent_result_loc->source_instruction->source_node; |
| 6155 | } |
| 6149 | 6156 | |
| 6150 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, parent_result_loc, |
| 6151 | | container_type); |
| 6157 | switch (kind) { |
| 6158 | case ContainerInitKindStruct: { |
| 6159 | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6160 | nullptr); |
| 6152 | 6161 | |
| 6153 | 6162 | size_t field_count = container_init_expr->entries.length; |
| 6154 | 6163 | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count); |
| ... | ... | @@ -6176,29 +6185,27 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6176 | 6185 | fields[i].source_node = entry_node; |
| 6177 | 6186 | fields[i].result_loc = field_ptr; |
| 6178 | 6187 | } |
| 6179 | | IrInstruction *init_fields = ir_build_container_init_fields(irb, scope, node, container_type, |
| 6180 | | field_count, fields, container_ptr); |
| 6188 | IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count, |
| 6189 | fields, container_ptr); |
| 6181 | 6190 | |
| 6182 | | return ir_lval_wrap(irb, scope, init_fields, lval, parent_result_loc); |
| 6191 | if (result_loc_cast != nullptr) { |
| 6192 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); |
| 6193 | } |
| 6194 | return ir_lval_wrap(irb, scope, result, lval, parent_result_loc); |
| 6183 | 6195 | } |
| 6184 | 6196 | case ContainerInitKindArray: { |
| 6185 | 6197 | size_t item_count = container_init_expr->entries.length; |
| 6186 | 6198 | |
| 6187 | | if (container_type == nullptr) { |
| 6188 | | IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 6189 | | container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type); |
| 6190 | | } |
| 6191 | | |
| 6192 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, parent_result_loc, |
| 6193 | | container_type); |
| 6199 | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6200 | nullptr); |
| 6194 | 6201 | |
| 6195 | 6202 | IrInstruction **result_locs = allocate<IrInstruction *>(item_count); |
| 6196 | 6203 | for (size_t i = 0; i < item_count; i += 1) { |
| 6197 | 6204 | AstNode *expr_node = container_init_expr->entries.at(i); |
| 6198 | 6205 | |
| 6199 | 6206 | IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i); |
| 6200 | | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, elem_index, |
| 6201 | | false, PtrLenSingle, container_type); |
| 6207 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, |
| 6208 | elem_index, false, PtrLenSingle, init_array_type_source_node); |
| 6202 | 6209 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6203 | 6210 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 6204 | 6211 | result_loc_inst->base.source_instruction = elem_ptr; |
| ... | ... | @@ -6213,9 +6220,12 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6213 | 6220 | |
| 6214 | 6221 | result_locs[i] = elem_ptr; |
| 6215 | 6222 | } |
| 6216 | | IrInstruction *init_list = ir_build_container_init_list(irb, scope, node, container_type, |
| 6217 | | item_count, result_locs, container_ptr); |
| 6218 | | return ir_lval_wrap(irb, scope, init_list, lval, parent_result_loc); |
| 6223 | IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count, |
| 6224 | result_locs, container_ptr, init_array_type_source_node); |
| 6225 | if (result_loc_cast != nullptr) { |
| 6226 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); |
| 6227 | } |
| 6228 | return ir_lval_wrap(irb, scope, result, lval, parent_result_loc); |
| 6219 | 6229 | } |
| 6220 | 6230 | } |
| 6221 | 6231 | zig_unreachable(); |
| ... | ... | @@ -7935,14 +7945,14 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o |
| 7935 | 7945 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 7936 | 7946 | Scope *scope, AstNode *source_node, Buf *out_bare_name) |
| 7937 | 7947 | { |
| 7938 | | if (exec->name) { |
| 7948 | if (exec != nullptr && exec->name) { |
| 7939 | 7949 | ZigType *import = get_scope_import(scope); |
| 7940 | 7950 | Buf *namespace_name = buf_alloc(); |
| 7941 | 7951 | append_namespace_qualification(codegen, namespace_name, import); |
| 7942 | 7952 | buf_append_buf(namespace_name, exec->name); |
| 7943 | 7953 | buf_init_from_buf(out_bare_name, exec->name); |
| 7944 | 7954 | return namespace_name; |
| 7945 | | } else if (exec->name_fn != nullptr) { |
| 7955 | } else if (exec != nullptr && exec->name_fn != nullptr) { |
| 7946 | 7956 | Buf *name = buf_alloc(); |
| 7947 | 7957 | buf_append_buf(name, &exec->name_fn->symbol_name); |
| 7948 | 7958 | buf_appendf(name, "("); |
| ... | ... | @@ -15541,11 +15551,7 @@ static bool ir_result_has_type(ResultLoc *result_loc) { |
| 15541 | 15551 | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 15542 | 15552 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) |
| 15543 | 15553 | { |
| 15544 | | Error err; |
| 15545 | | |
| 15546 | 15554 | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 15547 | | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown))) |
| 15548 | | return ira->codegen->invalid_instruction; |
| 15549 | 15555 | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 15550 | 15556 | PtrLenSingle, 0, 0, 0, false); |
| 15551 | 15557 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); |
| ... | ... | @@ -15750,6 +15756,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15750 | 15756 | return casted_value; |
| 15751 | 15757 | } |
| 15752 | 15758 | |
| 15759 | bool old_parent_result_loc_written = result_cast->parent->written; |
| 15753 | 15760 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 15754 | 15761 | dest_type, casted_value, force_runtime, non_null_comptime, true); |
| 15755 | 15762 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| ... | ... | @@ -15775,6 +15782,22 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 15775 | 15782 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, |
| 15776 | 15783 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); |
| 15777 | 15784 | |
| 15785 | { |
| 15786 | // we also need to check that this cast is OK. |
| 15787 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 15788 | parent_result_loc->value.type, ptr_type, |
| 15789 | result_cast->base.source_instruction->source_node, false); |
| 15790 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 15791 | return ira->codegen->invalid_instruction; |
| 15792 | if (const_cast_result.id != ConstCastResultIdOk) { |
| 15793 | // We will not be able to provide a result location for this value. Create |
| 15794 | // a new result location. |
| 15795 | result_cast->parent->written = old_parent_result_loc_written; |
| 15796 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 15797 | force_runtime, non_null_comptime); |
| 15798 | } |
| 15799 | } |
| 15800 | |
| 15778 | 15801 | result_loc->written = true; |
| 15779 | 15802 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 15780 | 15803 | ptr_type, result_cast->base.source_instruction, false); |
| ... | ... | @@ -15902,10 +15925,33 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 15902 | 15925 | return result_loc; |
| 15903 | 15926 | } |
| 15904 | 15927 | |
| 15905 | | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstructionResolveResult *instruction) { |
| 15906 | | ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 15907 | | if (type_is_invalid(implicit_elem_type)) |
| 15908 | | return ira->codegen->invalid_instruction; |
| 15928 | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 15929 | IrInstructionResolveResult *instruction) |
| 15930 | { |
| 15931 | ZigType *implicit_elem_type; |
| 15932 | if (instruction->ty == nullptr) { |
| 15933 | if (instruction->result_loc->id == ResultLocIdCast) { |
| 15934 | implicit_elem_type = ir_resolve_type(ira, |
| 15935 | instruction->result_loc->source_instruction->child); |
| 15936 | if (type_is_invalid(implicit_elem_type)) |
| 15937 | return ira->codegen->invalid_instruction; |
| 15938 | } else { |
| 15939 | Buf *bare_name = buf_alloc(); |
| 15940 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 15941 | instruction->base.scope, instruction->base.source_node, bare_name); |
| 15942 | |
| 15943 | ZigType *inferred_struct_type = get_partial_container_type(ira->codegen, |
| 15944 | instruction->base.scope, ContainerKindStruct, instruction->base.source_node, |
| 15945 | buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 15946 | inferred_struct_type->data.structure.is_inferred = true; |
| 15947 | inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| 15948 | implicit_elem_type = inferred_struct_type; |
| 15949 | } |
| 15950 | } else { |
| 15951 | implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 15952 | if (type_is_invalid(implicit_elem_type)) |
| 15953 | return ira->codegen->invalid_instruction; |
| 15954 | } |
| 15909 | 15955 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 15910 | 15956 | implicit_elem_type, nullptr, false, true, true); |
| 15911 | 15957 | if (result_loc != nullptr) |
| ... | ... | @@ -17837,7 +17883,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 17837 | 17883 | if (array_ptr_val == nullptr) |
| 17838 | 17884 | return ira->codegen->invalid_instruction; |
| 17839 | 17885 | |
| 17840 | | if (array_ptr_val->special == ConstValSpecialUndef && elem_ptr_instruction->init_array_type != nullptr) { |
| 17886 | if (array_ptr_val->special == ConstValSpecialUndef && |
| 17887 | elem_ptr_instruction->init_array_type_source_node != nullptr) |
| 17888 | { |
| 17841 | 17889 | if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) { |
| 17842 | 17890 | array_ptr_val->data.x_array.special = ConstArraySpecialNone; |
| 17843 | 17891 | array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len); |
| ... | ... | @@ -17851,11 +17899,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 17851 | 17899 | elem_val->parent.data.p_array.elem_index = i; |
| 17852 | 17900 | } |
| 17853 | 17901 | } else if (is_slice(array_type)) { |
| 17854 | | ZigType *actual_array_type = ir_resolve_type(ira, elem_ptr_instruction->init_array_type->child); |
| 17902 | ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 17903 | ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type; |
| 17904 | |
| 17855 | 17905 | if (type_is_invalid(actual_array_type)) |
| 17856 | 17906 | return ira->codegen->invalid_instruction; |
| 17857 | 17907 | if (actual_array_type->id != ZigTypeIdArray) { |
| 17858 | | ir_add_error(ira, elem_ptr_instruction->init_array_type, |
| 17908 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 17859 | 17909 | buf_sprintf("expected array type or [_], found slice")); |
| 17860 | 17910 | return ira->codegen->invalid_instruction; |
| 17861 | 17911 | } |
| ... | ... | @@ -17879,7 +17929,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 17879 | 17929 | false); |
| 17880 | 17930 | array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer; |
| 17881 | 17931 | } else { |
| 17882 | | ir_add_error(ira, elem_ptr_instruction->init_array_type, |
| 17932 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 17883 | 17933 | buf_sprintf("expected array type or [_], found '%s'", |
| 17884 | 17934 | buf_ptr(&array_type->name))); |
| 17885 | 17935 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -18012,7 +18062,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18012 | 18062 | if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 18013 | 18063 | result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18014 | 18064 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, |
| 18015 | | false, elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type); |
| 18065 | false, elem_ptr_instruction->ptr_len, nullptr); |
| 18016 | 18066 | result->value.type = return_type; |
| 18017 | 18067 | result->value.special = ConstValSpecialStatic; |
| 18018 | 18068 | } else { |
| ... | ... | @@ -18073,7 +18123,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18073 | 18123 | |
| 18074 | 18124 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18075 | 18125 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, |
| 18076 | | elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type); |
| 18126 | elem_ptr_instruction->ptr_len, nullptr); |
| 18077 | 18127 | result->value.type = return_type; |
| 18078 | 18128 | return result; |
| 18079 | 18129 | } |
| ... | ... | @@ -18223,6 +18273,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 18223 | 18273 | Error err; |
| 18224 | 18274 | |
| 18225 | 18275 | ZigType *bare_type = container_ref_type(container_type); |
| 18276 | |
| 18226 | 18277 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 18227 | 18278 | return ira->codegen->invalid_instruction; |
| 18228 | 18279 | |
| ... | ... | @@ -20124,14 +20175,18 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20124 | 20175 | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20125 | 20176 | IrInstructionContainerInitList *instruction) |
| 20126 | 20177 | { |
| 20127 | | ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child); |
| 20128 | | if (type_is_invalid(container_type)) |
| 20129 | | return ira->codegen->invalid_instruction; |
| 20178 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20179 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20180 | if (type_is_invalid(result_loc->value.type)) |
| 20181 | return result_loc; |
| 20182 | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 20183 | |
| 20184 | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 20130 | 20185 | |
| 20131 | 20186 | size_t elem_count = instruction->item_count; |
| 20132 | 20187 | |
| 20133 | 20188 | if (is_slice(container_type)) { |
| 20134 | | ir_add_error(ira, instruction->container_type, |
| 20189 | ir_add_error_node(ira, instruction->init_array_type_source_node, |
| 20135 | 20190 | buf_sprintf("expected array type or [_], found slice")); |
| 20136 | 20191 | return ira->codegen->invalid_instruction; |
| 20137 | 20192 | } |
| ... | ... | @@ -20160,12 +20215,6 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20160 | 20215 | return ira->codegen->invalid_instruction; |
| 20161 | 20216 | } |
| 20162 | 20217 | |
| 20163 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20164 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 20165 | | if (type_is_invalid(result_loc->value.type)) |
| 20166 | | return result_loc; |
| 20167 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 20168 | | |
| 20169 | 20218 | ZigType *child_type = container_type->data.array.child_type; |
| 20170 | 20219 | if (container_type->data.array.len != elem_count) { |
| 20171 | 20220 | ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count); |
| ... | ... | @@ -20262,16 +20311,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20262 | 20311 | static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 20263 | 20312 | IrInstructionContainerInitFields *instruction) |
| 20264 | 20313 | { |
| 20265 | | IrInstruction *container_type_value = instruction->container_type->child; |
| 20266 | | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 20267 | | if (type_is_invalid(container_type)) |
| 20268 | | return ira->codegen->invalid_instruction; |
| 20269 | | |
| 20270 | 20314 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20271 | 20315 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20272 | 20316 | if (type_is_invalid(result_loc->value.type)) |
| 20273 | 20317 | return result_loc; |
| 20274 | 20318 | |
| 20319 | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 20320 | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 20321 | |
| 20275 | 20322 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 20276 | 20323 | instruction->field_count, instruction->fields, result_loc); |
| 20277 | 20324 | } |
| ... | ... | @@ -24607,6 +24654,10 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 24607 | 24654 | ZigType *src_type = ptr->value.type; |
| 24608 | 24655 | assert(!type_is_invalid(src_type)); |
| 24609 | 24656 | |
| 24657 | if (src_type == dest_type) { |
| 24658 | return ptr; |
| 24659 | } |
| 24660 | |
| 24610 | 24661 | // We have a check for zero bits later so we use get_src_ptr_type to |
| 24611 | 24662 | // validate src_type and dest_type. |
| 24612 | 24663 | |
| ... | ... | @@ -24656,6 +24707,9 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 24656 | 24707 | IrInstruction *result; |
| 24657 | 24708 | if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 24658 | 24709 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 24710 | |
| 24711 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 24712 | return ira->codegen->invalid_instruction; |
| 24659 | 24713 | } else { |
| 24660 | 24714 | result = ir_const(ira, source_instr, dest_type); |
| 24661 | 24715 | } |