| ... | ... | @@ -26261,13 +26261,16 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26261 | 26261 | return ira->codegen->invalid_inst_gen; |
| 26262 | 26262 | } |
| 26263 | 26263 | |
| 26264 | ZigType *child_array_type = (array_type->id == ZigTypeIdPointer && |
| 26265 | array_type->data.pointer.ptr_len == PtrLenSingle) ? array_type->data.pointer.child_type : array_type; |
| 26266 | |
| 26264 | 26267 | // If start index and end index are both comptime known, then the result type is a pointer to array |
| 26265 | 26268 | // not a slice. |
| 26266 | 26269 | ZigType *return_type; |
| 26267 | 26270 | |
| 26268 | 26271 | if (value_is_comptime(casted_start->value) && |
| 26269 | 26272 | ((end != nullptr && value_is_comptime(end->value)) || |
| 26270 | | (end == nullptr && array_type->id == ZigTypeIdArray))) |
| 26273 | (end == nullptr && child_array_type->id == ZigTypeIdArray))) |
| 26271 | 26274 | { |
| 26272 | 26275 | ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); |
| 26273 | 26276 | if (!start_val) |
| ... | ... | @@ -26282,10 +26285,11 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26282 | 26285 | return ira->codegen->invalid_inst_gen; |
| 26283 | 26286 | end_scalar = bigint_as_u64(&end_val->data.x_bigint); |
| 26284 | 26287 | } else { |
| 26285 | | end_scalar = array_type->data.array.len; |
| 26288 | end_scalar = child_array_type->data.array.len; |
| 26286 | 26289 | } |
| 26287 | | ZigValue *array_sentinel = (array_type->id == ZigTypeIdArray && end_scalar == array_type->data.array.len) |
| 26288 | | ? sentinel_val : nullptr; |
| 26290 | ZigValue *array_sentinel = (child_array_type->id == ZigTypeIdArray && |
| 26291 | end_scalar == child_array_type->data.array.len) |
| 26292 | ? child_array_type->data.array.sentinel : nullptr; |
| 26289 | 26293 | |
| 26290 | 26294 | if (start_scalar > end_scalar) { |
| 26291 | 26295 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| ... | ... | @@ -26318,12 +26322,8 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 26318 | 26322 | size_t abs_offset; |
| 26319 | 26323 | size_t rel_end; |
| 26320 | 26324 | bool ptr_is_undef = false; |
| 26321 | | if (array_type->id == ZigTypeIdArray || |
| 26322 | | (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) |
| 26323 | | { |
| 26325 | if (child_array_type->id == ZigTypeIdArray) { |
| 26324 | 26326 | if (array_type->id == ZigTypeIdPointer) { |
| 26325 | | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 26326 | | assert(child_array_type->id == ZigTypeIdArray); |
| 26327 | 26327 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 26328 | 26328 | if (parent_ptr == nullptr) |
| 26329 | 26329 | return ira->codegen->invalid_inst_gen; |