| ... | ... | @@ -8683,16 +8683,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8683 | 8683 | bool actual_opt_or_ptr = actual_ptr_type != nullptr && |
| 8684 | 8684 | (actual_type->id == ZigTypeIdPointer || actual_type->id == ZigTypeIdOptional); |
| 8685 | 8685 | if (wanted_opt_or_ptr && actual_opt_or_ptr) { |
| 8686 | | bool ok_allows_zero = (wanted_allows_zero && |
| 8687 | | (actual_allows_zero || wanted_ptr_type->data.pointer.is_const)) || |
| 8688 | | (!wanted_allows_zero && !actual_allows_zero); |
| 8689 | | if (!ok_allows_zero) { |
| 8690 | | result.id = ConstCastResultIdBadAllowsZero; |
| 8691 | | result.data.bad_allows_zero = allocate_nonzero<ConstCastBadAllowsZero>(1); |
| 8692 | | result.data.bad_allows_zero->wanted_type = wanted_type; |
| 8693 | | result.data.bad_allows_zero->actual_type = actual_type; |
| 8694 | | return result; |
| 8695 | | } |
| 8696 | 8686 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type, |
| 8697 | 8687 | actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const); |
| 8698 | 8688 | if (child.id == ConstCastResultIdInvalid) |
| ... | ... | @@ -8705,6 +8695,16 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8705 | 8695 | result.data.pointer_mismatch->actual_child = actual_ptr_type->data.pointer.child_type; |
| 8706 | 8696 | return result; |
| 8707 | 8697 | } |
| 8698 | bool ok_allows_zero = (wanted_allows_zero && |
| 8699 | (actual_allows_zero || wanted_ptr_type->data.pointer.is_const)) || |
| 8700 | (!wanted_allows_zero && !actual_allows_zero); |
| 8701 | if (!ok_allows_zero) { |
| 8702 | result.id = ConstCastResultIdBadAllowsZero; |
| 8703 | result.data.bad_allows_zero = allocate_nonzero<ConstCastBadAllowsZero>(1); |
| 8704 | result.data.bad_allows_zero->wanted_type = wanted_type; |
| 8705 | result.data.bad_allows_zero->actual_type = actual_type; |
| 8706 | return result; |
| 8707 | } |
| 8708 | 8708 | if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8709 | 8709 | result.id = ConstCastResultIdInvalid; |
| 8710 | 8710 | return result; |
| ... | ... | @@ -10846,22 +10846,20 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10846 | 10846 | break; |
| 10847 | 10847 | } |
| 10848 | 10848 | case ConstCastResultIdBadAllowsZero: { |
| 10849 | | bool wanted_allows_zero = ptr_allows_addr_zero(cast_result->data.bad_allows_zero->wanted_type); |
| 10850 | | bool actual_allows_zero = ptr_allows_addr_zero(cast_result->data.bad_allows_zero->actual_type); |
| 10851 | | ZigType *wanted_ptr_type = get_src_ptr_type(cast_result->data.bad_allows_zero->wanted_type); |
| 10852 | | ZigType *actual_ptr_type = get_src_ptr_type(cast_result->data.bad_allows_zero->actual_type); |
| 10853 | | ZigType *wanted_elem_type = wanted_ptr_type->data.pointer.child_type; |
| 10854 | | ZigType *actual_elem_type = actual_ptr_type->data.pointer.child_type; |
| 10849 | ZigType *wanted_type = cast_result->data.bad_allows_zero->wanted_type; |
| 10850 | ZigType *actual_type = cast_result->data.bad_allows_zero->actual_type; |
| 10851 | bool wanted_allows_zero = ptr_allows_addr_zero(wanted_type); |
| 10852 | bool actual_allows_zero = ptr_allows_addr_zero(actual_type); |
| 10855 | 10853 | if (actual_allows_zero && !wanted_allows_zero) { |
| 10856 | 10854 | add_error_note(ira->codegen, parent_msg, source_node, |
| 10857 | 10855 | buf_sprintf("'%s' could have null values which are illegal in type '%s'", |
| 10858 | | buf_ptr(&actual_elem_type->name), |
| 10859 | | buf_ptr(&wanted_elem_type->name))); |
| 10856 | buf_ptr(&actual_type->name), |
| 10857 | buf_ptr(&wanted_type->name))); |
| 10860 | 10858 | } else { |
| 10861 | 10859 | add_error_note(ira->codegen, parent_msg, source_node, |
| 10862 | 10860 | buf_sprintf("mutable '%s' allows illegal null values stored to type '%s'", |
| 10863 | | buf_ptr(&cast_result->data.bad_allows_zero->wanted_type->name), |
| 10864 | | buf_ptr(&cast_result->data.bad_allows_zero->actual_type->name))); |
| 10861 | buf_ptr(&wanted_type->name), |
| 10862 | buf_ptr(&actual_type->name))); |
| 10865 | 10863 | } |
| 10866 | 10864 | break; |
| 10867 | 10865 | } |