mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This prevents the linker from trying to emit relative relocations to locally-defined public symbols into dynamic libraries, which gives ld.so heartache.
70 lines
2.5 KiB
Plaintext
70 lines
2.5 KiB
Plaintext
// RUN: rm -rf %t && mkdir %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)?}} void @purebred_method(%C18class_isa_pointers8Purebred*) {{.*}} {
|
|
// CHECK: [[ISA_PTR:%.*]] = bitcast %C18class_isa_pointers8Purebred* %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)?}} void @mongrel_method(%C18class_isa_pointers7Mongrel*) {{.*}} {
|
|
// 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 @_TToFC18class_isa_pointers7Mongrel6methodfT_T_ : $@convention(objc_method) (Purebred) -> () {
|
|
entry(%0 : $Purebred):
|
|
unreachable
|
|
}
|
|
sil private @_TToFC18class_isa_pointers7MongrelcfT7bellsOnSi_GSQS0__ : $@convention(objc_method) (Int, Purebred) -> () {
|
|
entry(%0 : $Int, %1 : $Purebred):
|
|
unreachable
|
|
}
|
|
sil private @_TToFC18class_isa_pointers7MongrelcfT_S0_ : $@convention(objc_method) (Purebred) -> () {
|
|
entry(%0 : $Purebred):
|
|
unreachable
|
|
}
|