| ... | @@ -1551,11 +1551,11 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou | ... | @@ -1551,11 +1551,11 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1551 | return &instruction->base; | 1551 | return &instruction->base; |
| 1552 | } | 1552 | } |
| 1553 | | 1553 | |
| 1554 | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { | 1554 | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { |
| 1555 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); | 1555 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); |
| 1556 | instruction->value = value; | 1556 | instruction->ptr = ptr; |
| 1557 | | 1557 | |
| 1558 | ir_ref_instruction(value, irb->current_basic_block); | 1558 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1559 | | 1559 | |
| 1560 | return &instruction->base; | 1560 | return &instruction->base; |
| 1561 | } | 1561 | } |
| ... | @@ -5689,9 +5689,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo | ... | @@ -5689,9 +5689,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5689 | if (array_val_ptr == irb->codegen->invalid_instruction) | 5689 | if (array_val_ptr == irb->codegen->invalid_instruction) |
| 5690 | return array_val_ptr; | 5690 | return array_val_ptr; |
| 5691 | | 5691 | |
| 5692 | IrInstruction *array_val = ir_build_load_ptr(irb, parent_scope, array_node, array_val_ptr); | 5692 | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr); |
| 5693 | | | |
| 5694 | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val); | | |
| 5695 | IrInstruction *elem_var_type; | 5693 | IrInstruction *elem_var_type; |
| 5696 | if (node->data.for_expr.elem_is_ptr) { | 5694 | if (node->data.for_expr.elem_is_ptr) { |
| 5697 | elem_var_type = pointer_type; | 5695 | elem_var_type = pointer_type; |
| ... | @@ -16301,18 +16299,17 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, | ... | @@ -16301,18 +16299,17 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 16301 | IrInstructionToPtrType *to_ptr_type_instruction) | 16299 | IrInstructionToPtrType *to_ptr_type_instruction) |
| 16302 | { | 16300 | { |
| 16303 | Error err; | 16301 | Error err; |
| 16304 | | 16302 | IrInstruction *ptr_ptr = to_ptr_type_instruction->ptr->child; |
| 16305 | IrInstruction *value = to_ptr_type_instruction->value->child; | 16303 | if (type_is_invalid(ptr_ptr->value.type)) |
| 16306 | ZigType *type_entry = value->value.type; | | |
| 16307 | if (type_is_invalid(type_entry)) | | |
| 16308 | return ira->codegen->invalid_instruction; | 16304 | return ira->codegen->invalid_instruction; |
| 16309 | | 16305 | |
| | 16306 | ZigType *ptr_ptr_type = ptr_ptr->value.type; |
| | 16307 | assert(ptr_ptr_type->id == ZigTypeIdPointer); |
| | 16308 | ZigType *type_entry = ptr_ptr_type->data.pointer.child_type; |
| | 16309 | |
| 16310 | ZigType *ptr_type; | 16310 | ZigType *ptr_type; |
| 16311 | if (type_entry->id == ZigTypeIdArray) { | 16311 | if (type_entry->id == ZigTypeIdArray) { |
| 16312 | // TODO: Allow capturing pointer to const array. | 16312 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, ptr_ptr_type->data.pointer.is_const); |
| 16313 | // const a = "123"; for (a) |*c| continue; | | |
| 16314 | // error: expected type '*u8', found '*const u8' | | |
| 16315 | ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); | | |
| 16316 | } else if (is_array_ref(type_entry)) { | 16313 | } else if (is_array_ref(type_entry)) { |
| 16317 | ptr_type = get_pointer_to_type(ira->codegen, | 16314 | ptr_type = get_pointer_to_type(ira->codegen, |
| 16318 | type_entry->data.pointer.child_type->data.array.child_type, type_entry->data.pointer.is_const); | 16315 | type_entry->data.pointer.child_type->data.array.child_type, type_entry->data.pointer.is_const); |
| ... | @@ -16329,9 +16326,6 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, | ... | @@ -16329,9 +16326,6 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 16329 | ptr_type = adjust_ptr_align(ira->codegen, ptr_type, reduced_align); | 16326 | ptr_type = adjust_ptr_align(ira->codegen, ptr_type, reduced_align); |
| 16330 | } | 16327 | } |
| 16331 | } else if (type_entry->id == ZigTypeIdArgTuple) { | 16328 | } else if (type_entry->id == ZigTypeIdArgTuple) { |
| 16332 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); | | |
| 16333 | if (!arg_tuple_val) | | |
| 16334 | return ira->codegen->invalid_instruction; | | |
| 16335 | zig_panic("TODO for loop on var args"); | 16329 | zig_panic("TODO for loop on var args"); |
| 16336 | } else { | 16330 | } else { |
| 16337 | ir_add_error_node(ira, to_ptr_type_instruction->base.source_node, | 16331 | ir_add_error_node(ira, to_ptr_type_instruction->base.source_node, |