| ... | @@ -1473,19 +1473,20 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI | ... | @@ -1473,19 +1473,20 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 1473 | if (canon_child_type->id == TypeTableEntryIdStruct && | 1473 | if (canon_child_type->id == TypeTableEntryIdStruct && |
| 1474 | canon_child_type->data.structure.layout == ContainerLayoutPacked) | 1474 | canon_child_type->data.structure.layout == ContainerLayoutPacked) |
| 1475 | { | 1475 | { |
| 1476 | LLVMTypeRef ptr_u8_type_ref = LLVMPointerType(LLVMInt8Type(), 0); | | |
| 1477 | LLVMValueRef u8_array_ptr = LLVMBuildBitCast(g->builder, array_ptr, ptr_u8_type_ref, ""); | | |
| 1478 | size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count; | 1476 | size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count; |
| 1479 | assert(unaligned_bit_count != 0); | 1477 | if (unaligned_bit_count != 0) { |
| 1480 | assert(unaligned_bit_count % 8 == 0); | 1478 | LLVMTypeRef ptr_u8_type_ref = LLVMPointerType(LLVMInt8Type(), 0); |
| 1481 | LLVMValueRef elem_size_bytes = LLVMConstInt(g->builtin_types.entry_usize->type_ref, | 1479 | LLVMValueRef u8_array_ptr = LLVMBuildBitCast(g->builder, array_ptr, ptr_u8_type_ref, ""); |
| 1482 | unaligned_bit_count / 8, false); | 1480 | assert(unaligned_bit_count % 8 == 0); |
| 1483 | LLVMValueRef byte_offset = LLVMBuildNUWMul(g->builder, subscript_value, elem_size_bytes, ""); | 1481 | LLVMValueRef elem_size_bytes = LLVMConstInt(g->builtin_types.entry_usize->type_ref, |
| 1484 | LLVMValueRef indices[] = { | 1482 | unaligned_bit_count / 8, false); |
| 1485 | byte_offset | 1483 | LLVMValueRef byte_offset = LLVMBuildNUWMul(g->builder, subscript_value, elem_size_bytes, ""); |
| 1486 | }; | 1484 | LLVMValueRef indices[] = { |
| 1487 | LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, ""); | 1485 | byte_offset |
| 1488 | return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), ""); | 1486 | }; |
| | 1487 | LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, ""); |
| | 1488 | return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), ""); |
| | 1489 | } |
| 1489 | } | 1490 | } |
| 1490 | LLVMValueRef indices[] = { | 1491 | LLVMValueRef indices[] = { |
| 1491 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), | 1492 | LLVMConstNull(g->builtin_types.entry_usize->type_ref), |