File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
validation-test/SILOptimizer Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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) " )
You can’t perform that action at this time.
0 commit comments