| ... | ... | @@ -8669,33 +8669,41 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8669 | 8669 | } |
| 8670 | 8670 | |
| 8671 | 8671 | // pointer const |
| 8672 | | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { |
| 8673 | | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8674 | | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| 8672 | ZigType *wanted_ptr_type = get_src_ptr_type(wanted_type); |
| 8673 | ZigType *actual_ptr_type = get_src_ptr_type(actual_type); |
| 8674 | bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC; |
| 8675 | bool actual_is_c_ptr = actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenC; |
| 8676 | if ((wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) || |
| 8677 | (wanted_ptr_type != nullptr && actual_is_c_ptr) || |
| 8678 | (actual_ptr_type != nullptr && wanted_is_c_ptr)) |
| 8679 | { |
| 8680 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type, |
| 8681 | actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const); |
| 8675 | 8682 | if (child.id == ConstCastResultIdInvalid) |
| 8676 | 8683 | return child; |
| 8677 | 8684 | if (child.id != ConstCastResultIdOk) { |
| 8678 | 8685 | result.id = ConstCastResultIdPointerChild; |
| 8679 | 8686 | result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1); |
| 8680 | 8687 | result.data.pointer_mismatch->child = child; |
| 8681 | | result.data.pointer_mismatch->wanted_child = wanted_type->data.pointer.child_type; |
| 8682 | | result.data.pointer_mismatch->actual_child = actual_type->data.pointer.child_type; |
| 8688 | result.data.pointer_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type; |
| 8689 | result.data.pointer_mismatch->actual_child = actual_ptr_type->data.pointer.child_type; |
| 8683 | 8690 | return result; |
| 8684 | 8691 | } |
| 8685 | | if ((err = type_resolve(g, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8692 | if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8686 | 8693 | result.id = ConstCastResultIdInvalid; |
| 8687 | 8694 | return result; |
| 8688 | 8695 | } |
| 8689 | | if ((err = type_resolve(g, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8696 | if ((err = type_resolve(g, wanted_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8690 | 8697 | result.id = ConstCastResultIdInvalid; |
| 8691 | 8698 | return result; |
| 8692 | 8699 | } |
| 8693 | | if ((actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && |
| 8694 | | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8695 | | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && |
| 8696 | | actual_type->data.pointer.bit_offset_in_host == wanted_type->data.pointer.bit_offset_in_host && |
| 8697 | | actual_type->data.pointer.host_int_bytes == wanted_type->data.pointer.host_int_bytes && |
| 8698 | | get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type)) |
| 8700 | bool ptr_lens_equal = actual_ptr_type->data.pointer.ptr_len == wanted_ptr_type->data.pointer.ptr_len; |
| 8701 | if ((ptr_lens_equal || wanted_is_c_ptr || actual_is_c_ptr) && |
| 8702 | (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 8703 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && |
| 8704 | actual_ptr_type->data.pointer.bit_offset_in_host == wanted_ptr_type->data.pointer.bit_offset_in_host && |
| 8705 | actual_ptr_type->data.pointer.host_int_bytes == wanted_ptr_type->data.pointer.host_int_bytes && |
| 8706 | get_ptr_align(ira->codegen, actual_ptr_type) >= get_ptr_align(ira->codegen, wanted_ptr_type)) |
| 8699 | 8707 | { |
| 8700 | 8708 | return result; |
| 8701 | 8709 | } |