diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-06 12:49:00 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-06 12:49:00 -0400 |
| commit | 77c203615922889e35c356827e26c00f3547a35e (patch) | |
| tree | fc0237b5716eef232a14aed6c13f8c6b6a554859 /src/ir.cpp | |
| parent | f00adb47f5c2b70496dac1c48f03236271b9bd57 (diff) | |
| parent | 65cf5a8e44f299bb24e139cc25df717f1ddba455 (diff) | |
| download | zig-77c203615922889e35c356827e26c00f3547a35e.tar.gz zig-77c203615922889e35c356827e26c00f3547a35e.zip | |
Merge pull request #2200 from ziglang/fix-1726
fixed #1726
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index b602df29ad..c572e3c885 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -1551,11 +1551,11 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou return &instruction->base; } -static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { +static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); - instruction->value = value; + instruction->ptr = ptr; - ir_ref_instruction(value, irb->current_basic_block); + ir_ref_instruction(ptr, irb->current_basic_block); return &instruction->base; } @@ -5689,9 +5689,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo if (array_val_ptr == irb->codegen->invalid_instruction) return array_val_ptr; - IrInstruction *array_val = ir_build_load_ptr(irb, parent_scope, array_node, array_val_ptr); - - IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val); + IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_val_ptr); IrInstruction *elem_var_type; if (node->data.for_expr.elem_is_ptr) { elem_var_type = pointer_type; @@ -16301,18 +16299,17 @@ static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, IrInstructionToPtrType *to_ptr_type_instruction) { Error err; - - IrInstruction *value = to_ptr_type_instruction->value->child; - ZigType *type_entry = value->value.type; - if (type_is_invalid(type_entry)) + IrInstruction *ptr_ptr = to_ptr_type_instruction->ptr->child; + if (type_is_invalid(ptr_ptr->value.type)) return ira->codegen->invalid_instruction; + ZigType *ptr_ptr_type = ptr_ptr->value.type; + assert(ptr_ptr_type->id == ZigTypeIdPointer); + ZigType *type_entry = ptr_ptr_type->data.pointer.child_type; + ZigType *ptr_type; if (type_entry->id == ZigTypeIdArray) { - // TODO: Allow capturing pointer to const array. - // const a = "123"; for (a) |*c| continue; - // error: expected type '*u8', found '*const u8' - ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); + ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, ptr_ptr_type->data.pointer.is_const); } else if (is_array_ref(type_entry)) { ptr_type = get_pointer_to_type(ira->codegen, 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, ptr_type = adjust_ptr_align(ira->codegen, ptr_type, reduced_align); } } else if (type_entry->id == ZigTypeIdArgTuple) { - ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); - if (!arg_tuple_val) - return ira->codegen->invalid_instruction; zig_panic("TODO for loop on var args"); } else { ir_add_error_node(ira, to_ptr_type_instruction->base.source_node, |
