aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index de71673c49..35e94cd8e4 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -273,12 +273,19 @@ static void preview_function_labels(CodeGen *g, AstNode *node, FnTableEntry *fn_
static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableEntry *struct_type) {
assert(struct_type->id == TypeTableEntryIdStruct);
+ AstNode *decl_node = struct_type->data.structure.decl_node;
+
+ if (struct_type->data.structure.embedded_in_current) {
+ add_node_error(g, decl_node,
+ buf_sprintf("struct has infinite size"));
+ return;
+ }
+
if (struct_type->data.structure.fields) {
// we already resolved this type. skip
return;
}
- AstNode *decl_node = struct_type->data.structure.decl_node;
assert(struct_type->di_type);
@@ -293,6 +300,9 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
uint64_t first_field_align_in_bits = 0;
uint64_t offset_in_bits = 0;
+ // this field should be set to true only during the recursive calls to resolve_struct_type
+ struct_type->data.structure.embedded_in_current = true;
+
for (int i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.struct_decl.fields.at(i);
TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
@@ -321,6 +331,7 @@ static void resolve_struct_type(CodeGen *g, ImportTableEntry *import, TypeTableE
offset_in_bits += type_struct_field->type_entry->size_in_bits;
}
+ struct_type->data.structure.embedded_in_current = false;
LLVMStructSetBody(struct_type->type_ref, element_types, field_count, false);