authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-06 10:56:07+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-06 10:56:07+02:00
log3109c898505820fb8cc89f87759292a9aebe3db1
tree5f8fa1619d685b15db6c4cc11aa8b56e5d22479a
parentf00adb47f5c2b70496dac1c48f03236271b9bd57

fixed 1726


3 files changed, 13 insertions(+), 16 deletions(-)

src/all_types.hpp+1-1
......@@ -2621,7 +2621,7 @@ struct IrInstructionTypeOf {
26212621struct IrInstructionToPtrType {
26222622 IrInstruction base;
26232623
2624 IrInstruction *value;
2624 IrInstruction *ptr;
26252625};
26262626
26272627struct IrInstructionPtrTypeChild {
src/ir.cpp+11-14
......@@ -1551,11 +1551,11 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
15511551 return &instruction->base;
15521552}
15531553
1554static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
1554static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {
15551555 IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node);
1556 instruction->value = value;
1556 instruction->ptr = ptr;
15571557
1558 ir_ref_instruction(value, irb->current_basic_block);
1558 ir_ref_instruction(ptr, irb->current_basic_block);
15591559
15601560 return &instruction->base;
15611561}
......@@ -5689,9 +5689,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
56895689 if (array_val_ptr == irb->codegen->invalid_instruction)
56905690 return array_val_ptr;
56915691
5692 IrInstruction *array_val = ir_build_load_ptr(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);
5692 IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr);
56955693 IrInstruction *elem_var_type;
56965694 if (node->data.for_expr.elem_is_ptr) {
56975695 elem_var_type = pointer_type;
......@@ -16301,18 +16299,20 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1630116299 IrInstructionToPtrType *to_ptr_type_instruction)
1630216300{
1630316301 Error err;
16304
16305 IrInstruction *value = to_ptr_type_instruction->value->child;
16306 ZigType *type_entry = value->value.type;
16307 if (type_is_invalid(type_entry))
16302 IrInstruction *ptr_ptr = to_ptr_type_instruction->ptr->child;
16303 if (type_is_invalid(ptr_ptr->value.type))
1630816304 return ira->codegen->invalid_instruction;
1630916305
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
1631016310 ZigType *ptr_type;
1631116311 if (type_entry->id == ZigTypeIdArray) {
1631216312 // TODO: Allow capturing pointer to const array.
1631316313 // const a = "123"; for (a) |*c| continue;
1631416314 // error: expected type '*u8', found '*const u8'
16315 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
16315 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, ptr_ptr_type->data.pointer.is_const);
1631616316 } else if (is_array_ref(type_entry)) {
1631716317 ptr_type = get_pointer_to_type(ira->codegen,
1631816318 type_entry->data.pointer.child_type->data.array.child_type, type_entry->data.pointer.is_const);
......@@ -16329,9 +16329,6 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
1632916329 ptr_type = adjust_ptr_align(ira->codegen, ptr_type, reduced_align);
1633016330 }
1633116331 } 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;
1633516332 zig_panic("TODO for loop on var args");
1633616333 } else {
1633716334 ir_add_error_node(ira, to_ptr_type_instruction->base.source_node,
src/ir_print.cpp+1-1
......@@ -356,7 +356,7 @@ static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
356356
357357static void ir_print_to_ptr_type(IrPrint *irp, IrInstructionToPtrType *instruction) {
358358 fprintf(irp->f, "@toPtrType(");
359 ir_print_other_instruction(irp, instruction->value);
359 ir_print_other_instruction(irp, instruction->ptr);
360360 fprintf(irp->f, ")");
361361}
362362