| ... | @@ -20642,12 +20642,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20642,12 +20642,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20642 | if (type_is_invalid(array_ptr->value->type)) | 20642 | if (type_is_invalid(array_ptr->value->type)) |
| 20643 | return ira->codegen->invalid_inst_gen; | 20643 | return ira->codegen->invalid_inst_gen; |
| 20644 | | 20644 | |
| 20645 | ZigValue *orig_array_ptr_val = array_ptr->value; | | |
| 20646 | | | |
| 20647 | IrInstGen *elem_index = elem_ptr_instruction->elem_index->child; | 20645 | IrInstGen *elem_index = elem_ptr_instruction->elem_index->child; |
| 20648 | if (type_is_invalid(elem_index->value->type)) | 20646 | if (type_is_invalid(elem_index->value->type)) |
| 20649 | return ira->codegen->invalid_inst_gen; | 20647 | return ira->codegen->invalid_inst_gen; |
| 20650 | | 20648 | |
| | 20649 | ZigValue *orig_array_ptr_val = array_ptr->value; |
| | 20650 | |
| 20651 | ZigType *ptr_type = orig_array_ptr_val->type; | 20651 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 20652 | assert(ptr_type->id == ZigTypeIdPointer); | 20652 | assert(ptr_type->id == ZigTypeIdPointer); |
| 20653 | | 20653 | |
| ... | @@ -20657,23 +20657,25 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20657,23 +20657,25 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20657 | // We will adjust return_type's alignment before returning it. | 20657 | // We will adjust return_type's alignment before returning it. |
| 20658 | ZigType *return_type; | 20658 | ZigType *return_type; |
| 20659 | | 20659 | |
| 20660 | if (type_is_invalid(array_type)) { | 20660 | if (type_is_invalid(array_type)) |
| 20661 | return ira->codegen->invalid_inst_gen; | 20661 | return ira->codegen->invalid_inst_gen; |
| 20662 | } else if (array_type->id == ZigTypeIdArray || | 20662 | |
| 20663 | (array_type->id == ZigTypeIdPointer && | 20663 | if (array_type->id == ZigTypeIdPointer && |
| 20664 | array_type->data.pointer.ptr_len == PtrLenSingle && | 20664 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| 20665 | array_type->data.pointer.child_type->id == ZigTypeIdArray)) | 20665 | array_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 20666 | { | 20666 | { |
| 20667 | if (array_type->id == ZigTypeIdPointer) { | 20667 | IrInstGen *ptr_value = ir_get_deref(ira, &elem_ptr_instruction->base.base, |
| 20668 | array_type = array_type->data.pointer.child_type; | 20668 | array_ptr, nullptr); |
| 20669 | ptr_type = ptr_type->data.pointer.child_type; | 20669 | if (type_is_invalid(ptr_value->value->type)) |
| 20670 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { | 20670 | return ira->codegen->invalid_inst_gen; |
| 20671 | orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, | 20671 | |
| 20672 | elem_ptr_instruction->base.base.source_node); | 20672 | array_type = array_type->data.pointer.child_type; |
| 20673 | if (orig_array_ptr_val == nullptr) | 20673 | ptr_type = ptr_type->data.pointer.child_type; |
| 20674 | return ira->codegen->invalid_inst_gen; | 20674 | |
| 20675 | } | 20675 | orig_array_ptr_val = ptr_value->value; |
| 20676 | } | 20676 | } |
| | 20677 | |
| | 20678 | if (array_type->id == ZigTypeIdArray) { |
| 20677 | if (array_type->data.array.len == 0) { | 20679 | if (array_type->data.array.len == 0) { |
| 20678 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, | 20680 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 20679 | buf_sprintf("index 0 outside array of size 0")); | 20681 | buf_sprintf("index 0 outside array of size 0")); |
| ... | @@ -20811,8 +20813,14 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP | ... | @@ -20811,8 +20813,14 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20811 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && | 20813 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 20812 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) | 20814 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) |
| 20813 | { | 20815 | { |
| | 20816 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| | 20817 | elem_ptr_instruction->base.base.source_node, orig_array_ptr_val, UndefBad))) |
| | 20818 | { |
| | 20819 | return ira->codegen->invalid_inst_gen; |
| | 20820 | } |
| | 20821 | |
| 20814 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, | 20822 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 20815 | elem_ptr_instruction->base.base.source_node); | 20823 | elem_ptr_instruction->base.base.source_node); |
| 20816 | if (array_ptr_val == nullptr) | 20824 | if (array_ptr_val == nullptr) |
| 20817 | return ira->codegen->invalid_inst_gen; | 20825 | return ira->codegen->invalid_inst_gen; |
| 20818 | | 20826 | |
| ... | @@ -23674,14 +23682,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa | ... | @@ -23674,14 +23682,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa |
| 23674 | if ((err = type_resolve(ira->codegen, type_info_fn_decl_inline_type, ResolveStatusSizeKnown))) | 23682 | if ((err = type_resolve(ira->codegen, type_info_fn_decl_inline_type, ResolveStatusSizeKnown))) |
| 23675 | return err; | 23683 | return err; |
| 23676 | | 23684 | |
| 23677 | // Loop through our declarations once to figure out how many declarations we will generate info for. | 23685 | // The unresolved declarations are collected in a separate queue to avoid |
| | 23686 | // modifying decl_table while iterating over it |
| | 23687 | ZigList<Tld*> resolve_decl_queue{}; |
| | 23688 | |
| 23678 | auto decl_it = decls_scope->decl_table.entry_iterator(); | 23689 | auto decl_it = decls_scope->decl_table.entry_iterator(); |
| 23679 | decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr; | 23690 | decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr; |
| 23680 | int declaration_count = 0; | | |
| 23681 | | | |
| 23682 | while ((curr_entry = decl_it.next()) != nullptr) { | 23691 | while ((curr_entry = decl_it.next()) != nullptr) { |
| 23683 | // If the declaration is unresolved, force it to be resolved again. | | |
| 23684 | resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false); | | |
| 23685 | if (curr_entry->value->resolution == TldResolutionInvalid) { | 23692 | if (curr_entry->value->resolution == TldResolutionInvalid) { |
| 23686 | return ErrorSemanticAnalyzeFail; | 23693 | return ErrorSemanticAnalyzeFail; |
| 23687 | } | 23694 | } |
| ... | @@ -23691,16 +23698,36 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa | ... | @@ -23691,16 +23698,36 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa |
| 23691 | return ErrorSemanticAnalyzeFail; | 23698 | return ErrorSemanticAnalyzeFail; |
| 23692 | } | 23699 | } |
| 23693 | | 23700 | |
| | 23701 | // If the declaration is unresolved, force it to be resolved again. |
| | 23702 | if (curr_entry->value->resolution == TldResolutionUnresolved) |
| | 23703 | resolve_decl_queue.append(curr_entry->value); |
| | 23704 | } |
| | 23705 | |
| | 23706 | for (size_t i = 0; i < resolve_decl_queue.length; i++) { |
| | 23707 | Tld *decl = resolve_decl_queue.at(i); |
| | 23708 | resolve_top_level_decl(ira->codegen, decl, decl->source_node, false); |
| | 23709 | if (decl->resolution == TldResolutionInvalid) { |
| | 23710 | return ErrorSemanticAnalyzeFail; |
| | 23711 | } |
| | 23712 | } |
| | 23713 | |
| | 23714 | resolve_decl_queue.deinit(); |
| | 23715 | |
| | 23716 | // Loop through our declarations once to figure out how many declarations we will generate info for. |
| | 23717 | int declaration_count = 0; |
| | 23718 | decl_it = decls_scope->decl_table.entry_iterator(); |
| | 23719 | while ((curr_entry = decl_it.next()) != nullptr) { |
| 23694 | // Skip comptime blocks and test functions. | 23720 | // Skip comptime blocks and test functions. |
| 23695 | if (curr_entry->value->id != TldIdCompTime) { | 23721 | if (curr_entry->value->id == TldIdCompTime) |
| 23696 | if (curr_entry->value->id == TldIdFn) { | 23722 | continue; |
| 23697 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; | | |
| 23698 | if (fn_entry->is_test) | | |
| 23699 | continue; | | |
| 23700 | } | | |
| 23701 | | 23723 | |
| 23702 | declaration_count += 1; | 23724 | if (curr_entry->value->id == TldIdFn) { |
| | 23725 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| | 23726 | if (fn_entry->is_test) |
| | 23727 | continue; |
| 23703 | } | 23728 | } |
| | 23729 | |
| | 23730 | declaration_count += 1; |
| 23704 | } | 23731 | } |
| 23705 | | 23732 | |
| 23706 | ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>(); | 23733 | ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>(); |