mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This allows to eliminate a dead stack location which contains an existential. rdar://problem/32272199
32 lines
698 B
Swift
32 lines
698 B
Swift
// RUN: %target-swift-frontend -O -emit-sil -parse-as-library %s | %FileCheck %s
|
|
|
|
protocol E {
|
|
func f() -> Bool
|
|
}
|
|
|
|
protocol P {
|
|
associatedtype A = Int
|
|
}
|
|
|
|
public struct X : P, E {
|
|
func f() -> Bool { return true }
|
|
}
|
|
|
|
func g<T : P>(_ x : T) -> Bool {
|
|
if let y = x as? E { return y.f() }
|
|
return false
|
|
}
|
|
|
|
// Check that this function can be completely constant folded and no alloc_stack remains.
|
|
|
|
// CHECK-LABEL: sil @$s16dead_alloc_stack6testitySbAA1XVF
|
|
// CHECK: bb0({{.*}}):
|
|
// CHECK-NEXT: integer_literal
|
|
// CHECK-NEXT: struct
|
|
// CHECK-NEXT: return
|
|
// CHECK-NEXT: } // end sil function '$s16dead_alloc_stack6testitySbAA1XVF'
|
|
public func testit(_ x: X) -> Bool {
|
|
return g(x)
|
|
}
|
|
|