blob: ff2c9f42e2697cb0da8c3ce1f9d3917b03209b0a [file] [log] [blame]
// RUN: %target-swift-frontend %s -parse-as-library -O -emit-sil | %FileCheck %s
// RUN: %target-swift-frontend %s -parse-as-library -Osize -emit-sil | %FileCheck %s --check-prefix=OSIZE
//
// Test speculative devirtualization.
// Test MaxNumSpeculativeTargets.
// rdar:23228386
public class Base {
public init() {}
public func foo() {}
}
class Sub1 : Base {
override func foo() {}
}
class Sub2 : Base {
override func foo() {}
}
class Sub3 : Base {
override func foo() {}
}
class Sub4 : Base {
override func foo() {}
}
class Sub5 : Base {
override func foo() {}
}
class Sub6 : Base {
override func foo() {}
}
class Sub7 : Base {
override func foo() {}
}
// CHECK: @_T016devirt_speculate28testMaxNumSpeculativeTargetsyAA4BaseCF
// CHECK: checked_cast_br [exact] %0 : $Base to $Base
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub1
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub2
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub3
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub4
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub5
// CHECK: checked_cast_br [exact] %0 : $Base to $Sub6
// CHECK-NOT: checked_cast_br
// CHECK: %[[CM:[0-9]+]] = class_method %0 : $Base, #Base.foo!1 : (Base) -> () -> (), $@convention(method) (@guaranteed Base) -> ()
// CHECK: apply %[[CM]](%0) : $@convention(method) (@guaranteed Base) -> ()
// OSIZE: @_T016devirt_speculate28testMaxNumSpeculativeTargetsyAA4BaseCF
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Base
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Sub
public func testMaxNumSpeculativeTargets(_ b: Base) {
b.foo()
}