| ... | ... | @@ -1303,14 +1303,23 @@ static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 1303 | 1303 | return &ptr_type_of_instruction->base; |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | | static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, IrInstruction *value) { |
| 1307 | | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 1308 | | br_instruction->op_id = op_id; |
| 1309 | | br_instruction->value = value; |
| 1306 | static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 1307 | IrInstruction *value, LVal lval) |
| 1308 | { |
| 1309 | IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 1310 | instruction->op_id = op_id; |
| 1311 | instruction->value = value; |
| 1312 | instruction->lval = lval; |
| 1310 | 1313 | |
| 1311 | 1314 | ir_ref_instruction(value, irb->current_basic_block); |
| 1312 | 1315 | |
| 1313 | | return &br_instruction->base; |
| 1316 | return &instruction->base; |
| 1317 | } |
| 1318 | |
| 1319 | static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 1320 | IrInstruction *value) |
| 1321 | { |
| 1322 | return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone); |
| 1314 | 1323 | } |
| 1315 | 1324 | |
| 1316 | 1325 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| ... | ... | @@ -7223,7 +7232,10 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 7223 | 7232 | if (value == irb->codegen->invalid_instruction) |
| 7224 | 7233 | return value; |
| 7225 | 7234 | |
| 7226 | | return ir_build_un_op(irb, scope, node, IrUnOpDereference, value); |
| 7235 | // We essentially just converted any lvalue from &(x.*) to (&x).*; |
| 7236 | // this inhibits checking that x is a pointer later, so we directly |
| 7237 | // record whether the pointer check is needed |
| 7238 | return ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval); |
| 7227 | 7239 | } |
| 7228 | 7240 | case NodeTypeUnwrapOptional: { |
| 7229 | 7241 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| ... | ... | @@ -11463,7 +11475,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11463 | 11475 | return load_ptr_instruction; |
| 11464 | 11476 | } else { |
| 11465 | 11477 | ir_add_error_node(ira, source_instruction->source_node, |
| 11466 | | buf_sprintf("attempt to dereference non pointer type '%s'", |
| 11478 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 11467 | 11479 | buf_ptr(&type_entry->name))); |
| 11468 | 11480 | return ira->codegen->invalid_instruction; |
| 11469 | 11481 | } |
| ... | ... | @@ -13678,11 +13690,7 @@ no_mem_slot: |
| 13678 | 13690 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 13679 | 13691 | IrInstruction *ptr, IrInstruction *uncasted_value) |
| 13680 | 13692 | { |
| 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 | | } |
| 13693 | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 13686 | 13694 | |
| 13687 | 13695 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 13688 | 13696 | return ir_const_void(ira, source_instr); |
| ... | ... | @@ -14612,11 +14620,18 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 14612 | 14620 | buf_ptr(&ptr_type->name))); |
| 14613 | 14621 | return ira->codegen->invalid_instruction; |
| 14614 | 14622 | } |
| 14615 | | // this dereference is always an rvalue because in the IR gen we identify lvalue and emit |
| 14616 | | // one of the ptr instructions |
| 14623 | |
| 14617 | 14624 | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr); |
| 14618 | 14625 | if (result == ira->codegen->invalid_instruction) |
| 14619 | 14626 | return ira->codegen->invalid_instruction; |
| 14627 | |
| 14628 | // If the result needs to be an lvalue, type check it |
| 14629 | if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { |
| 14630 | ir_add_error(ira, &instruction->base, |
| 14631 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); |
| 14632 | return ira->codegen->invalid_instruction; |
| 14633 | } |
| 14634 | |
| 14620 | 14635 | return result; |
| 14621 | 14636 | } |
| 14622 | 14637 | case IrUnOpOptional: |
| ... | ... | @@ -15442,12 +15457,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 15442 | 15457 | if (type_is_invalid(container_ptr->value.type)) |
| 15443 | 15458 | return ira->codegen->invalid_instruction; |
| 15444 | 15459 | |
| 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 | 15460 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 15452 | 15461 | |
| 15453 | 15462 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| ... | ... | @@ -16658,11 +16667,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16658 | 16667 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 16659 | 16668 | } |
| 16660 | 16669 | |
| 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 | 16670 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16667 | 16671 | ConstExprValue *pointee_val = nullptr; |
| 16668 | 16672 | if (instr_is_comptime(target_value_ptr)) { |