authorgravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-07 03:19:08+02:00
committergravatar for jhc@dismail.deJimmi Holst Christensen <jhc@dismail.de> 2019-04-07 03:19:08+02:00
log7c38651a65b48b8cc683bc31a40952d9b469ec4d
tree84dff112a46c7fc273b83787311ee10e033781e3
parent6960cd156addc23492ddbb3c1b7627a63d2ba46a
parent77c203615922889e35c356827e26c00f3547a35e

Merge branch 'master' of github.com:ziglang/zig


4 files changed, 19 insertions(+), 19 deletions(-)

src/all_types.hpp+1-1
...@@ -2621,7 +2621,7 @@ struct IrInstructionTypeOf {...@@ -2621,7 +2621,7 @@ struct IrInstructionTypeOf {
2621struct IrInstructionToPtrType {2621struct IrInstructionToPtrType {
2622 IrInstruction base;2622 IrInstruction base;
26232623
2624 IrInstruction *value;2624 IrInstruction *ptr;
2625};2625};
26262626
2627struct IrInstructionPtrTypeChild {2627struct IrInstructionPtrTypeChild {
src/ir.cpp+11-17
...@@ -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}
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) {
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;
15571557
1558 ir_ref_instruction(value, irb->current_basic_block);1558 ir_ref_instruction(ptr, irb->current_basic_block);
15591559
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;
56915691
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;
1630416302 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;
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
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,
src/ir_print.cpp+1-1
...@@ -356,7 +356,7 @@ static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {...@@ -356,7 +356,7 @@ static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
356356
357static void ir_print_to_ptr_type(IrPrint *irp, IrInstructionToPtrType *instruction) {357static void ir_print_to_ptr_type(IrPrint *irp, IrInstructionToPtrType *instruction) {
358 fprintf(irp->f, "@toPtrType(");358 fprintf(irp->f, "@toPtrType(");
359 ir_print_other_instruction(irp, instruction->value);359 ir_print_other_instruction(irp, instruction->ptr);
360 fprintf(irp->f, ")");360 fprintf(irp->f, ")");
361}361}
362362
test/stage1/behavior/for.zig+6
...@@ -27,7 +27,13 @@ test "for loop with pointer elem var" {...@@ -27,7 +27,13 @@ test "for loop with pointer elem var" {
27 mem.copy(u8, target[0..], source);27 mem.copy(u8, target[0..], source);
28 mangleString(target[0..]);28 mangleString(target[0..]);
29 expect(mem.eql(u8, target, "bcdefgh"));29 expect(mem.eql(u8, target, "bcdefgh"));
30
31 for (source) |*c, i|
32 expect(@typeOf(c) == *const u8);
33 for (target) |*c, i|
34 expect(@typeOf(c) == *u8);
30}35}
36
31fn mangleString(s: []u8) void {37fn mangleString(s: []u8) void {
32 for (s) |*c| {38 for (s) |*c| {
33 c.* += 1;39 c.* += 1;