| ... | @@ -2992,18 +2992,26 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI | ... | @@ -2992,18 +2992,26 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 2992 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); | 2992 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); |
| 2993 | } else if (array_type->id == TypeTableEntryIdStruct) { | 2993 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 2994 | assert(array_type->data.structure.is_slice); | 2994 | assert(array_type->data.structure.is_slice); |
| | 2995 | if (!type_has_bits(instruction->base.value.type)) { |
| | 2996 | if (safety_check_on) { |
| | 2997 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMIntegerTypeKind); |
| | 2998 | add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, array_ptr); |
| | 2999 | } |
| | 3000 | return nullptr; |
| | 3001 | } |
| | 3002 | |
| 2995 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); | 3003 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); |
| 2996 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); | 3004 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 2997 | | 3005 | |
| 2998 | if (safety_check_on) { | 3006 | if (safety_check_on) { |
| 2999 | size_t len_index = array_type->data.structure.fields[1].gen_index; | 3007 | size_t len_index = array_type->data.structure.fields[slice_len_index].gen_index; |
| 3000 | assert(len_index != SIZE_MAX); | 3008 | assert(len_index != SIZE_MAX); |
| 3001 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, ""); | 3009 | LLVMValueRef len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, ""); |
| 3002 | LLVMValueRef len = gen_load_untyped(g, len_ptr, 0, false, ""); | 3010 | LLVMValueRef len = gen_load_untyped(g, len_ptr, 0, false, ""); |
| 3003 | add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); | 3011 | add_bounds_check(g, subscript_value, LLVMIntEQ, nullptr, LLVMIntULT, len); |
| 3004 | } | 3012 | } |
| 3005 | | 3013 | |
| 3006 | size_t ptr_index = array_type->data.structure.fields[0].gen_index; | 3014 | size_t ptr_index = array_type->data.structure.fields[slice_ptr_index].gen_index; |
| 3007 | assert(ptr_index != SIZE_MAX); | 3015 | assert(ptr_index != SIZE_MAX); |
| 3008 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, ""); | 3016 | LLVMValueRef ptr_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)ptr_index, ""); |
| 3009 | LLVMValueRef ptr = gen_load_untyped(g, ptr_ptr, 0, false, ""); | 3017 | LLVMValueRef ptr = gen_load_untyped(g, ptr_ptr, 0, false, ""); |
| ... | @@ -3983,11 +3991,15 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst | ... | @@ -3983,11 +3991,15 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst |
| 3983 | add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); | 3991 | add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val); |
| 3984 | } | 3992 | } |
| 3985 | | 3993 | |
| 3986 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_ptr_index, ""); | 3994 | if (type_has_bits(array_type)) { |
| 3987 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); | 3995 | size_t gen_ptr_index = instruction->base.value.type->data.structure.fields[slice_ptr_index].gen_index; |
| 3988 | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); | 3996 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, ""); |
| | 3997 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, ""); |
| | 3998 | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); |
| | 3999 | } |
| 3989 | | 4000 | |
| 3990 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, ""); | 4001 | size_t gen_len_index = instruction->base.value.type->data.structure.fields[slice_len_index].gen_index; |
| | 4002 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, ""); |
| 3991 | LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); | 4003 | LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); |
| 3992 | gen_store_untyped(g, len_value, len_field_ptr, 0, false); | 4004 | gen_store_untyped(g, len_value, len_field_ptr, 0, false); |
| 3993 | | 4005 | |