aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-11-04 20:56:49 +0000
committerGitHub <noreply@github.com>2025-11-04 20:56:49 +0000
commit12d8572d439d40d030b12e8fc98210ed255405d7 (patch)
treebdcdac4db3ca857ed5515492c348617ff4d3d536 /src
parentf70454c237a74b8ead76bf1cd6d3fb94e30d2e8a (diff)
parent3ef063632498a59bd6df3de5d34e92bf6b6102d8 (diff)
Merge pull request #5886 from laytan/32bit-typeid-fixes
fixes for 32bit with regards to typeid
Diffstat (limited to 'src')
-rw-r--r--src/llvm_backend_const.cpp5
-rw-r--r--src/llvm_backend_debug.cpp6
-rw-r--r--src/llvm_backend_stmt.cpp13
-rw-r--r--src/llvm_backend_type.cpp25
-rw-r--r--src/llvm_backend_utility.cpp2
-rw-r--r--src/types.cpp5
6 files changed, 25 insertions, 31 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp
index c014adc05..9b785c4b4 100644
--- a/src/llvm_backend_const.cpp
+++ b/src/llvm_backend_const.cpp
@@ -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);
diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp
index 3372165f2..187aebf7c 100644
--- a/src/llvm_backend_debug.cpp
+++ b/src/llvm_backend_debug.cpp
@@ -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
diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp
index f247fa2a7..3dbcea4fb 100644
--- a/src/llvm_backend_stmt.cpp
+++ b/src/llvm_backend_stmt.cpp
@@ -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);
diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp
index 7d412eb15..474999191 100644
--- a/src/llvm_backend_type.cpp
+++ b/src/llvm_backend_type.cpp
@@ -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);
diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp
index c7b4170e9..33ad2ee8d 100644
--- a/src/llvm_backend_utility.cpp
+++ b/src/llvm_backend_utility.cpp
@@ -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) {
diff --git a/src/types.cpp b/src/types.cpp
index a1311ba5d..b9089b9fc 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -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:
{