| ... | @@ -26191,6 +26191,16 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy | ... | @@ -26191,6 +26191,16 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy |
| 26191 | return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count); | 26191 | return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count); |
| 26192 | } | 26192 | } |
| 26193 | | 26193 | |
| | 26194 | static ZigType *get_result_loc_type(IrAnalyze *ira, ResultLoc *result_loc) { |
| | 26195 | if (result_loc == nullptr) return nullptr; |
| | 26196 | |
| | 26197 | if (result_loc->id == ResultLocIdCast) { |
| | 26198 | return ir_resolve_type(ira, result_loc->source_instruction->child); |
| | 26199 | } |
| | 26200 | |
| | 26201 | return nullptr; |
| | 26202 | } |
| | 26203 | |
| 26194 | static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) { | 26204 | static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) { |
| 26195 | Error err; | 26205 | Error err; |
| 26196 | | 26206 | |
| ... | @@ -26297,11 +26307,16 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i | ... | @@ -26297,11 +26307,16 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26297 | ZigType *child_array_type = (array_type->id == ZigTypeIdPointer && | 26307 | ZigType *child_array_type = (array_type->id == ZigTypeIdPointer && |
| 26298 | array_type->data.pointer.ptr_len == PtrLenSingle) ? array_type->data.pointer.child_type : array_type; | 26308 | array_type->data.pointer.ptr_len == PtrLenSingle) ? array_type->data.pointer.child_type : array_type; |
| 26299 | | 26309 | |
| 26300 | // If start index and end index are both comptime known, then the result type is a pointer to array | | |
| 26301 | // not a slice. | | |
| 26302 | ZigType *return_type; | 26310 | ZigType *return_type; |
| 26303 | | 26311 | |
| 26304 | if (value_is_comptime(casted_start->value) && | 26312 | // If start index and end index are both comptime known, then the result type is a pointer to array |
| | 26313 | // not a slice. However, if the start or end index is a lazy value, and the result location is a slice, |
| | 26314 | // then the pointer-to-array would be casted to a slice anyway. So, we preserve the laziness of these |
| | 26315 | // values by making the return type a slice. |
| | 26316 | ZigType *res_loc_type = get_result_loc_type(ira, instruction->result_loc); |
| | 26317 | |
| | 26318 | if ((res_loc_type == nullptr || !is_slice(res_loc_type)) && |
| | 26319 | value_is_comptime(casted_start->value) && |
| 26305 | ((end != nullptr && value_is_comptime(end->value)) || | 26320 | ((end != nullptr && value_is_comptime(end->value)) || |
| 26306 | (end == nullptr && child_array_type->id == ZigTypeIdArray))) | 26321 | (end == nullptr && child_array_type->id == ZigTypeIdArray))) |
| 26307 | { | 26322 | { |