aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-04 21:42:35 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-04 21:42:35 -0700
commite1ff201d60e6eb28c7e5ca5110b27b1e35194b82 (patch)
treedba0a9619d78374a0b0c90bc0f4c20ca7a07ad0e /src
parente0aa0736be47e5e1383d8fb25f744f95c5a830ba (diff)
downloadzig-e1ff201d60e6eb28c7e5ca5110b27b1e35194b82.tar.gz
zig-e1ff201d60e6eb28c7e5ca5110b27b1e35194b82.zip
fix crash when struct field is invalid
Diffstat (limited to 'src')
-rw-r--r--src/analyze.cpp26
-rw-r--r--src/analyze.hpp1
2 files changed, 17 insertions, 10 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index dcc2fcf42f..ada3cf4323 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -429,6 +429,9 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
if (type_struct_field->type_entry->id == TypeTableEntryIdStruct) {
resolve_struct_type(g, import, type_struct_field->type_entry);
+ } else if (type_struct_field->type_entry->id == TypeTableEntryIdInvalid) {
+ struct_type->data.structure.is_invalid = true;
+ continue;
}
di_element_types[i] = LLVMZigCreateDebugMemberType(g->dbuilder,
@@ -451,19 +454,22 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
}
struct_type->data.structure.embedded_in_current = false;
- LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false);
+ if (!struct_type->data.structure.is_invalid) {
+
+ LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false);
- struct_type->align_in_bits = first_field_align_in_bits;
- struct_type->size_in_bits = total_size_in_bits;
+ struct_type->align_in_bits = first_field_align_in_bits;
+ struct_type->size_in_bits = total_size_in_bits;
- LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder,
- LLVMZigFileToScope(import->di_file),
- buf_ptr(&decl_node->data.struct_decl.name),
- import->di_file, decl_node->line + 1, struct_type->size_in_bits, struct_type->align_in_bits, 0,
- nullptr, di_element_types, field_count, 0, nullptr, "");
+ LLVMZigDIType *replacement_di_type = LLVMZigCreateDebugStructType(g->dbuilder,
+ LLVMZigFileToScope(import->di_file),
+ buf_ptr(&decl_node->data.struct_decl.name),
+ import->di_file, decl_node->line + 1, struct_type->size_in_bits, struct_type->align_in_bits, 0,
+ nullptr, di_element_types, field_count, 0, nullptr, "");
- LLVMZigReplaceTemporary(g->dbuilder, struct_type->di_type, replacement_di_type);
- struct_type->di_type = replacement_di_type;
+ LLVMZigReplaceTemporary(g->dbuilder, struct_type->di_type, replacement_di_type);
+ struct_type->di_type = replacement_di_type;
+ }
}
static void preview_fn_def(CodeGen *g, ImportTableEntry *import, AstNode *node, TypeTableEntry *struct_type) {
diff --git a/src/analyze.hpp b/src/analyze.hpp
index a578a0f4e3..dcb85c94a1 100644
--- a/src/analyze.hpp
+++ b/src/analyze.hpp
@@ -45,6 +45,7 @@ struct TypeTableEntryStruct {
int field_count;
TypeStructField *fields;
uint64_t size_bytes;
+ bool is_invalid; // true if any fields are invalid
// reminder: hash tables must be initialized before use
HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;