| ... | ... | @@ -11521,6 +11521,19 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 11521 | 11521 | return ir_analyze_int_to_ptr(ira, source_instr, unsigned_integer, dest_type); |
| 11522 | 11522 | } |
| 11523 | 11523 | |
| 11524 | static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) { |
| 11525 | if (ty->id == ZigTypeIdPointer) return ty->data.pointer.child_type->id != ZigTypeIdPointer; |
| 11526 | if (ty->id == ZigTypeIdFn) return true; |
| 11527 | if (ty->id == ZigTypeIdPromise) return true; |
| 11528 | if (ty->id == ZigTypeIdOptional) { |
| 11529 | ZigType *ptr_ty = ty->data.maybe.child_type; |
| 11530 | if (ptr_ty->id == ZigTypeIdPointer) return ptr_ty->data.pointer.child_type->id != ZigTypeIdPointer; |
| 11531 | if (ptr_ty->id == ZigTypeIdFn) return true; |
| 11532 | if (ptr_ty->id == ZigTypeIdPromise) return true; |
| 11533 | } |
| 11534 | return false; |
| 11535 | } |
| 11536 | |
| 11524 | 11537 | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 11525 | 11538 | ZigType *wanted_type, IrInstruction *value) |
| 11526 | 11539 | { |
| ... | ... | @@ -11895,27 +11908,19 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11895 | 11908 | |
| 11896 | 11909 | // cast from *T and [*]T to *c_void and ?*c_void |
| 11897 | 11910 | // but don't do it if the actual type is a double pointer |
| 11898 | | if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.child_type->id != ZigTypeIdPointer) { |
| 11911 | if (is_pointery_and_elem_is_not_pointery(actual_type)) { |
| 11899 | 11912 | ZigType *dest_ptr_type = nullptr; |
| 11900 | 11913 | if (wanted_type->id == ZigTypeIdPointer && |
| 11901 | | wanted_type->data.pointer.ptr_len == PtrLenSingle && |
| 11902 | 11914 | wanted_type->data.pointer.child_type == ira->codegen->builtin_types.entry_c_void) |
| 11903 | 11915 | { |
| 11904 | 11916 | dest_ptr_type = wanted_type; |
| 11905 | 11917 | } else if (wanted_type->id == ZigTypeIdOptional && |
| 11906 | 11918 | wanted_type->data.maybe.child_type->id == ZigTypeIdPointer && |
| 11907 | | wanted_type->data.maybe.child_type->data.pointer.ptr_len == PtrLenSingle && |
| 11908 | 11919 | wanted_type->data.maybe.child_type->data.pointer.child_type == ira->codegen->builtin_types.entry_c_void) |
| 11909 | 11920 | { |
| 11910 | 11921 | dest_ptr_type = wanted_type->data.maybe.child_type; |
| 11911 | 11922 | } |
| 11912 | | if (dest_ptr_type != nullptr && |
| 11913 | | (!actual_type->data.pointer.is_const || dest_ptr_type->data.pointer.is_const) && |
| 11914 | | (!actual_type->data.pointer.is_volatile || dest_ptr_type->data.pointer.is_volatile) && |
| 11915 | | actual_type->data.pointer.bit_offset_in_host == dest_ptr_type->data.pointer.bit_offset_in_host && |
| 11916 | | actual_type->data.pointer.host_int_bytes == dest_ptr_type->data.pointer.host_int_bytes && |
| 11917 | | get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, dest_ptr_type)) |
| 11918 | | { |
| 11923 | if (dest_ptr_type != nullptr) { |
| 11919 | 11924 | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); |
| 11920 | 11925 | } |
| 11921 | 11926 | } |