mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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.
90 lines
4.6 KiB
Plaintext
90 lines
4.6 KiB
Plaintext
// RUN: %swift -emit-ir -target x86_64-apple-macosx10.9 %s | FileCheck --check-prefix=X86_64 %s
|
|
// RUN: %swift -emit-ir -target arm64-apple-ios8.0 %s | FileCheck --check-prefix=ARM64 %s
|
|
// RUN: %swift -emit-ir -target armv7-apple-ios8.0 %s | FileCheck --check-prefix=ARMV7 %s
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
|
|
class C {}
|
|
sil_vtable C {}
|
|
|
|
@objc protocol ObjC {}
|
|
|
|
// X86_64-LABEL: define{{( protected)?}} void @retain_release_bridge_object
|
|
// X86_64: call [[BRIDGE:%swift.bridge\*]] @swift_bridgeObjectRetain
|
|
// X86_64: call void @swift_bridgeObjectRelease
|
|
sil @retain_release_bridge_object : $(Builtin.BridgeObject) -> () {
|
|
entry(%b : $Builtin.BridgeObject):
|
|
strong_retain %b : $Builtin.BridgeObject
|
|
strong_release %b : $Builtin.BridgeObject
|
|
return undef : $()
|
|
}
|
|
|
|
// X86_64-LABEL: define{{( protected)?}} %swift.bridge* @convert_to_bridge_object
|
|
// X86_64: [[REFBITS:%.*]] = ptrtoint [[C:%C13bridge_object1C\*]] %0 to i64
|
|
// X86_64: [[OR:%.*]] = or i64 [[REFBITS]], %1
|
|
// X86_64: inttoptr i64 [[OR]] to [[BRIDGE]]
|
|
sil @convert_to_bridge_object : $(C, Builtin.Word) -> Builtin.BridgeObject {
|
|
entry(%c : $C, %w : $Builtin.Word):
|
|
%b = ref_to_bridge_object %c : $C, %w : $Builtin.Word
|
|
return %b : $Builtin.BridgeObject
|
|
}
|
|
|
|
// X86_64-LABEL: define{{( protected)?}} { %objc_object*, i64 } @convert_from_bridge_object
|
|
// X86_64: [[BOBITS:%.*]] = ptrtoint [[BRIDGE]] %0 to i64
|
|
// -- 0x8000_0000_0000_0001
|
|
// X86_64: [[TAGBITS:%.*]] = and i64 [[BOBITS]], -9223372036854775807
|
|
// X86_64: [[TAGGED:%.*]] = icmp eq i64 [[TAGBITS]], 0
|
|
// X86_64: br i1 [[TAGGED]], label %not-tagged-pointer, label %tagged-pointer
|
|
// X86_64: tagged-pointer:
|
|
// X86_64: [[TAGGED_RESULT:%.*]] = bitcast [[BRIDGE]] %0 to [[C:%objc_object\*]]
|
|
// X86_64: br label %tagged-cont
|
|
// X86_64: not-tagged-pointer:
|
|
// -- 0x00ff_ffff_ffff_fff8
|
|
// X86_64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
|
|
// X86_64: [[MASKED_RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C]]
|
|
// X86_64: br label %tagged-cont
|
|
// X86_64: tagged-cont:
|
|
// X86_64: phi [[C]] [ [[TAGGED_RESULT]], %tagged-pointer ], [ [[MASKED_RESULT]], %not-tagged-pointer ]
|
|
|
|
// ARM64-LABEL: define{{( protected)?}} { %objc_object*, i64 } @convert_from_bridge_object
|
|
// ARM64: [[BOBITS:%.*]] = ptrtoint [[BRIDGE:%swift.bridge\*]] %0 to i64
|
|
// -- 0x8000_0000_0000_0000
|
|
// ARM64: [[TAGBITS:%.*]] = and i64 [[BOBITS]], -9223372036854775808
|
|
// ARM64: [[TAGGED:%.*]] = icmp eq i64 [[TAGBITS]], 0
|
|
// ARM64: br i1 [[TAGGED]], label %not-tagged-pointer, label %tagged-pointer
|
|
// ARM64: tagged-pointer:
|
|
// ARM64: [[TAGGED_RESULT:%.*]] = bitcast [[BRIDGE]] %0 to [[C:%objc_object\*]]
|
|
// ARM64: br label %tagged-cont
|
|
// ARM64: not-tagged-pointer:
|
|
// -- 0x00ff_ffff_ffff_fff8
|
|
// ARM64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
|
|
// ARM64: [[MASKED_RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C]]
|
|
// ARM64: br label %tagged-cont
|
|
// ARM64: tagged-cont:
|
|
// ARM64: phi [[C]] [ [[TAGGED_RESULT]], %tagged-pointer ], [ [[MASKED_RESULT]], %not-tagged-pointer ]
|
|
|
|
// ARMV7-LABEL: define{{( protected)?}} { %objc_object*, i32 } @convert_from_bridge_object
|
|
// ARMV7: [[BOBITS:%.*]] = ptrtoint [[BRIDGE:%swift.bridge\*]] %0 to i32
|
|
// ARMV7: [[MASKED_BITS:%.*]] = and i32 [[BOBITS]], -4
|
|
// ARMV7: inttoptr i32 [[MASKED_BITS]] to [[C:%objc_object\*]]
|
|
sil @convert_from_bridge_object : $Builtin.BridgeObject -> (ObjC, Builtin.Word) {
|
|
entry(%b : $Builtin.BridgeObject):
|
|
%c = bridge_object_to_ref %b : $Builtin.BridgeObject to $ObjC
|
|
%w = bridge_object_to_word %b : $Builtin.BridgeObject to $Builtin.Word
|
|
%t = tuple (%c : $ObjC, %w : $Builtin.Word)
|
|
return %t : $(ObjC, Builtin.Word)
|
|
}
|
|
|
|
// X86_64-LABEL: define{{( protected)?}} %C13bridge_object1C* @convert_from_native_bridge_object
|
|
// X86_64: [[BOBITS:%.*]] = ptrtoint %swift.bridge* %0 to i64
|
|
// X86_64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
|
|
// X86_64: [[RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C:%C13bridge_object1C\*]]
|
|
// X86_64: ret %C13bridge_object1C* [[RESULT]]
|
|
sil @convert_from_native_bridge_object : $Builtin.BridgeObject -> C {
|
|
entry(%b : $Builtin.BridgeObject):
|
|
%c = bridge_object_to_ref %b : $Builtin.BridgeObject to $C
|
|
return %c : $C
|
|
}
|