| // RUN: %empty-directory(%t) |
| // RUN: %build-irgen-test-overlays |
| // RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) %s -emit-ir | %FileCheck %s |
| |
| // REQUIRES: CPU=x86_64 |
| // REQUIRES: objc_interop |
| |
| import Swift |
| import gizmo |
| |
| // |
| // A pure Swift class. We can access its isa directly. |
| // |
| |
| class Purebred { |
| func method() {} |
| } |
| sil_vtable Purebred {} |
| |
| // CHECK-LABEL: define{{( protected)?}} swiftcc void @purebred_method(%T18class_isa_pointers8PurebredC*) {{.*}} { |
| // CHECK: [[ISA_PTR:%.*]] = bitcast %T18class_isa_pointers8PurebredC* %0 to %swift.type** |
| // CHECK: [[ISA:%.*]] = load %swift.type*, %swift.type** [[ISA_PTR]] |
| // CHECK: [[VTABLE:%.*]] = bitcast %swift.type* [[ISA]] |
| // CHECK: getelementptr inbounds {{.*}} [[VTABLE]] |
| sil @purebred_method : $@convention(thin) (@owned Purebred) -> () { |
| entry(%0 : $Purebred): |
| %m = class_method %0 : $Purebred, #Purebred.method!1 : (Purebred) -> () -> (), $@convention(method) (@guaranteed Purebred) -> () |
| %z = apply %m(%0) : $@convention(method) (@guaranteed Purebred) -> () |
| return %z : $() |
| } |
| |
| // |
| // A mixed Swift/ObjC class. We have to mask when reading its isa. |
| // |
| |
| class Mongrel: Gizmo { |
| func method() {} |
| } |
| sil_vtable Mongrel {} |
| |
| // CHECK-LABEL: define{{( protected)?}} swiftcc void @mongrel_method(%T18class_isa_pointers7MongrelC*) {{.*}} { |
| // CHECK: [[T0:%.*]] = bitcast {{.*}} %0 to i64* |
| // CHECK-NEXT: [[T1:%.*]] = load i64, i64* [[T0]], align 8 |
| // CHECK-NEXT: [[T2:%.*]] = load i64, i64* @swift_isaMask, align 8 |
| // CHECK-NEXT: [[T3:%.*]] = and i64 [[T1]], [[T2]] |
| // CHECK: [[ISA:%.*]] = inttoptr i64 [[T3]] to %swift.type* |
| // CHECK: [[VTABLE:%.*]] = bitcast %swift.type* [[ISA]] |
| // CHECK: getelementptr inbounds {{.*}} [[VTABLE]] |
| sil @mongrel_method : $@convention(thin) (@owned Mongrel) -> () { |
| entry(%0 : $Mongrel): |
| %m = class_method %0 : $Mongrel, #Mongrel.method!1 : (Mongrel) -> () -> (), $@convention(method) (@guaranteed Mongrel) -> () |
| %z = apply %m(%0) : $@convention(method) (@guaranteed Mongrel) -> () |
| return %z : $() |
| } |
| |
| // ObjC stubs expected by ObjC metadata emission |
| |
| sil private @$S18class_isa_pointers7MongrelC6methodyyFTo : $@convention(objc_method) (Purebred) -> () { |
| entry(%0 : $Purebred): |
| unreachable |
| } |
| sil private @$S18class_isa_pointers7MongrelC7bellsOnACSgSi_tcfcTo : $@convention(objc_method) (Int, Purebred) -> () { |
| entry(%0 : $Int, %1 : $Purebred): |
| unreachable |
| } |
| sil private @$S18class_isa_pointers7MongrelCACycfcTo : $@convention(objc_method) (Purebred) -> () { |
| entry(%0 : $Purebred): |
| unreachable |
| } |