| ... | @@ -9711,10 +9711,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9711,10 +9711,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9711 | @tagName(dest_ty.zigTypeTag()), dest_ty, | 9711 | @tagName(dest_ty.zigTypeTag()), dest_ty, |
| 9712 | }); | 9712 | }); |
| 9713 | } | 9713 | } |
| 9714 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 9714 | return sema.coerceCompatiblePtrs(block, dest_ty, operand, operand_src); |
| 9715 | return sema.addConstant(dest_ty, val); | | |
| 9716 | } | | |
| 9717 | return block.addBitCast(dest_ty, operand); | | |
| 9718 | } | 9715 | } |
| 9719 | | 9716 | |
| 9720 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9717 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -12096,6 +12093,14 @@ fn coerce( | ... | @@ -12096,6 +12093,14 @@ fn coerce( |
| 12096 | else => {}, | 12093 | else => {}, |
| 12097 | } | 12094 | } |
| 12098 | } | 12095 | } |
| | 12096 | |
| | 12097 | // cast from *T and [*]T to *c_void |
| | 12098 | // but don't do it if the source type is a double pointer |
| | 12099 | if (dest_info.pointee_type.tag() == .c_void and inst_ty.zigTypeTag() == .Pointer and |
| | 12100 | inst_ty.childType().zigTypeTag() != .Pointer) |
| | 12101 | { |
| | 12102 | return sema.coerceCompatiblePtrs(block, dest_ty, inst, inst_src); |
| | 12103 | } |
| 12099 | }, | 12104 | }, |
| 12100 | .Int => { | 12105 | .Int => { |
| 12101 | // integer widening | 12106 | // integer widening |
| ... | @@ -12808,7 +12813,7 @@ fn coerceCompatiblePtrs( | ... | @@ -12808,7 +12813,7 @@ fn coerceCompatiblePtrs( |
| 12808 | inst: Air.Inst.Ref, | 12813 | inst: Air.Inst.Ref, |
| 12809 | inst_src: LazySrcLoc, | 12814 | inst_src: LazySrcLoc, |
| 12810 | ) !Air.Inst.Ref { | 12815 | ) !Air.Inst.Ref { |
| 12811 | if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| { | 12816 | if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| { |
| 12812 | // The comptime Value representation is compatible with both types. | 12817 | // The comptime Value representation is compatible with both types. |
| 12813 | return sema.addConstant(dest_ty, val); | 12818 | return sema.addConstant(dest_ty, val); |
| 12814 | } | 12819 | } |