From cde442fa2cb8ebd2a2e305b75f677348c17bb768 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 20 Apr 2023 11:55:18 +0100 Subject: Add internal padding to types where ptr size != int size --- src/llvm_backend_utility.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/llvm_backend_utility.cpp') diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index ddae2243b..99deca5e9 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -929,7 +929,33 @@ gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { if (t->kind == Type_Struct) { auto field_remapping = lb_get_struct_remapping(m, t); - index = field_remapping[index]; + return field_remapping[index]; + } else if (build_context.word_size != build_context.int_size) { + switch (t->kind) { + case Type_Slice: + GB_ASSERT(build_context.word_size*2 == build_context.int_size); + switch (index) { + case 0: return 0; // data + case 1: return 2; // len + } + break; + case Type_DynamicArray: + GB_ASSERT(build_context.word_size*2 == build_context.int_size); + switch (index) { + case 0: return 0; // data + case 1: return 2; // len + case 2: return 3; // cap + case 3: return 4; // allocator + } + break; + case Type_SoaPointer: + GB_ASSERT(build_context.word_size*2 == build_context.int_size); + switch (index) { + case 0: return 0; // data + case 1: return 2; // offset + } + break; + } } return index; } -- cgit v1.2.3