|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -generic-specializer | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: objc_interop |
| 4 | + |
| 5 | +// This test checks that we properly distinguish in between the specialized |
| 6 | +// functions for the @thick, @thin, and @objc_metatype metatypes. |
| 7 | +// |
| 8 | +// This can occur if we do not properly mangle in the metatype representation |
| 9 | +// into the name of functions and thus reuse the incorrect already specialized |
| 10 | +// method instead of the new specialized method. |
| 11 | + |
| 12 | +sil_stage canonical |
| 13 | + |
| 14 | +import Builtin |
| 15 | + |
| 16 | +protocol AnyObject {} |
| 17 | + |
| 18 | +sil [noinline] @tmp : $@convention(thin) <T> () -> (@out T) { |
| 19 | +bb0(%0 : $*T): |
| 20 | + %1 = tuple() |
| 21 | + return %1 : $() |
| 22 | +} |
| 23 | + |
| 24 | +// CHECK-LABEL: sil [ossa] @tmp2 : $@convention(thin) () -> () { |
| 25 | +// CHECK: [[FUN1:%[0-9]+]] = function_ref @$s3tmp4main9AnyObject_pXmT_Tg5 : $@convention(thin) () -> @thick AnyObject.Type |
| 26 | +// CHECK-NEXT: apply [[FUN1]] |
| 27 | +// CHECK: [[FUN2:%[0-9]+]] = function_ref @$s3tmp4main9AnyObject_pXmo_Tg5 : $@convention(thin) () -> @objc_metatype AnyObject.Type |
| 28 | +// CHECK-NEXT: apply [[FUN2]] |
| 29 | +// CHECK: [[FUN3:%[0-9]+]] = function_ref @$s3tmpBi32_XMT_Tg5 : $@convention(thin) () -> @thick Builtin.Int32.Type |
| 30 | +// CHECK-NEXT: apply [[FUN3]] |
| 31 | +// CHECK: [[FUN4:%[0-9]+]] = function_ref @$s3tmpBi32_XMo_Tg5 : $@convention(thin) () -> @objc_metatype Builtin.Int32.Type |
| 32 | +// CHECK-NEXT: apply [[FUN4]] |
| 33 | +// CHECK: [[FUN5:%[0-9]+]] = function_ref @$s3tmpBi32_XMt_Tg5 : $@convention(thin) () -> @thin Builtin.Int32.Type |
| 34 | +// CHECK-NEXT: apply [[FUN5]] |
| 35 | +sil [ossa] @tmp2 : $@convention(thin) () -> () { |
| 36 | +bb0: |
| 37 | + %0 = function_ref @tmp : $@convention(thin) <T> () -> (@out T) |
| 38 | + %1 = alloc_box $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type> |
| 39 | + %1a = project_box %1 : $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type>, 0 |
| 40 | + %2 = alloc_box $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type> |
| 41 | + %2a = project_box %2 : $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type>, 0 |
| 42 | + %4 = apply %0<@thick AnyObject.Type>(%1a) : $@convention(thin) <T> () -> (@out T) |
| 43 | + %5 = apply %0<@objc_metatype AnyObject.Type>(%2a) : $@convention(thin) <T> () -> (@out T) |
| 44 | + |
| 45 | + %6 = alloc_box $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type> |
| 46 | + %6a = project_box %6 : $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type>, 0 |
| 47 | + %7 = alloc_box $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type> |
| 48 | + %7a = project_box %7 : $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type>, 0 |
| 49 | + %8 = alloc_box $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type> |
| 50 | + %8a = project_box %8 : $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type>, 0 |
| 51 | + %9 = apply %0<@thick Builtin.Int32.Type>(%6a) : $@convention(thin) <T> () -> (@out T) |
| 52 | + %10 = apply %0<@objc_metatype Builtin.Int32.Type>(%7a) : $@convention(thin) <T> () -> (@out T) |
| 53 | + %11 = apply %0<@thin Builtin.Int32.Type>(%8a) : $@convention(thin) <T> () -> (@out T) |
| 54 | + destroy_value %8 : $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type> |
| 55 | + destroy_value %7 : $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type> |
| 56 | + destroy_value %6 : $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type> |
| 57 | + destroy_value %2 : $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type> |
| 58 | + destroy_value %1 : $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type> |
| 59 | + %9999 = tuple() |
| 60 | + return %9999 : $() |
| 61 | +} |
0 commit comments