Skip to content

Commit c2374f0

Browse files
committed
Add unit test for ARCSequenceOpts with optimizable arc ops around
try_apply
1 parent 1ec1c0e commit c2374f0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/SILOptimizer/arcsequenceopts.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ bb0(%0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>):
405405
return %1 : $()
406406
}
407407

408+
sil @guaranteed_box_throwing_use : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Builtin.Int64>) -> @error Error {
409+
bb0(%0 : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>):
410+
%1 = tuple ()
411+
return %1 : $()
412+
}
413+
408414
// CHECK_LABEL: sil hidden [noinline] @$test_guaranteed_call :
409415
// CHECK: bb1{{.*}}:
410416
// CHECK-NOT: strong_retain
@@ -2157,6 +2163,30 @@ bb2(%4 : $Error):
21572163
throw %4 : $Error
21582164
}
21592165

2166+
// CHECK_LABEL: sil hidden [noinline] @$try_apply_test_3 :
2167+
// CHECK-NOT: strong_retain
2168+
// CHECK-NOT: strong_release
2169+
// CHECK_LABEL: } // end sil function '$try_apply_test_3'
2170+
sil hidden [noinline] @$try_apply_test_3 : $@convention(thin) () -> @error Error {
2171+
bb0:
2172+
%box = alloc_box $<τ_0_0> { var τ_0_0 } <Builtin.Int64>
2173+
%proj = project_box %box : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>, 0
2174+
%funcref = function_ref @guaranteed_box_throwing_use : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Builtin.Int64>) -> @error Error
2175+
br bb1
2176+
2177+
bb1:
2178+
strong_retain %box : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>
2179+
try_apply %funcref (%box) : $@convention(thin) (@guaranteed <τ_0_0> { var τ_0_0 } <Builtin.Int64>) -> @error Error, normal bbs, error bbe
2180+
2181+
bbs(%s : $()):
2182+
strong_release %box : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>
2183+
return undef : $()
2184+
2185+
bbe(%e : $Error):
2186+
strong_release %box : $<τ_0_0> { var τ_0_0 } <Builtin.Int64>
2187+
throw %e : $Error
2188+
}
2189+
21602190
// In this control flow, ARC runs multiple iterations to get rid of and move the retain and releases.
21612191
// In the first iteration, we will try to move id1/id3 towards each other.
21622192
// we create new instructions and remove the old ones. However we had a bug to insert these newly created

0 commit comments

Comments
 (0)