| ... | @@ -464,9 +464,8 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) | ... | @@ -464,9 +464,8 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) |
| 464 | TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false); | 464 | TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false); |
| 465 | const char *field_names[] = {AWAITER_HANDLE_FIELD_NAME, RESULT_FIELD_NAME, RESULT_PTR_FIELD_NAME}; | 465 | const char *field_names[] = {AWAITER_HANDLE_FIELD_NAME, RESULT_FIELD_NAME, RESULT_PTR_FIELD_NAME}; |
| 466 | TypeTableEntry *field_types[] = {awaiter_handle_type, return_type, result_ptr_type}; | 466 | TypeTableEntry *field_types[] = {awaiter_handle_type, return_type, result_ptr_type}; |
| 467 | size_t field_count = type_has_bits(result_ptr_type) ? 3 : 1; | | |
| 468 | Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name)); | 467 | Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name)); |
| 469 | TypeTableEntry *entry = get_struct_type(g, buf_ptr(name), field_names, field_types, field_count); | 468 | TypeTableEntry *entry = get_struct_type(g, buf_ptr(name), field_names, field_types, 3); |
| 470 | | 469 | |
| 471 | return_type->promise_frame_parent = entry; | 470 | return_type->promise_frame_parent = entry; |
| 472 | return entry; | 471 | return entry; |
| ... | @@ -1715,7 +1714,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f | ... | @@ -1715,7 +1714,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f |
| 1715 | buf_init_from_str(&struct_type->name, type_name); | 1714 | buf_init_from_str(&struct_type->name, type_name); |
| 1716 | | 1715 | |
| 1717 | struct_type->data.structure.src_field_count = field_count; | 1716 | struct_type->data.structure.src_field_count = field_count; |
| 1718 | struct_type->data.structure.gen_field_count = field_count; | 1717 | struct_type->data.structure.gen_field_count = 0; |
| 1719 | struct_type->data.structure.zero_bits_known = true; | 1718 | struct_type->data.structure.zero_bits_known = true; |
| 1720 | struct_type->data.structure.complete = true; | 1719 | struct_type->data.structure.complete = true; |
| 1721 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); | 1720 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); |
| ... | @@ -1724,22 +1723,26 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f | ... | @@ -1724,22 +1723,26 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f |
| 1724 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(field_count); | 1723 | ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(field_count); |
| 1725 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count); | 1724 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count); |
| 1726 | for (size_t i = 0; i < field_count; i += 1) { | 1725 | for (size_t i = 0; i < field_count; i += 1) { |
| 1727 | element_types[i] = field_types[i]->type_ref; | 1726 | element_types[struct_type->data.structure.gen_field_count] = field_types[i]->type_ref; |
| 1728 | | 1727 | |
| 1729 | TypeStructField *field = &struct_type->data.structure.fields[i]; | 1728 | TypeStructField *field = &struct_type->data.structure.fields[i]; |
| 1730 | field->name = buf_create_from_str(field_names[i]); | 1729 | field->name = buf_create_from_str(field_names[i]); |
| 1731 | field->type_entry = field_types[i]; | 1730 | field->type_entry = field_types[i]; |
| 1732 | field->src_index = i; | 1731 | field->src_index = i; |
| 1733 | field->gen_index = i; | | |
| 1734 | | 1732 | |
| 1735 | assert(type_has_bits(field->type_entry)); | 1733 | if (type_has_bits(field->type_entry)) { |
| | 1734 | field->gen_index = struct_type->data.structure.gen_field_count; |
| | 1735 | struct_type->data.structure.gen_field_count += 1; |
| | 1736 | } else { |
| | 1737 | field->gen_index = SIZE_MAX; |
| | 1738 | } |
| 1736 | | 1739 | |
| 1737 | auto prev_entry = struct_type->data.structure.fields_by_name.put_unique(field->name, field); | 1740 | auto prev_entry = struct_type->data.structure.fields_by_name.put_unique(field->name, field); |
| 1738 | assert(prev_entry == nullptr); | 1741 | assert(prev_entry == nullptr); |
| 1739 | } | 1742 | } |
| 1740 | | 1743 | |
| 1741 | struct_type->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), type_name); | 1744 | struct_type->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), type_name); |
| 1742 | LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false); | 1745 | LLVMStructSetBody(struct_type->type_ref, element_types, struct_type->data.structure.gen_field_count, false); |
| 1743 | | 1746 | |
| 1744 | struct_type->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, | 1747 | struct_type->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder, |
| 1745 | ZigLLVMTag_DW_structure_type(), type_name, | 1748 | ZigLLVMTag_DW_structure_type(), type_name, |
| ... | @@ -1747,11 +1750,14 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f | ... | @@ -1747,11 +1750,14 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f |
| 1747 | | 1750 | |
| 1748 | for (size_t i = 0; i < field_count; i += 1) { | 1751 | for (size_t i = 0; i < field_count; i += 1) { |
| 1749 | TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; | 1752 | TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; |
| | 1753 | if (type_struct_field->gen_index == SIZE_MAX) { |
| | 1754 | continue; |
| | 1755 | } |
| 1750 | TypeTableEntry *field_type = type_struct_field->type_entry; | 1756 | TypeTableEntry *field_type = type_struct_field->type_entry; |
| 1751 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref); | 1757 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref); |
| 1752 | uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref); | 1758 | uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref); |
| 1753 | uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, i); | 1759 | uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, type_struct_field->gen_index); |
| 1754 | di_element_types[i] = ZigLLVMCreateDebugMemberType(g->dbuilder, | 1760 | di_element_types[type_struct_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 1755 | ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name), | 1761 | ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name), |
| 1756 | nullptr, 0, | 1762 | nullptr, 0, |
| 1757 | debug_size_in_bits, | 1763 | debug_size_in_bits, |
| ... | @@ -1759,7 +1765,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f | ... | @@ -1759,7 +1765,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f |
| 1759 | debug_offset_in_bits, | 1765 | debug_offset_in_bits, |
| 1760 | 0, field_type->di_type); | 1766 | 0, field_type->di_type); |
| 1761 | | 1767 | |
| 1762 | assert(di_element_types[i]); | 1768 | assert(di_element_types[type_struct_field->gen_index]); |
| 1763 | } | 1769 | } |
| 1764 | | 1770 | |
| 1765 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref); | 1771 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref); |
| ... | @@ -1770,7 +1776,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f | ... | @@ -1770,7 +1776,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f |
| 1770 | debug_size_in_bits, | 1776 | debug_size_in_bits, |
| 1771 | debug_align_in_bits, | 1777 | debug_align_in_bits, |
| 1772 | 0, | 1778 | 0, |
| 1773 | nullptr, di_element_types, field_count, 0, nullptr, ""); | 1779 | nullptr, di_element_types, struct_type->data.structure.gen_field_count, 0, nullptr, ""); |
| 1774 | | 1780 | |
| 1775 | ZigLLVMReplaceTemporary(g->dbuilder, struct_type->di_type, replacement_di_type); | 1781 | ZigLLVMReplaceTemporary(g->dbuilder, struct_type->di_type, replacement_di_type); |
| 1776 | struct_type->di_type = replacement_di_type; | 1782 | struct_type->di_type = replacement_di_type; |