| ... | ... | @@ -1307,6 +1307,7 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1307 | 1307 | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 1308 | 1308 | br_instruction->op_id = op_id; |
| 1309 | 1309 | br_instruction->value = value; |
| 1310 | br_instruction->lval = LValNone; |
| 1310 | 1311 | |
| 1311 | 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 | 7224 | if (value == irb->codegen->invalid_instruction) |
| 7224 | 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 | 7235 | case NodeTypeUnwrapOptional: { |
| 7229 | 7236 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| ... | ... | @@ -11437,7 +11444,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11437 | 11444 | return load_ptr_instruction; |
| 11438 | 11445 | } else { |
| 11439 | 11446 | ir_add_error_node(ira, source_instruction->source_node, |
| 11440 | | buf_sprintf("attempt to dereference non pointer type '%s'", |
| 11447 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 11441 | 11448 | buf_ptr(&type_entry->name))); |
| 11442 | 11449 | return ira->codegen->invalid_instruction; |
| 11443 | 11450 | } |
| ... | ... | @@ -13616,12 +13623,6 @@ no_mem_slot: |
| 13616 | 13623 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 13617 | 13624 | IrInstruction *ptr, IrInstruction *uncasted_value) |
| 13618 | 13625 | { |
| 13619 | | if (ptr->value.type->id != ZigTypeIdPointer) { |
| 13620 | | ir_add_error(ira, ptr, |
| 13621 | | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); |
| 13622 | | return ira->codegen->invalid_instruction; |
| 13623 | | } |
| 13624 | | |
| 13625 | 13626 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 13626 | 13627 | return ir_const_void(ira, source_instr); |
| 13627 | 13628 | } |
| ... | ... | @@ -14550,11 +14551,18 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 14550 | 14551 | buf_ptr(&ptr_type->name))); |
| 14551 | 14552 | return ira->codegen->invalid_instruction; |
| 14552 | 14553 | } |
| 14553 | | // this dereference is always an rvalue because in the IR gen we identify lvalue and emit |
| 14554 | | // one of the ptr instructions |
| 14554 | |
| 14555 | 14555 | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr); |
| 14556 | 14556 | if (result == ira->codegen->invalid_instruction) |
| 14557 | 14557 | return ira->codegen->invalid_instruction; |
| 14558 | |
| 14559 | // If the result needs to be an lvalue, type check it |
| 14560 | if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { |
| 14561 | ir_add_error(ira, &instruction->base, |
| 14562 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); |
| 14563 | return ira->codegen->invalid_instruction; |
| 14564 | } |
| 14565 | |
| 14558 | 14566 | return result; |
| 14559 | 14567 | } |
| 14560 | 14568 | case IrUnOpOptional: |
| ... | ... | @@ -15380,12 +15388,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 15380 | 15388 | if (type_is_invalid(container_ptr->value.type)) |
| 15381 | 15389 | return ira->codegen->invalid_instruction; |
| 15382 | 15390 | |
| 15383 | | if (container_ptr->value.type->id != ZigTypeIdPointer) { |
| 15384 | | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15385 | | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 15386 | | buf_ptr(&container_ptr->value.type->name))); |
| 15387 | | return ira->codegen->invalid_instruction; |
| 15388 | | } |
| 15389 | 15391 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 15390 | 15392 | |
| 15391 | 15393 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| ... | ... | @@ -16596,11 +16598,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16596 | 16598 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 16597 | 16599 | } |
| 16598 | 16600 | |
| 16599 | | if (target_value_ptr->value.type->id != ZigTypeIdPointer) { |
| 16600 | | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); |
| 16601 | | return ira->codegen->invalid_instruction; |
| 16602 | | } |
| 16603 | | |
| 16604 | 16601 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16605 | 16602 | ConstExprValue *pointee_val = nullptr; |
| 16606 | 16603 | if (instr_is_comptime(target_value_ptr)) { |