Skip to content

Commit d895c34

Browse files
committed
[Test] Add regression test.
1 parent ac5ae3c commit d895c34

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(-Xfrontend -sil-verify-all)
2+
// RUN: %target-run-simple-swift(-O -Xfrontend -sil-verify-all)
3+
4+
// REQUIRES: executable_test
5+
6+
/// A unique value represented by a heap memory location.
7+
struct Handle: ~Copyable {
8+
var address: UnsafeMutableRawPointer
9+
10+
init() {
11+
self.address = .allocate(byteCount: 2, alignment: 2)
12+
}
13+
14+
consuming func done() {
15+
let address = self.address
16+
discard self
17+
address.deallocate()
18+
print("deallocated handle via done()")
19+
}
20+
21+
deinit {
22+
address.deallocate()
23+
print("deallocated handle via deinit")
24+
}
25+
}
26+
27+
func description(of pointer: UnsafeRawPointer) -> String {
28+
let address = UInt(bitPattern: pointer)
29+
return "0x" + String(address, radix: 16)
30+
}
31+
32+
func borrowHandleAndCrashNoMore(_ handle: borrowing Handle) -> String {
33+
var string = ""
34+
return string.withUTF8 { _ in
35+
description(of: handle.address)
36+
}
37+
}
38+
39+
let handleDescription: String
40+
41+
do {
42+
let handle = Handle()
43+
handleDescription = borrowHandleAndCrashNoMore(handle)
44+
handle.done()
45+
}
46+
47+
// CHECK: result: 0x
48+
print("result: \(handleDescription)")

0 commit comments

Comments
 (0)