| ... | ... | @@ -273,12 +273,19 @@ static void preview_function_labels(CodeGen *g, AstNode *node, FnTableEntry *fn_ |
| 273 | 273 | static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableEntry *struct_type) { |
| 274 | 274 | assert(struct_type->id == TypeTableEntryIdStruct); |
| 275 | 275 | |
| 276 | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 277 | |
| 278 | if (struct_type->data.structure.embedded_in_current) { |
| 279 | add_node_error(g, decl_node, |
| 280 | buf_sprintf("struct has infinite size")); |
| 281 | return; |
| 282 | } |
| 283 | |
| 276 | 284 | if (struct_type->data.structure.fields) { |
| 277 | 285 | // we already resolved this type. skip |
| 278 | 286 | return; |
| 279 | 287 | } |
| 280 | 288 | |
| 281 | | AstNode *decl_node = struct_type->data.structure.decl_node; |
| 282 | 289 | |
| 283 | 290 | assert(struct_type->di_type); |
| 284 | 291 | |
| ... | ... | @@ -293,6 +300,9 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE |
| 293 | 300 | uint64_t first_field_align_in_bits = 0; |
| 294 | 301 | uint64_t offset_in_bits = 0; |
| 295 | 302 | |
| 303 | // this field should be set to true only during the recursive calls to resolve_struct_type |
| 304 | struct_type->data.structure.embedded_in_current = true; |
| 305 | |
| 296 | 306 | for (int i = 0; i < field_count; i += 1) { |
| 297 | 307 | AstNode *field_node = decl_node->data.struct_decl.fields.at(i); |
| 298 | 308 | TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; |
| ... | ... | @@ -321,6 +331,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE |
| 321 | 331 | offset_in_bits += type_struct_field->type_entry->size_in_bits; |
| 322 | 332 | |
| 323 | 333 | } |
| 334 | struct_type->data.structure.embedded_in_current = false; |
| 324 | 335 | |
| 325 | 336 | LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false); |
| 326 | 337 | |