Skip to content

Commit 7e0b218

Browse files
committed
[Test] Added optimization test case.
rdar://92652273
1 parent 8f893fc commit 7e0b218

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-run-simple-swift | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
// REQUIRES: optimized_stdlib
5+
// REQUIRES: swift_test_mode_optimize
6+
7+
struct Consumer {
8+
let store: [Int]
9+
@inline(__always)
10+
init(_ x: [Int]) {
11+
var y = x
12+
y[0] = 42
13+
store = y
14+
}
15+
}
16+
17+
typealias PInt = UnsafePointer<Int>
18+
@inline(never)
19+
func baseAddress(_ a: PInt) -> PInt { a }
20+
21+
extension Optional {
22+
@inline(__always)
23+
mutating func release() -> Wrapped {
24+
defer { self = nil }
25+
return self!
26+
}
27+
}
28+
29+
@inline(never)
30+
func main(_ a: inout [Int]?) -> [Int] {
31+
let x = a.release()
32+
let r = Consumer(x).store
33+
return r
34+
}
35+
36+
func test() {
37+
var a = Optional(Array(0...3))
38+
let b0 = baseAddress(a!)
39+
let b = main(&a)
40+
let b1 = baseAddress(b)
41+
// CHECK: true
42+
print(b0 == b1)
43+
// CHECK: nil [42, 1, 2, 3]
44+
print(a as Any, b)
45+
}
46+
47+
test()
48+

0 commit comments

Comments
 (0)