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 {
26212621struct IrInstructionToPtrType {
26222622 IrInstruction base;
26232623
2624 IrInstruction *value;
2624 IrInstruction *ptr;
26252625};
26262626
26272627struct IrInstructionPtrTypeChild {
src/ir.cpp+11-17
......@@ -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,17 @@ 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) {
16312 // TODO: Allow capturing pointer to const array.
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);
16312 ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, ptr_ptr_type->data.pointer.is_const);
1631616313 } else if (is_array_ref(type_entry)) {
1631716314 ptr_type = get_pointer_to_type(ira->codegen,
1631816315 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,
1632916326 ptr_type = adjust_ptr_align(ira->codegen, ptr_type, reduced_align);
1633016327 }
1633116328 } 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;
1633516329 zig_panic("TODO for loop on var args");
1633616330 } else {
1633716331 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
test/stage1/behavior/for.zig+6
......@@ -27,7 +27,13 @@ test "for loop with pointer elem var" {
2727 mem.copy(u8, target[0..], source);
2828 mangleString(target[0..]);
2929 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);
3035}
36
3137fn mangleString(s: []u8) void {
3238 for (s) |*c| {
3339 c.* += 1;