mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
specialization to be separately lowered in IRGen, use the mangling of the specialized type as the name of the llvm::StructType instead of the base, unspecialized type. This tends to produce fewer collisions between IR type names. LLVM does unique the names on its own, so that's not strictly necessary, but it's still a good idea because it makes the test output more reliable and somewhat easier to read (modulo the impact of bigger type names). Collisions will still occur if the type is specialized at an archetype, since in this case we will fall back on the unspecialized type.
81 lines
2.9 KiB
Plaintext
81 lines
2.9 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 --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize %s
|
|
|
|
// REQUIRES: CPU=i386_or_x86_64
|
|
// REQUIRES: objc_interop
|
|
|
|
import Swift
|
|
import Foundation
|
|
|
|
class C {}
|
|
sil_vtable C {}
|
|
class D: NSObject {}
|
|
sil_vtable D {}
|
|
|
|
enum SwiftClass {
|
|
case A(C), B(D)
|
|
}
|
|
// can use spare bits—both payloads are Swift-defined classes
|
|
// CHECK-32: %O15enum_spare_bits10SwiftClass = type <{ [4 x i8] }>
|
|
// CHECK-64: %O15enum_spare_bits10SwiftClass = type <{ [8 x i8] }>
|
|
|
|
enum ObjCClass {
|
|
case A(NSObject), B(C)
|
|
}
|
|
// can't use spare bits—NSObject is an ObjC-defined class
|
|
// CHECK-32: %O15enum_spare_bits9ObjCClass = type <{ [4 x i8] }>
|
|
// CHECK-64: %O15enum_spare_bits9ObjCClass = type <{ [8 x i8], [1 x i8] }>
|
|
|
|
@objc @unsafe_no_objc_tagged_pointer
|
|
protocol NoTaggedPointers {}
|
|
|
|
enum Existential {
|
|
case A(AnyObject), B(C)
|
|
}
|
|
// can't use spare bits—existential may be bound to tagged pointer type
|
|
// CHECK-32: %O15enum_spare_bits11Existential = type <{ [4 x i8] }>
|
|
// CHECK-64: %O15enum_spare_bits11Existential = type <{ [8 x i8], [1 x i8] }>
|
|
|
|
enum ExistentialNoTaggedPointers {
|
|
case A(NoTaggedPointers), B(C)
|
|
}
|
|
// can use spare bits—@unsafe_no_objc_tagged_pointer says it's ok
|
|
// CHECK-32: %O15enum_spare_bits27ExistentialNoTaggedPointers = type <{ [4 x i8] }>
|
|
// CHECK-64: %O15enum_spare_bits27ExistentialNoTaggedPointers = type <{ [8 x i8] }>
|
|
|
|
enum Archetype<T: AnyObject> {
|
|
case A(T), B(C)
|
|
}
|
|
// can't use spare bits—archetype may be bound to tagged pointer type
|
|
// CHECK-32: [[ARCHETYPE:%GO15enum_spare_bits9ArchetypeCS_1C_]] = type <{ [4 x i8], [1 x i8] }>
|
|
// CHECK-32: [[ARCHETYPE_OBJC:%GO15enum_spare_bits9ArchetypeCSo8NSObject_]] = type <{ [4 x i8], [1 x i8] }>
|
|
// CHECK-64: [[ARCHETYPE:%GO15enum_spare_bits9ArchetypeCS_1C_]] = type <{ [8 x i8], [1 x i8] }>
|
|
// CHECK-64: [[ARCHETYPE_OBJC:%GO15enum_spare_bits9ArchetypeCSo8NSObject_]] = type <{ [8 x i8], [1 x i8] }>
|
|
|
|
sil_global @swiftClass: $SwiftClass
|
|
sil_global @objcClass: $ObjCClass
|
|
sil_global @existential: $Existential
|
|
sil_global @existentialntp: $ExistentialNoTaggedPointers
|
|
sil_global @archetypeBoundToSwift: $Archetype<C>
|
|
sil_global @archetypeBoundToObjC: $Archetype<NSObject>
|
|
|
|
// CHECK: @archetypeBoundToSwift = {{(protected )?}}global [[ARCHETYPE]]
|
|
// CHECK: @archetypeBoundToObjC = {{(protected )?}}global [[ARCHETYPE_OBJC]]
|
|
|
|
sil @instantiate_globals : $() -> () {
|
|
entry:
|
|
%a = global_addr @swiftClass : $*SwiftClass
|
|
%b = global_addr @objcClass : $*ObjCClass
|
|
%c = global_addr @existential : $*Existential
|
|
%d = global_addr @existentialntp : $*ExistentialNoTaggedPointers
|
|
%e = global_addr @archetypeBoundToSwift : $*Archetype<C>
|
|
%f = global_addr @archetypeBoundToObjC : $*Archetype<NSObject>
|
|
return undef : $()
|
|
}
|
|
|
|
sil @_TToFC15enum_spare_bits1DcfT_S0_ : $(@owned D) -> @owned D {
|
|
entry(%x : $D):
|
|
return undef : $D
|
|
}
|