Skip to content

Commit 4678567

Browse files
committed
Fix a bunch of test cases with illegal OSSA
Borrowing an unowned value is illegal.
1 parent 5b37728 commit 4678567

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

test/IRGen/async/builtins.sil

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
3535
// CHECK-LABEL: define hidden swiftcc void @launch_task
3636
sil hidden [ossa] @launch_task : $@convention(method) @async (Int, Optional<Builtin.NativeObject>, @guaranteed @async @callee_guaranteed () -> (@error Error)) -> () {
3737
bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@async @callee_guaranteed () -> (@error Error)):
38-
%3 = begin_borrow %1 : $Optional<Builtin.NativeObject>
39-
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]])
38+
%copy = copy_value %1 : $Optional<Builtin.NativeObject>
39+
%3 = begin_borrow %copy : $Optional<Builtin.NativeObject>
40+
// CHECK: [[FN_CONTEXT:%.*]] = load %swift.refcounted*, %swift.refcounted** %.data
41+
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT]])
4042
// CHECK: [[NEW_TASK_AND_CONTEXT:%.*]] = call swiftcc %swift.async_task_and_context @swift_task_create_f(
4143
// CHECK-NEXT: [[NEW_CONTEXT_RAW:%.*]] = extractvalue %swift.async_task_and_context [[NEW_TASK_AND_CONTEXT]], 1
4244
// CHECK-NEXT: [[NEW_CONTEXT:%.*]] = bitcast %swift.context* [[NEW_CONTEXT_RAW]] to
4345
// CHECK-NEXT: [[CONTEXT_INFO_LOC:%.*]] = getelementptr inbounds <{{.*}}>* [[NEW_CONTEXT]]
4446
// CHECK-NEXT: store %swift.refcounted* [[FN_CONTEXT]], %swift.refcounted** [[CONTEXT_INFO_LOC]]
4547
%20 = builtin "createAsyncTask"(%0 : $Int, %3 : $Optional<Builtin.NativeObject>, %2 : $@async @callee_guaranteed () -> (@error Error)) : $(Builtin.NativeObject, Builtin.RawPointer)
4648
end_borrow %3 : $Optional<Builtin.NativeObject>
49+
destroy_value %copy : $Optional<Builtin.NativeObject>
4750
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
4851
%21 = tuple ()
4952
return %21 : $()
@@ -52,7 +55,11 @@ bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@a
5255
// CHECK-LABEL: define hidden swiftcc void @launch_future
5356
sil hidden [ossa] @launch_future : $@convention(method) <T> (Int, Optional<Builtin.NativeObject>, @guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>, @in_guaranteed T) -> () {
5457
bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>, %3: $*T):
55-
%4 = begin_borrow %1 : $Optional<Builtin.NativeObject>
58+
%copy = copy_value %1 : $Optional<Builtin.NativeObject>
59+
// CHECK-32: [[TEMP:%.*]] = inttoptr i32 %1 to %swift.refcounted*
60+
// CHECK-64: [[TEMP:%.*]] = inttoptr i64 %1 to %swift.refcounted*
61+
%4 = begin_borrow %copy : $Optional<Builtin.NativeObject>
62+
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[TEMP]])
5663
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]])
5764
%9 = metatype $@thick T.Type
5865
%10 = init_existential_metatype %9 : $@thick T.Type, $@thick Any.Type
@@ -64,14 +71,20 @@ bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@a
6471
// CHECK-NEXT: store %swift.refcounted* [[FN_CONTEXT]], %swift.refcounted** [[CONTEXT_INFO_LOC]]
6572
%20 = builtin "createAsyncTaskFuture"<T>(%0 : $Int, %4 : $Optional<Builtin.NativeObject>, %10 : $@thick Any.Type, %2 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <T>) : $(Builtin.NativeObject, Builtin.RawPointer)
6673
end_borrow %4 : $Optional<Builtin.NativeObject>
74+
destroy_value %copy : $Optional<Builtin.NativeObject>
6775
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
6876
%21 = tuple ()
6977
return %21 : $()
7078
}
7179

80+
// CHECK-LABEL: define hidden swiftcc void @launch_void_future
7281
sil hidden [ossa] @launch_void_future : $@convention(method) (Int, Optional<Builtin.NativeObject>, @guaranteed @async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) -> () {
7382
bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>):
74-
%4 = begin_borrow %1 : $Optional<Builtin.NativeObject>
83+
%copy = copy_value %1 : $Optional<Builtin.NativeObject>
84+
%4 = begin_borrow %copy : $Optional<Builtin.NativeObject>
85+
// CHECK-32: [[TEMP:%.*]] = inttoptr i32 %1 to %swift.refcounted*
86+
// CHECK-64: [[TEMP:%.*]] = inttoptr i64 %1 to %swift.refcounted*
87+
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[TEMP]])
7588
// CHECK: call %swift.refcounted* @swift_retain(%swift.refcounted* returned [[FN_CONTEXT:%.*]])
7689
%8 = metatype $@thick ().Type // user: %9
7790
%9 = init_existential_metatype %8 : $@thick ().Type, $@thick Any.Type // user: %10
@@ -83,6 +96,7 @@ bb0(%0 : $Int, %1: @unowned $Optional<Builtin.NativeObject>, %2: @guaranteed $@a
8396
// CHECK-NEXT: store %swift.refcounted* [[FN_CONTEXT]], %swift.refcounted** [[CONTEXT_INFO_LOC]]
8497
%20 = builtin "createAsyncTaskFuture"<()>(%0 : $Int, %4 : $Optional<Builtin.NativeObject>, %9 : $@thick Any.Type, %2 : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@out τ_0_0, @error Error) for <()>) : $(Builtin.NativeObject, Builtin.RawPointer)
8598
end_borrow %4 : $Optional<Builtin.NativeObject>
99+
destroy_value %copy : $Optional<Builtin.NativeObject>
86100
destroy_value %20 : $(Builtin.NativeObject, Builtin.RawPointer)
87101
%21 = tuple ()
88102
return %21 : $()

