authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-13 16:24:13-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-13 16:24:13-05:00
log83f1a6fae24b9fa74ced6f8022f38be08d27a0c0
tree454eced69e81f4d9ae95d3c82db88b8ed0f10c62
parent652bfab3d0c554e1479563a6fe007d527ee0f5cb

fix some bugs with structs


1 files changed, 25 insertions(+), 4 deletions(-)

src/analyze.cpp+25-4
......@@ -520,6 +520,8 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
520520 TypeTableEntry *entry = existing_entry->value;
521521 return entry;
522522 } else {
523 ensure_complete_type(g, child_type);
524
523525 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArray);
524526 entry->zero_bits = (array_size == 0) || child_type->zero_bits;
525527
......@@ -1080,6 +1082,23 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
10801082 return get_fn_type(g, &fn_type_id);
10811083}
10821084
1085static bool type_is_invalid(TypeTableEntry *type_entry) {
1086 switch (type_entry->id) {
1087 case TypeTableEntryIdInvalid:
1088 return true;
1089 case TypeTableEntryIdStruct:
1090 return type_entry->data.structure.is_invalid;
1091 case TypeTableEntryIdEnum:
1092 return type_entry->data.enumeration.is_invalid;
1093 case TypeTableEntryIdUnion:
1094 return type_entry->data.unionation.is_invalid;
1095 default:
1096 return false;
1097 }
1098 zig_unreachable();
1099}
1100
1101
10831102static TypeTableEntry *create_enum_tag_type(CodeGen *g, TypeTableEntry *enum_type, TypeTableEntry *int_type) {
10841103 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdEnumTag);
10851104
......@@ -1296,7 +1315,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
12961315 }
12971316
12981317 assert(!struct_type->data.structure.zero_bits_loop_flag);
1299 assert(struct_type->data.enumeration.fields);
1318 assert(struct_type->data.structure.fields);
13001319 assert(decl_node->type == NodeTypeContainerDecl);
13011320
13021321 size_t field_count = struct_type->data.structure.src_field_count;
......@@ -1309,13 +1328,14 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
13091328
13101329 Scope *scope = &struct_type->data.structure.decls_scope->base;
13111330
1331 //if (buf_eql_str(&struct_type->name, "Particle")) { BREAKPOINT; }
13121332 for (size_t i = 0; i < field_count; i += 1) {
13131333 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
13141334 TypeTableEntry *field_type = type_struct_field->type_entry;
13151335
13161336 ensure_complete_type(g, field_type);
1317 if (field_type->id == TypeTableEntryIdInvalid) {
1318 struct_type->data.enumeration.is_invalid = true;
1337 if (type_is_invalid(field_type)) {
1338 struct_type->data.structure.is_invalid = true;
13191339 continue;
13201340 }
13211341
......@@ -1342,6 +1362,7 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
13421362 assert(struct_type->di_type);
13431363
13441364 LLVMStructSetBody(struct_type->type_ref, element_types, gen_field_count, false);
1365 assert(LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref) > 0);
13451366
13461367 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(gen_field_count);
13471368
......@@ -1492,7 +1513,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
14921513 type_struct_field->gen_index = SIZE_MAX;
14931514
14941515 type_ensure_zero_bits_known(g, field_type);
1495 if (field_type->id == TypeTableEntryIdInvalid) {
1516 if (type_is_invalid(field_type)) {
14961517 struct_type->data.structure.is_invalid = true;
14971518 continue;
14981519 }