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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// RUN: %target-swift-frontend -swift-version 4 -enforce-exclusivity=checked %s -emit-ir | %FileCheck %s --check-prefix=CHECK
sil_stage canonical
import Builtin
import Swift
class A {
@_hasStorage var property: Int64 { get set }
@_hasStorage var exProperty: Any { get set }
deinit
init()
}
// CHECK-DAG: [[C:%T14access_markers1AC]] = type
// CHECK-DAG: [[INT:%Ts5Int64V]] = type <{ i64 }>
sil_vtable A {}
sil @int_user : $@convention(thin) (Int64, Int64) -> ()
// CHECK-LABEL: define {{.*}} @testPaired(
sil [ossa] @testPaired : $(@guaranteed A) -> () {
bb0(%0 : @guaranteed $A):
%func = function_ref @int_user : $@convention(thin) (Int64, Int64) -> ()
// CHECK: [[SCRATCH1:%.*]] = alloca [[BUFFER:.* x i8.]], align
// CHECK: [[SCRATCH2:%.*]] = alloca [[BUFFER]], align
// CHECK: [[PROPERTY:%.*]] = getelementptr inbounds [[C]], ptr %0, i32 0, i32 1
%2 = ref_element_addr %0 : $A, #A.property
// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 {{.*}}, ptr [[SCRATCH1]])
// CHECK-NEXT: call void @swift_beginAccess(ptr [[PROPERTY]], ptr [[SCRATCH1]], [[SIZE:i(32|64)]] 33, ptr null)
%3 = begin_access [modify] [dynamic] %2 : $*Int64
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, ptr [[PROPERTY]], i32 0, i32 0
// CHECK-NEXT: load i64, ptr
%4 = load [trivial] %3 : $*Int64
// CHECK-NEXT: call void @swift_endAccess(ptr [[SCRATCH1]])
// CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 {{.*}}, ptr [[SCRATCH1]])
end_access %3 : $*Int64
// CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 {{.*}}, ptr [[SCRATCH2]])
// CHECK-NEXT: call void @swift_beginAccess(ptr [[PROPERTY]], ptr [[SCRATCH2]], [[SIZE]] 32, ptr null)
%6 = begin_access [read] [dynamic] %2 : $*Int64
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, ptr [[PROPERTY]], i32 0, i32 0
// CHECK-NEXT: load i64, ptr
%7 = load [trivial] %6 : $*Int64
// CHECK-NEXT: call void @swift_endAccess(ptr [[SCRATCH2]])
// CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 {{.*}}, ptr [[SCRATCH2]])
end_access %6 : $*Int64
apply %func(%4, %7) : $@convention(thin) (Int64, Int64) -> ()
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: define {{.*}}void @testUnpaired(
sil @testUnpaired : $(@guaranteed A) -> () {
bb0(%0 : $A):
// CHECK: [[SCRATCH:%.*]] = alloca [[BUFFER:.* x i8.]], align
%1 = alloc_stack $Builtin.UnsafeValueBuffer
// CHECK: [[PROPERTY:%.*]] = getelementptr inbounds [[C]], ptr %0, i32 0, i32 1
%2 = ref_element_addr %0 : $A, #A.property
// CHECK-NEXT: call void @swift_beginAccess(ptr [[PROPERTY]], ptr [[SCRATCH]], [[SIZE]] 33, ptr null)
begin_unpaired_access [modify] [dynamic] %2 : $*Int64, %1 : $*Builtin.UnsafeValueBuffer
// CHECK-NEXT: call void @swift_endAccess(ptr [[SCRATCH]])
end_unpaired_access [dynamic] %1 : $*Builtin.UnsafeValueBuffer
// CHECK-NEXT: call void @swift_beginAccess(ptr [[PROPERTY]], ptr [[SCRATCH]], [[SIZE]] 32, ptr null)
begin_unpaired_access [read] [dynamic] %2 : $*Int64, %1 : $*Builtin.UnsafeValueBuffer
// CHECK-NEXT: call void @swift_endAccess(ptr [[SCRATCH]])
end_unpaired_access [dynamic] %1 : $*Builtin.UnsafeValueBuffer
dealloc_stack %1 : $*Builtin.UnsafeValueBuffer
%20 = tuple ()
return %20 : $()
}
sil @writeEmptyTuple : $(@inout ()) -> ()
sil @readEmptyTuple : $(@in_guaranteed ()) -> ()
// rdar://32039394 - Don't apply dynamic enforcement to empty types.
// CHECK-LABEL: define {{.*}}void @testPairedBox(
sil @testPairedBox : $(@guaranteed { var () }) -> () {
bb0(%0 : ${ var () }):
// CHECK: entry:
%2 = project_box %0 : ${ var () }, 0
// CHECK-NEXT: call {{.*}}void @writeEmptyTuple(ptr nocapture undef)
%3 = begin_access [modify] [dynamic] %2 : $*()
%write_fn = function_ref @writeEmptyTuple : $@convention(thin) (@inout ()) -> ()
apply %write_fn(%3) : $@convention(thin) (@inout ()) -> ()
end_access %3 : $*()
// CHECK-NEXT: call {{.*}}void @readEmptyTuple(ptr noalias nocapture undef)
%5 = begin_access [read] [dynamic] %2 : $*()
%read_fn = function_ref @readEmptyTuple : $@convention(thin) (@in_guaranteed ()) -> ()
apply %read_fn(%5) : $@convention(thin) (@in_guaranteed ()) -> ()
end_access %5 : $*()
// CHECK-NEXT: ret void
%20 = tuple ()
return %20 : $()
}
// rdar://31964550
// Just check that this doesn't crash.
sil @testCopyAddr : $(@guaranteed A) -> () {
bb0(%0 : $A):
%1 = alloc_stack $Any
%2 = ref_element_addr %0 : $A, #A.exProperty
%3 = begin_access [dynamic] [read] %2 : $*Any
copy_addr %2 to [init] %1 : $*Any
end_access %3 : $*Any
destroy_addr %1 : $*Any
dealloc_stack %1 : $*Any
%20 = tuple ()
return %20 : $()
}
// CHECK-LABEL: define {{.*}}void @testNontracking(
sil @testNontracking : $(@guaranteed A) -> () {
bb0(%0 : $A):
%1 = alloc_stack $Int64
// CHECK: [[PROPERTY:%.*]] = getelementptr inbounds [[C]], ptr %0, i32 0, i32 1
%2 = ref_element_addr %0 : $A, #A.property
// CHECK: call void @swift_beginAccess(ptr %{{.*}}, ptr %{{.*}}, [[SIZE]] 0, ptr null)
%3 = begin_access [read] [dynamic] [no_nested_conflict] %2 : $*Int64
copy_addr %3 to [init] %1 : $*Int64
// CHECK-NOT: end_access
end_access %3 : $*Int64
%9 = alloc_stack $Builtin.UnsafeValueBuffer
// CHECK: call void @swift_beginAccess(ptr %{{.*}}, ptr %{{.*}}, [[SIZE]] 0, ptr null)
begin_unpaired_access [read] [dynamic] [no_nested_conflict] %2 : $*Int64, %9 : $*Builtin.UnsafeValueBuffer
copy_addr %2 to %1 : $*Int64
dealloc_stack %9 : $*Builtin.UnsafeValueBuffer
dealloc_stack %1 : $*Int64
%20 = tuple ()
return %20 : $()
}
|