test/IRGen/objc_dealloc.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bb0(%0 : @owned $SwiftGizmo):
5050

5151
sil [ossa] @$s12objc_dealloc10SwiftGizmoC1xAA1XCfgTo : $@convention(objc_method) (SwiftGizmo) -> @autoreleased X {
5252
bb0(%0 : @unowned $SwiftGizmo):
53-
%1 = begin_borrow %0 : $SwiftGizmo
53+
%1 = unchecked_ownership_conversion %0 : $SwiftGizmo, @unowned to @guaranteed
5454
%2 = ref_element_addr %1 : $SwiftGizmo, #SwiftGizmo.x // user: %2
5555
%3 = load [copy] %2 : $*X // users: %4, %3
5656
end_borrow %1 : $SwiftGizmo
@@ -92,7 +92,7 @@ bb0(%0 : @unowned $SwiftGizmo):
9292
// CHECK-NEXT: [[XADDR:%[.a-zA-Z0-9]+]] = bitcast i8* [[IVAR_ADDR]] to %T12objc_dealloc1XC**
9393
// CHECK-NEXT: [[X:%[a-zA-Z0-9]+]] = load %T12objc_dealloc1XC*, %T12objc_dealloc1XC** [[XADDR]], align 8
9494
// CHECK-NEXT: call void bitcast (void (%swift.refcounted*)* @swift_release to void (%T12objc_dealloc1XC*)*)(%T12objc_dealloc1XC* [[X]])
95-
%3 = begin_borrow %0 : $SwiftGizmo
95+
%3 = unchecked_ownership_conversion %0 : $SwiftGizmo, @unowned to @guaranteed
9696
%4 = ref_element_addr %3 : $SwiftGizmo, #SwiftGizmo.x // user: %4
9797
destroy_addr %4 : $*X // id: %4
9898
end_borrow %3 : $SwiftGizmo

test/SIL/ownership-verifier/borrow_cast_validate.sil

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ bb0(%0 : @guaranteed $Optional<Klass>):
135135
return %res : $()
136136
}
137137

138-
// CHECK-NOT: Function: 'bitwise_cast_borrow_dest'
138+
// CHECK-LABEL: Error#: 0. Begin Error in Function: 'bitwise_cast_borrow_dest'
139+
// CHECK: Have operand with incompatible ownership?!
140+
// CHECK: Value: %2 = unchecked_bitwise_cast %1 : $Pair to $AnyObject // user: %3
141+
// CHECK: User: %3 = begin_borrow %2 : $AnyObject // users: %6, %5
142+
// CHECK: Conv: unowned
143+
// CHECK-LABEL: Error#: 0. End Error in Function: 'bitwise_cast_borrow_dest'
139144
sil [ossa] @bitwise_cast_borrow_dest : $@convention(thin) (@guaranteed Pair) -> () {
140145
bb0(%0 : @guaranteed $Pair):
141146
%1 = copy_value %0 : $Pair

test/SILGen/objc_dealloc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SwiftGizmo : Gizmo {
7878
// CHECK-LABEL: sil hidden [ossa] @$s12objc_dealloc10SwiftGizmoCfETo : $@convention(objc_method) (SwiftGizmo) -> ()
7979
// CHECK: bb0([[SELF:%[0-9]+]] : @unowned $SwiftGizmo):
8080
// CHECK-NEXT: debug_value [[SELF]] : $SwiftGizmo, let, name "self"
81-
// CHECK-NEXT: [[SELF_BORROW:%.*]] = begin_borrow [[SELF]]
81+
// CHECK-NEXT: [[SELF_BORROW:%.*]] = unchecked_ownership_conversion %0 : $SwiftGizmo, @unowned to @guaranteed
8282
// CHECK-NEXT: [[X:%[0-9]+]] = ref_element_addr [[SELF_BORROW]] : $SwiftGizmo, #SwiftGizmo.x
8383
// CHECK-NEXT: [[X_ACCESS:%.*]] = begin_access [deinit] [static] [[X]]
8484
// CHECK-NEXT: destroy_addr [[X_ACCESS]]

0 commit comments

Comments
 (0)