Merge pull request #5886 from laytan/32bit-typeid-fixes

fixes for 32bit with regards to typeid
This commit is contained in:
gingerBill
2025-11-04 20:56:49 +00:00
committed by GitHub
6 changed files with 25 additions and 31 deletions

View File

@@ -185,8 +185,7 @@ gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValue
}
Type *bt = base_type(t);
GB_ASSERT(bt->kind == Type_Struct || bt->kind == Type_Union);
GB_ASSERT(value_count_ == bt->Struct.fields.count);
GB_ASSERT(bt->kind != Type_Struct || value_count_ == bt->Struct.fields.count);
auto field_remapping = lb_get_struct_remapping(m, t);
unsigned values_with_padding_count = elem_count;
@@ -513,7 +512,7 @@ gb_internal LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, Bi
max_count = mp_pack_count(a, nails, size);
if (sz < max_count) {
debug_print_big_int(a);
gb_printf_err("%s -> %tu\n", type_to_string(original_type), sz);;
gb_printf_err("%s -> %tu\n", type_to_string(original_type), sz);
}
GB_ASSERT_MSG(sz >= max_count, "max_count: %tu, sz: %tu, written: %tu, type %s", max_count, sz, written, type_to_string(original_type));
GB_ASSERT(gb_size_of(rop64) >= sz);

View File

@@ -704,7 +704,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Basic_uintptr: return lb_debug_type_basic_type(m, str_lit("uintptr"), ptr_bits, LLVMDWARFTypeEncoding_Unsigned);
case Basic_typeid:
return lb_debug_type_basic_type(m, str_lit("typeid"), ptr_bits, LLVMDWARFTypeEncoding_Unsigned);
return lb_debug_type_basic_type(m, str_lit("typeid"), 64, LLVMDWARFTypeEncoding_Unsigned);
// Endian Specific Types
case Basic_i16le: return lb_debug_type_basic_type(m, str_lit("i16le"), 16, LLVMDWARFTypeEncoding_Signed, LLVMDIFlagLittleEndian);
@@ -820,8 +820,8 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
{
LLVMMetadataRef elements[2] = {};
elements[0] = lb_debug_struct_field(m, str_lit("data"), t_rawptr, 0);
elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, ptr_bits);
return lb_debug_basic_struct(m, str_lit("any"), 2*ptr_bits, ptr_bits, elements, gb_count_of(elements));
elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, 64);
return lb_debug_basic_struct(m, str_lit("any"), 128, 64, elements, gb_count_of(elements));
}
// Untyped types

View File

@@ -2178,11 +2178,14 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) {
LLVMSetLinkage(var_global_ref, LLVMInternalLinkage);
}
LLVMValueRef vals[2] = {
lb_emit_conv(p, var_global.addr, t_rawptr).value,
lb_typeid(p->module, var_type).value,
};
LLVMValueRef init = llvm_const_named_struct(p->module, e->type, vals, gb_count_of(vals));
auto vals = array_make<LLVMValueRef>(temporary_allocator(), 0, 3);
array_add(&vals, lb_emit_conv(p, var_global.addr, t_rawptr).value);
if (build_context.metrics.ptr_size == 4) {
array_add(&vals, LLVMConstNull(lb_type_padding_filler(p->module, 4, 4)));
}
array_add(&vals, lb_typeid(p->module, var_type).value);
LLVMValueRef init = llvm_const_named_struct(p->module, e->type, vals.data, vals.count);
LLVMSetInitializer(global, init);
} else {
LLVMSetInitializer(global, value.value);

View File

@@ -181,15 +181,9 @@ gb_internal LLVMTypeRef *lb_setup_modified_types_for_type_info(lbModule *m, isiz
stypes[0] = lb_type(m, tibt->Struct.fields[0]->type);
stypes[1] = lb_type(m, tibt->Struct.fields[1]->type);
stypes[2] = lb_type(m, tibt->Struct.fields[2]->type);
isize variant_index = 0;
if (build_context.ptr_size == 8) {
stypes[3] = lb_type(m, t_i32); // padding
stypes[4] = lb_type(m, tibt->Struct.fields[3]->type);
variant_index = 5;
} else {
stypes[3] = lb_type(m, tibt->Struct.fields[3]->type);
variant_index = 4;
}
stypes[3] = lb_type(m, t_i32); // padding
stypes[4] = lb_type(m, tibt->Struct.fields[3]->type);
isize variant_index = 5;
LLVMTypeRef *modified_types = gb_alloc_array(heap_allocator(), LLVMTypeRef, Typeid__COUNT);
GB_ASSERT(Typeid__COUNT == ut->Union.variants.count);
@@ -360,16 +354,9 @@ gb_internal void lb_setup_type_info_data_giant_array(lbModule *m, i64 global_typ
small_const_values[0] = LLVMConstInt(lb_type(m, t_int), size, true);
small_const_values[1] = LLVMConstInt(lb_type(m, t_int), align, true);
small_const_values[2] = type_info_flags.value;
unsigned variant_index = 0;
if (build_context.ptr_size == 8) {
small_const_values[3] = LLVMConstNull(LLVMStructGetTypeAtIndex(stype, 3));
small_const_values[4] = id.value;
variant_index = 5;
} else {
small_const_values[3] = id.value;
variant_index = 4;
}
small_const_values[3] = LLVMConstNull(LLVMStructGetTypeAtIndex(stype, 3));
small_const_values[4] = id.value;
unsigned variant_index = 5;
LLVMTypeRef full_variant_type = LLVMStructGetTypeAtIndex(stype, variant_index);
unsigned full_variant_elem_count = LLVMCountStructElementTypes(full_variant_type);

View File

@@ -1005,6 +1005,7 @@ gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
switch (index) {
case 0: return 0; // data
case 1: return 2; // id
default: GB_PANIC("index > 1");
}
} else if (build_context.ptr_size != build_context.int_size) {
switch (t->kind) {
@@ -1203,6 +1204,7 @@ gb_internal lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
switch (index) {
case 0: result_type = t_rawptr; break;
case 1: result_type = t_typeid; break;
default: GB_PANIC("index > 1");
}
} else if (is_type_dynamic_array(t)) {
switch (index) {

View File

@@ -4577,6 +4577,8 @@ gb_internal i64 type_offset_of(Type *t, i64 index, Type **field_type_) {
case 1:
if (field_type_) *field_type_ = t_typeid;
return 8; // id
default:
GB_PANIC("index > 1");
}
}
break;
@@ -4654,6 +4656,7 @@ gb_internal i64 type_offset_of_from_selection(Type *type, Selection sel) {
switch (index) {
case 0: t = t_rawptr; break;
case 1: t = t_typeid; break;
default: GB_PANIC("index > 1");
}
}
break;
@@ -4919,7 +4922,7 @@ gb_internal Type *type_internal_index(Type *t, isize index) {
case Type_Slice:
{
GB_ASSERT(index == 0 || index == 1);
return index == 0 ? t_rawptr : t_typeid;
return index == 0 ? t_rawptr : t_int;
}
case Type_DynamicArray:
{