// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s // rdar://146780049 class Image {} class MyV { var image: Image = Image() } func takesPtr(_: UnsafePointer?, _: UnsafePointer?, _: UnsafePointer?) { } func test(buffers: [MyV]) { withUnsafePointer(to: buffers[0].image) { ptrA in withUnsafePointer(to: buffers[1].image) { ptrB in withUnsafePointer(to: buffers[2].image) { ptrC in _ = takesPtr(ptrA, ptrB, ptrC) } } } } // The other valid conversion here that should not be considered because it has a worse // score is pointer-to-pointer instead of value-to-optional. The generated SIL looks // quite different in that case, involving calls to intrinsics. Make sure we pick the // value-to-optional conversion, because it generates much simpler SIL: // CHECK-LABEL: sil private [ossa] @$s28ambiguous_pointer_conversion4test7buffersySayAA3MyVCG_tFySPyAA5ImageCGXEfU_yAIXEfU_yAIXEfU_ : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2> (UnsafePointer<τ_0_0>, UnsafePointer, UnsafePointer) -> (@out τ_0_2, @error_indirect τ_0_1) for { // CHECK: bb0(%0 : $*(), %1 : $*Never, %2 : $UnsafePointer, %3 : @closureCapture $UnsafePointer, %4 : @closureCapture $UnsafePointer): // CHECK: [[X:%.*]] = enum $Optional>, #Optional.some!enumelt, %3 // CHECK: [[Y:%.*]] = enum $Optional>, #Optional.some!enumelt, %4 // CHECK: [[Z:%.*]] = enum $Optional>, #Optional.some!enumelt, %2 // CHECK: [[FN:%.*]] = function_ref @$s28ambiguous_pointer_conversion8takesPtryySPyAA5ImageCGSg_A2FtF : $@convention(thin) (Optional>, Optional>, Optional>) -> () // CHECK: apply %11([[X]], [[Y]], [[Z]]) : $@convention(thin) (Optional>, Optional>, Optional>) -> () // CHECK: return