authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 13:25:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 13:25:55-07:00
log8d510c699afe2b508482f2c106ef4b4524a5861b
treee3f9cbfc13902c2c671cf4ff9bea4a426913050b
parentc8376af92d63d13574cae7d177b7d314dda44cfe

parseh: fix branching on undefined memory


2 files changed, 18 insertions(+), 9 deletions(-)

src/analyze.cpp+1-1
...@@ -749,7 +749,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor...@@ -749,7 +749,7 @@ static TypeTableEntry *analyze_fn_proto_type(CodeGen *g, ImportTableEntry *impor
749 return g->builtin_types.entry_invalid;749 return g->builtin_types.entry_invalid;
750 }750 }
751751
752 FnTypeId fn_type_id;752 FnTypeId fn_type_id = {0};
753 fn_type_id.is_extern = fn_proto->is_extern || (fn_proto->visib_mod == VisibModExport);753 fn_type_id.is_extern = fn_proto->is_extern || (fn_proto->visib_mod == VisibModExport);
754 fn_type_id.is_naked = is_naked;754 fn_type_id.is_naked = is_naked;
755 fn_type_id.is_cold = is_cold;755 fn_type_id.is_cold = is_cold;
src/parseh.cpp+17-8
...@@ -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 }
488488
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_
908908
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);
916913
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 }
936934
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);
947960
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]);
951962
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;
957968
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,