| ... | @@ -232,7 +232,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) | ... | @@ -232,7 +232,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) |
| 232 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, | 232 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 233 | ZigValue *out_val, ZigValue *ptr_val); | 233 | ZigValue *out_val, ZigValue *ptr_val); |
| 234 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, | 234 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 235 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); | 235 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); |
| 236 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); | 236 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); |
| 237 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); | 237 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 238 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, | 238 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| ... | @@ -14999,7 +14999,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, | ... | @@ -14999,7 +14999,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 14999 | dest_ptr_type = wanted_type->data.maybe.child_type; | 14999 | dest_ptr_type = wanted_type->data.maybe.child_type; |
| 15000 | } | 15000 | } |
| 15001 | if (dest_ptr_type != nullptr) { | 15001 | if (dest_ptr_type != nullptr) { |
| 15002 | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); | 15002 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 15003 | } | 15003 | } |
| 15004 | } | 15004 | } |
| 15005 | | 15005 | |
| ... | @@ -15041,7 +15041,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, | ... | @@ -15041,7 +15041,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 15041 | actual_type->data.pointer.child_type, source_node, | 15041 | actual_type->data.pointer.child_type, source_node, |
| 15042 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 15042 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 15043 | { | 15043 | { |
| 15044 | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); | 15044 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 15045 | } | 15045 | } |
| 15046 | | 15046 | |
| 15047 | // cast from integer to C pointer | 15047 | // cast from integer to C pointer |
| ... | @@ -18478,7 +18478,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18478,7 +18478,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18478 | | 18478 | |
| 18479 | result_loc->written = true; | 18479 | result_loc->written = true; |
| 18480 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, | 18480 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 18481 | ptr_type, &result_cast->base.source_instruction->base, false); | 18481 | &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false); |
| 18482 | return result_loc->resolved_loc; | 18482 | return result_loc->resolved_loc; |
| 18483 | } | 18483 | } |
| 18484 | case ResultLocIdBitCast: { | 18484 | case ResultLocIdBitCast: { |
| ... | @@ -18566,7 +18566,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i | ... | @@ -18566,7 +18566,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 18566 | | 18566 | |
| 18567 | result_loc->written = true; | 18567 | result_loc->written = true; |
| 18568 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, | 18568 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 18569 | ptr_type, &result_bit_cast->base.source_instruction->base, false); | 18569 | &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false); |
| 18570 | return result_loc->resolved_loc; | 18570 | return result_loc->resolved_loc; |
| 18571 | } | 18571 | } |
| 18572 | } | 18572 | } |
| ... | @@ -22716,8 +22716,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi | ... | @@ -22716,8 +22716,8 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 22716 | ref_type->data.pointer.explicit_alignment, | 22716 | ref_type->data.pointer.explicit_alignment, |
| 22717 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, | 22717 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 22718 | ref_type->data.pointer.allow_zero); | 22718 | ref_type->data.pointer.allow_zero); |
| 22719 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, | 22719 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22720 | &instruction->base.base, false); | 22720 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 22721 | } else { | 22721 | } else { |
| 22722 | ir_add_error(ira, &instruction->base.base, | 22722 | ir_add_error(ira, &instruction->base.base, |
| 22723 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); | 22723 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| ... | @@ -22797,8 +22797,8 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, | ... | @@ -22797,8 +22797,8 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 22797 | ref_type->data.pointer.explicit_alignment, | 22797 | ref_type->data.pointer.explicit_alignment, |
| 22798 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, | 22798 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 22799 | ref_type->data.pointer.allow_zero); | 22799 | ref_type->data.pointer.allow_zero); |
| 22800 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, | 22800 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22801 | &instruction->base.base, false); | 22801 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 22802 | } | 22802 | } |
| 22803 | | 22803 | |
| 22804 | return target_value_ptr; | 22804 | return target_value_ptr; |
| ... | @@ -27688,7 +27688,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig | ... | @@ -27688,7 +27688,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 27688 | } | 27688 | } |
| 27689 | | 27689 | |
| 27690 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, | 27690 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 27691 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) | 27691 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) |
| 27692 | { | 27692 | { |
| 27693 | Error err; | 27693 | Error err; |
| 27694 | | 27694 | |
| ... | @@ -27704,7 +27704,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27704,7 +27704,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27704 | | 27704 | |
| 27705 | ZigType *src_ptr_type = get_src_ptr_type(src_type); | 27705 | ZigType *src_ptr_type = get_src_ptr_type(src_type); |
| 27706 | if (src_ptr_type == nullptr) { | 27706 | if (src_ptr_type == nullptr) { |
| 27707 | ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); | 27707 | ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 27708 | return ira->codegen->invalid_inst_gen; | 27708 | return ira->codegen->invalid_inst_gen; |
| 27709 | } | 27709 | } |
| 27710 | | 27710 | |
| ... | @@ -27737,7 +27737,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27737,7 +27737,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27737 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 27737 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 27738 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", | 27738 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", |
| 27739 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); | 27739 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 27740 | add_error_note(ira->codegen, msg, ptr->base.source_node, | 27740 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 27741 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); | 27741 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); |
| 27742 | add_error_note(ira->codegen, msg, dest_type_src->source_node, | 27742 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 27743 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); | 27743 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); |
| ... | @@ -27801,7 +27801,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn | ... | @@ -27801,7 +27801,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 27801 | | 27801 | |
| 27802 | if (dest_align_bytes > src_align_bytes) { | 27802 | if (dest_align_bytes > src_align_bytes) { |
| 27803 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); | 27803 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 27804 | add_error_note(ira->codegen, msg, ptr->base.source_node, | 27804 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 27805 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); | 27805 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); |
| 27806 | add_error_note(ira->codegen, msg, dest_type_src->source_node, | 27806 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 27807 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); | 27807 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); |
| ... | @@ -27834,8 +27834,8 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa | ... | @@ -27834,8 +27834,8 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa |
| 27834 | if (type_is_invalid(src_type)) | 27834 | if (type_is_invalid(src_type)) |
| 27835 | return ira->codegen->invalid_inst_gen; | 27835 | return ira->codegen->invalid_inst_gen; |
| 27836 | | 27836 | |
| 27837 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, dest_type, &dest_type_value->base, | 27837 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base, |
| 27838 | instruction->safety_check_on); | 27838 | dest_type, &dest_type_value->base, instruction->safety_check_on); |
| 27839 | } | 27839 | } |
| 27840 | | 27840 | |
| 27841 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { | 27841 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { |