File: access_marker_verify_objc.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (69 lines) | stat: -rw-r--r-- 4,579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// RUN: %target-swift-frontend -enforce-exclusivity=checked -import-objc-header %S/Inputs/access_marker_verify_objc.h -Onone -emit-silgen -swift-version 4 -parse-as-library %s | %FileCheck %s
// RUN: %target-swift-frontend -enable-verify-exclusivity -enforce-exclusivity=checked -import-objc-header %S/Inputs/access_marker_verify_objc.h -Onone -emit-sil -swift-version 4 -parse-as-library %s
// REQUIRES: asserts
// REQUIRES: OS=macosx

// Test the combination of SILGen + DiagnoseStaticExclusivity with verification.
//
// This augments access_marker_verify with tests that require ObjC or
// CoreFoundation.
import Foundation

// --- initializer `let` of CFString.
// The verifier should ignore this.

// CHECK-LABEL: sil private {{.*}}WZ : $@convention(c) (Builtin.RawPointer) -> () {
// CHECK: bb0(%0 : $Builtin.RawPointer):
// CHECK:   alloc_global @$s25access_marker_verify_objc12testCFStringC8cfStringSo0F3RefavpZ
// CHECK:   [[GA:%.*]] = global_addr @$s25access_marker_verify_objc12testCFStringC8cfStringSo0F3RefavpZ : $*CFString
// CHECK-NOT: begin_access
// CHECK:   store %{{.*}} to [init] [[GA]] : $*CFString
// CHECK:   return %{{.*}} : $()                               
// CHECK-LABEL: } // end sil function '{{.*}}WZ'
class testCFString {
  public static let cfString: CFString = "" as CFString
}

// --- objC method.
// The verifier should be able to handle a thunk of a block and ignore
// an incoming block argument.
@objc protocol HasBlock {
  func block(_: (Int) -> Int)
}

class HasBlockImpl: HasBlock {
  @objc func block(_: (Int) -> Int) {}
}
// CHECK-LABEL: sil private [thunk] [ossa] @$s25access_marker_verify_objc12HasBlockImplC5blockyyS2iXEFTo : $@convention(objc_method) (@convention(block) @noescape (Int) -> Int, HasBlockImpl) -> () {
// CHECK: bb0(%0 : @unowned $@convention(block) @noescape (Int) -> Int, %1 : @unowned $HasBlockImpl):
// CHECK:   [[CP:%.*]] = copy_block %0 : $@convention(block) @noescape (Int) -> Int
            // function_ref thunk for @callee_unowned @convention(block) (@unowned Int) -> (@unowned Int)
// CHECK:   [[THUNK:%.*]] = function_ref @$sS2iIyByd_S2iIegyd_TR : $@convention(thin) (Int, @guaranteed @convention(block) @noescape (Int) -> Int) -> Int
// CHECK:   [[PA:%.*]] = partial_apply [callee_guaranteed] [[THUNK]]([[CP]]) : $@convention(thin) (Int, @guaranteed @convention(block) @noescape (Int) -> Int) -> Int
// CHECK:   [[CVT:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PA]] : $@callee_guaranteed (Int) -> Int to $@noescape @callee_guaranteed (Int) -> Int
// CHECK:   [[CVTB:%.*]] = begin_borrow [[CVT]]
// CHECK:   [[F:%.*]] = function_ref @$s25access_marker_verify_objc12HasBlockImplC5blockyyS2iXEF : $@convention(method) (@guaranteed @noescape @callee_guaranteed (Int) -> Int, @guaranteed HasBlockImpl) -> ()
// CHECK:   %{{.*}} = apply [[F]]([[CVTB]], %{{.*}}) : $@convention(method) (@guaranteed @noescape @callee_guaranteed (Int) -> Int, @guaranteed HasBlockImpl) -> ()
// CHECK:   return %{{.*}} : $()                                
// CHECK-LABEL: } // end sil function '$s25access_marker_verify_objc12HasBlockImplC5blockyyS2iXEFTo'

// thunk for @callee_unowned @convention(block) (@unowned Int) -> (@unowned Int)
// CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sS2iIyByd_S2iIegyd_TR : $@convention(thin) (Int, @guaranteed @convention(block) @noescape (Int) -> Int) -> Int {
// CHECK: bb0(%0 : $Int, %1 : @guaranteed $@convention(block) @noescape (Int) -> Int):
// CHECK:   %{{.*}} = apply %1(%0) : $@convention(block) @noescape (Int) -> Int
// CHECK:  return %{{.*}} : $Int                               
// CHECK-LABEL: } // end sil function '$sS2iIyByd_S2iIegyd_TR'

// --- C global.
// The verifier should ignore this access.
// CHECK-LABEL: sil hidden [ossa] @$s25access_marker_verify_objc14GlobalPropertyC14globalCFStringSo0H3RefavgZ : $@convention(method) (@thick GlobalProperty.Type) -> @owned CFString {
// CHECK: bb0(%0 : $@thick GlobalProperty.Type):
// CHECK:   [[GA:%.*]] = global_addr @constCGlobal : $*Optional<CFString>
// CHECK:   [[STR:%.*]] = load [copy] [[GA]] : $*Optional<CFString>            
// CHECK: switch_enum [[STR]] : $Optional<CFString>, case #Optional.some!enumelt: [[SOMEBB:bb.*]], case #Optional.none!enumelt: bb{{.*}}
// CHECK:   [[SOMEBB]]([[R:%.*]] : @owned $CFString):
// CHECK:   return [[R]] : $CFString
// CHECK-LABEL: } // end sil function '$s25access_marker_verify_objc14GlobalPropertyC14globalCFStringSo0H3RefavgZ'
class GlobalProperty {
  public class var globalCFString: CFString { return constCGlobal }
}