| ... | @@ -486,7 +486,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const | ... | @@ -486,7 +486,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const |
| 486 | return c->codegen->builtin_types.entry_invalid; | 486 | return c->codegen->builtin_types.entry_invalid; |
| 487 | } | 487 | } |
| 488 | | 488 | |
| 489 | FnTypeId fn_type_id; | 489 | FnTypeId fn_type_id = {0}; |
| 490 | fn_type_id.is_naked = false; | 490 | fn_type_id.is_naked = false; |
| 491 | fn_type_id.is_extern = true; | 491 | fn_type_id.is_extern = true; |
| 492 | fn_type_id.is_var_args = fn_proto_ty->isVariadic(); | 492 | fn_type_id.is_var_args = fn_proto_ty->isVariadic(); |
| ... | @@ -908,12 +908,10 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ | ... | @@ -908,12 +908,10 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 908 | | 908 | |
| 909 | struct_type->data.structure.src_field_count = field_count; | 909 | struct_type->data.structure.src_field_count = field_count; |
| 910 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); | 910 | struct_type->data.structure.fields = allocate<TypeStructField>(field_count); |
| 911 | | | |
| 912 | // we possibly allocate too much here since gen_field_count can be lower than field_count. | | |
| 913 | // the only problem is potential wasted space though. | | |
| 914 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count); | 911 | LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count); |
| 915 | LLVMZigDIType **di_element_types = allocate<LLVMZigDIType*>(field_count); | 912 | LLVMZigDIType **di_element_types = allocate<LLVMZigDIType*>(field_count); |
| 916 | | 913 | |
| | 914 | // next, populate element_types as its needed for LLVMStructSetBody which is needed for LLVMOffsetOfElement |
| 917 | uint32_t i = 0; | 915 | uint32_t i = 0; |
| 918 | for (auto it = record_def->field_begin(), | 916 | for (auto it = record_def->field_begin(), |
| 919 | it_end = record_def->field_end(); | 917 | it_end = record_def->field_end(); |
| ... | @@ -934,6 +932,21 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ | ... | @@ -934,6 +932,21 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 934 | return struct_type; | 932 | return struct_type; |
| 935 | } | 933 | } |
| 936 | | 934 | |
| | 935 | element_types[i] = field_type->type_ref; |
| | 936 | assert(element_types[i]); |
| | 937 | } |
| | 938 | |
| | 939 | LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false); |
| | 940 | |
| | 941 | // finally populate debug info |
| | 942 | i = 0; |
| | 943 | for (auto it = record_def->field_begin(), |
| | 944 | it_end = record_def->field_end(); |
| | 945 | it != it_end; ++it, i += 1) |
| | 946 | { |
| | 947 | TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; |
| | 948 | TypeTableEntry *field_type = type_struct_field->type_entry; |
| | 949 | |
| 937 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(c->codegen->target_data_ref, field_type->type_ref); | 950 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(c->codegen->target_data_ref, field_type->type_ref); |
| 938 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(c->codegen->target_data_ref, field_type->type_ref); | 951 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(c->codegen->target_data_ref, field_type->type_ref); |
| 939 | uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(c->codegen->target_data_ref, struct_type->type_ref, i); | 952 | uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(c->codegen->target_data_ref, struct_type->type_ref, i); |
| ... | @@ -945,9 +958,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ | ... | @@ -945,9 +958,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 945 | debug_offset_in_bits, | 958 | debug_offset_in_bits, |
| 946 | 0, field_type->di_type); | 959 | 0, field_type->di_type); |
| 947 | | 960 | |
| 948 | element_types[i] = field_type->type_ref; | | |
| 949 | assert(di_element_types[i]); | 961 | assert(di_element_types[i]); |
| 950 | assert(element_types[i]); | | |
| 951 | | 962 | |
| 952 | } | 963 | } |
| 953 | struct_type->data.structure.embedded_in_current = false; | 964 | struct_type->data.structure.embedded_in_current = false; |
| ... | @@ -955,8 +966,6 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ | ... | @@ -955,8 +966,6 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_ |
| 955 | struct_type->data.structure.gen_field_count = field_count; | 966 | struct_type->data.structure.gen_field_count = field_count; |
| 956 | struct_type->data.structure.complete = true; | 967 | struct_type->data.structure.complete = true; |
| 957 | | 968 | |
| 958 | LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false); | | |
| 959 | | | |
| 960 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(c->codegen->target_data_ref, struct_type->type_ref); | 969 | uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(c->codegen->target_data_ref, struct_type->type_ref); |
| 961 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(c->codegen->target_data_ref, struct_type->type_ref); | 970 | uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(c->codegen->target_data_ref, struct_type->type_ref); |
| 962 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(c->codegen->dbuilder, | 971 | LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(c->codegen->dbuilder, |