mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-28 07:51:33 +00:00
Merge pull request #7361 from ssenthilnathan3/fix/recursive-soa-sigbus
Fix: SIGBUS/segfault when compiling recursive #soa slice/dynamic array types
This commit is contained in:
@@ -2617,6 +2617,22 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
return struct_type;
|
||||
}
|
||||
|
||||
bool is_soa_struct = type->Struct.soa_kind != StructSoa_None;
|
||||
LLVMTypeRef named_struct_type = nullptr;
|
||||
if (is_soa_struct) {
|
||||
// NOTE(bill): SOA structs are anonymous and may be recursive
|
||||
// (e.g. `#soa[]T` where `T` itself contains a field of type
|
||||
// `#soa[]T`). Register an opaque named struct up front so that any
|
||||
// recursive field references resolve to it instead of recursing
|
||||
// infinitely.
|
||||
gbString soa_name = temp_canonical_string(type);
|
||||
named_struct_type = LLVMGetTypeByName(m->mod, soa_name);
|
||||
if (named_struct_type == nullptr) {
|
||||
named_struct_type = LLVMStructCreateNamed(ctx, soa_name);
|
||||
}
|
||||
map_set(&m->types, type, named_struct_type);
|
||||
}
|
||||
|
||||
lbStructFieldRemapping field_remapping = {};
|
||||
slice_init(&field_remapping, permanent_allocator(), type->Struct.fields.count);
|
||||
|
||||
@@ -2669,7 +2685,13 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
|
||||
GB_ASSERT(fields[i] != nullptr);
|
||||
}
|
||||
|
||||
LLVMTypeRef struct_type = LLVMStructTypeInContext(ctx, fields.data, cast(unsigned)fields.count, requires_packing);
|
||||
LLVMTypeRef struct_type = nullptr;
|
||||
if (is_soa_struct) {
|
||||
struct_type = named_struct_type;
|
||||
LLVMStructSetBody(struct_type, fields.data, cast(unsigned)fields.count, requires_packing);
|
||||
} else {
|
||||
struct_type = LLVMStructTypeInContext(ctx, fields.data, cast(unsigned)fields.count, requires_packing);
|
||||
}
|
||||
map_set(&m->struct_field_remapping, cast(void *)struct_type, field_remapping);
|
||||
map_set(&m->struct_field_remapping, cast(void *)type, field_remapping);
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user