| ... | ... | @@ -3052,8 +3052,10 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex |
| 3052 | 3052 | IrInstructionPtrOfArrayToSlice *instruction) |
| 3053 | 3053 | { |
| 3054 | 3054 | ZigType *actual_type = instruction->operand->value.type; |
| 3055 | | LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand); |
| 3056 | | assert(expr_val); |
| 3055 | ZigType *slice_type = instruction->base.value.type; |
| 3056 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index].type_entry; |
| 3057 | size_t ptr_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; |
| 3058 | size_t len_index = slice_type->data.structure.fields[slice_len_index].gen_index; |
| 3057 | 3059 | |
| 3058 | 3060 | LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); |
| 3059 | 3061 | |
| ... | ... | @@ -3061,15 +3063,21 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex |
| 3061 | 3063 | ZigType *array_type = actual_type->data.pointer.child_type; |
| 3062 | 3064 | assert(array_type->id == ZigTypeIdArray); |
| 3063 | 3065 | |
| 3064 | | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, slice_ptr_index, ""); |
| 3065 | | LLVMValueRef indices[] = { |
| 3066 | | LLVMConstNull(g->builtin_types.entry_usize->llvm_type), |
| 3067 | | LLVMConstInt(g->builtin_types.entry_usize->llvm_type, 0, false), |
| 3068 | | }; |
| 3069 | | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, expr_val, indices, 2, ""); |
| 3070 | | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); |
| 3066 | if (type_has_bits(actual_type)) { |
| 3067 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, ""); |
| 3068 | LLVMValueRef indices[] = { |
| 3069 | LLVMConstNull(g->builtin_types.entry_usize->llvm_type), |
| 3070 | LLVMConstInt(g->builtin_types.entry_usize->llvm_type, 0, false), |
| 3071 | }; |
| 3072 | LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand); |
| 3073 | LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, expr_val, indices, 2, ""); |
| 3074 | gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false); |
| 3075 | } else if (ir_want_runtime_safety(g, &instruction->base)) { |
| 3076 | LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, ""); |
| 3077 | gen_undef_init(g, slice_ptr_type->abi_align, slice_ptr_type, ptr_field_ptr); |
| 3078 | } |
| 3071 | 3079 | |
| 3072 | | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, slice_len_index, ""); |
| 3080 | LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, len_index, ""); |
| 3073 | 3081 | LLVMValueRef len_value = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, |
| 3074 | 3082 | array_type->data.array.len, false); |
| 3075 | 3083 | gen_store_untyped(g, len_value, len_field_ptr, 0, false); |