mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
35 lines
1.2 KiB
Plaintext
35 lines
1.2 KiB
Plaintext
// RUN: %target-swift-frontend -O -emit-ir %s | %FileCheck %s
|
|
//
|
|
// Test LLVM ARC Optimization
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
typealias AnyObject = Builtin.AnyObject
|
|
|
|
sil @getObject : $@convention(thin) <T where T : AnyObject> () -> T
|
|
|
|
// Test swift_getObjCClassFromObject side-effects. It reads the object
|
|
// argument. A release cannot be hoisted above it.
|
|
//
|
|
// CHECK-LABEL: define {{.*}}swiftcc ptr @testGetObjCClassFromObjectSideEffect(ptr %T)
|
|
// CHECK: entry:
|
|
// CHECK-NEXT: %0 = tail call swiftcc ptr @getObject(ptr %T)
|
|
// CHECK-NEXT: %.Type = tail call ptr @swift_getObjCClassFromObject(ptr %0)
|
|
// CHECK-NEXT: tail call void @swift_unknownObjectRelease(ptr %0)
|
|
// CHECK: ret ptr %.Type
|
|
// CHECK: }
|
|
sil @testGetObjCClassFromObjectSideEffect : $@convention(thin) <T where T : AnyObject> () -> @objc_metatype T.Type {
|
|
bb0:
|
|
%f = function_ref @getObject : $@convention(thin) <τ_0_0 where τ_0_0 : AnyObject> () -> τ_0_0
|
|
%obj = apply %f<T>() : $@convention(thin) <τ_0_0 where τ_0_0 : AnyObject> () -> τ_0_0
|
|
%mt = value_metatype $@objc_metatype T.Type, %obj : $T
|
|
// Do not hoist this release.
|
|
strong_release %obj : $T
|
|
return %mt : $@objc_metatype T.Type
|
|
}
|