| ... | @@ -1307,6 +1307,7 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour | ... | @@ -1307,6 +1307,7 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1307 | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); | 1307 | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 1308 | br_instruction->op_id = op_id; | 1308 | br_instruction->op_id = op_id; |
| 1309 | br_instruction->value = value; | 1309 | br_instruction->value = value; |
| | 1310 | br_instruction->lval = LValNone; |
| 1310 | | 1311 | |
| 1311 | ir_ref_instruction(value, irb->current_basic_block); | 1312 | ir_ref_instruction(value, irb->current_basic_block); |
| 1312 | | 1313 | |
| ... | @@ -7223,7 +7224,13 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -7223,7 +7224,13 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7223 | if (value == irb->codegen->invalid_instruction) | 7224 | if (value == irb->codegen->invalid_instruction) |
| 7224 | return value; | 7225 | return value; |
| 7225 | | 7226 | |
| 7226 | return ir_build_un_op(irb, scope, node, IrUnOpDereference, value); | 7227 | // We essentially just converted any lvalue from &(x.*) to (&x).*; |
| | 7228 | // this inhibits checking that x is a pointer later, so we directly |
| | 7229 | // record whether the pointer check is needed |
| | 7230 | IrInstructionUnOp *result = (IrInstructionUnOp*)ir_build_un_op(irb, scope, node, IrUnOpDereference, value); |
| | 7231 | result->lval = lval; |
| | 7232 | |
| | 7233 | return &result->base; |
| 7227 | } | 7234 | } |
| 7228 | case NodeTypeUnwrapOptional: { | 7235 | case NodeTypeUnwrapOptional: { |
| 7229 | AstNode *expr_node = node->data.unwrap_optional.expr; | 7236 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| ... | @@ -11463,7 +11470,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -11463,7 +11470,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11463 | return load_ptr_instruction; | 11470 | return load_ptr_instruction; |
| 11464 | } else { | 11471 | } else { |
| 11465 | ir_add_error_node(ira, source_instruction->source_node, | 11472 | ir_add_error_node(ira, source_instruction->source_node, |
| 11466 | buf_sprintf("attempt to dereference non pointer type '%s'", | 11473 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 11467 | buf_ptr(&type_entry->name))); | 11474 | buf_ptr(&type_entry->name))); |
| 11468 | return ira->codegen->invalid_instruction; | 11475 | return ira->codegen->invalid_instruction; |
| 11469 | } | 11476 | } |
| ... | @@ -13678,12 +13685,6 @@ no_mem_slot: | ... | @@ -13678,12 +13685,6 @@ no_mem_slot: |
| 13678 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, | 13685 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 13679 | IrInstruction *ptr, IrInstruction *uncasted_value) | 13686 | IrInstruction *ptr, IrInstruction *uncasted_value) |
| 13680 | { | 13687 | { |
| 13681 | if (ptr->value.type->id != ZigTypeIdPointer) { | | |
| 13682 | ir_add_error(ira, ptr, | | |
| 13683 | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); | | |
| 13684 | return ira->codegen->invalid_instruction; | | |
| 13685 | } | | |
| 13686 | | | |
| 13687 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { | 13688 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 13688 | return ir_const_void(ira, source_instr); | 13689 | return ir_const_void(ira, source_instr); |
| 13689 | } | 13690 | } |
| ... | @@ -14612,11 +14613,18 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction | ... | @@ -14612,11 +14613,18 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 14612 | buf_ptr(&ptr_type->name))); | 14613 | buf_ptr(&ptr_type->name))); |
| 14613 | return ira->codegen->invalid_instruction; | 14614 | return ira->codegen->invalid_instruction; |
| 14614 | } | 14615 | } |
| 14615 | // this dereference is always an rvalue because in the IR gen we identify lvalue and emit | 14616 | |
| 14616 | // one of the ptr instructions | | |
| 14617 | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr); | 14617 | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr); |
| 14618 | if (result == ira->codegen->invalid_instruction) | 14618 | if (result == ira->codegen->invalid_instruction) |
| 14619 | return ira->codegen->invalid_instruction; | 14619 | return ira->codegen->invalid_instruction; |
| | 14620 | |
| | 14621 | // If the result needs to be an lvalue, type check it |
| | 14622 | if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { |
| | 14623 | ir_add_error(ira, &instruction->base, |
| | 14624 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); |
| | 14625 | return ira->codegen->invalid_instruction; |
| | 14626 | } |
| | 14627 | |
| 14620 | return result; | 14628 | return result; |
| 14621 | } | 14629 | } |
| 14622 | case IrUnOpOptional: | 14630 | case IrUnOpOptional: |
| ... | @@ -15442,12 +15450,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc | ... | @@ -15442,12 +15450,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 15442 | if (type_is_invalid(container_ptr->value.type)) | 15450 | if (type_is_invalid(container_ptr->value.type)) |
| 15443 | return ira->codegen->invalid_instruction; | 15451 | return ira->codegen->invalid_instruction; |
| 15444 | | 15452 | |
| 15445 | if (container_ptr->value.type->id != ZigTypeIdPointer) { | | |
| 15446 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, | | |
| 15447 | buf_sprintf("attempt to dereference non-pointer type '%s'", | | |
| 15448 | buf_ptr(&container_ptr->value.type->name))); | | |
| 15449 | return ira->codegen->invalid_instruction; | | |
| 15450 | } | | |
| 15451 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; | 15453 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 15452 | | 15454 | |
| 15453 | Buf *field_name = field_ptr_instruction->field_name_buffer; | 15455 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| ... | @@ -16658,11 +16660,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -16658,11 +16660,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16658 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); | 16660 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 16659 | } | 16661 | } |
| 16660 | | 16662 | |
| 16661 | if (target_value_ptr->value.type->id != ZigTypeIdPointer) { | | |
| 16662 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); | | |
| 16663 | return ira->codegen->invalid_instruction; | | |
| 16664 | } | | |
| 16665 | | | |
| 16666 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; | 16663 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16667 | ConstExprValue *pointee_val = nullptr; | 16664 | ConstExprValue *pointee_val = nullptr; |
| 16668 | if (instr_is_comptime(target_value_ptr)) { | 16665 | if (instr_is_comptime(target_value_ptr)) { |