@@ -1356,3 +1356,58 @@ bb0:
13561356 %22 = tuple ()
13571357 return %22 : $()
13581358}
1359+
1360+ sil @paable : $@convention(thin) (Builtin.Int64) -> ()
1361+
1362+ final class FC {
1363+ @_hasStorage @_hasInitialValue final var storage: Optional<Builtin.Int64>
1364+ }
1365+
1366+ sil @consume_int64 : $@convention(thin) (Builtin.Int64) -> ()
1367+
1368+ sil [lazy_getter] [ossa] @partial_apply_on_stack_nesting_violator : $@convention(method) (@guaranteed FC) -> Builtin.Int64 {
1369+ entry(%instance : @guaranteed $FC):
1370+ %storage_addr = ref_element_addr %instance : $FC, #FC.storage
1371+ %optional = load [trivial] %storage_addr : $*Optional<Builtin.Int64>
1372+ switch_enum %optional : $Optional<Builtin.Int64>, case #Optional.some!enumelt: some, case #Optional.none!enumelt: none
1373+ none:
1374+ %one = integer_literal $Builtin.Int64, 1
1375+ %optone = enum $Optional<Builtin.Int64>, #Optional.some!enumelt, %one : $Builtin.Int64
1376+ store %optone to [trivial] %storage_addr : $*Optional<Builtin.Int64>
1377+ br exit(%one : $Builtin.Int64)
1378+
1379+ some(%value : $Builtin.Int64):
1380+ %paable = function_ref @paable : $@convention(thin) (Builtin.Int64) -> ()
1381+ %first = partial_apply [callee_guaranteed] [on_stack] %paable(%value) : $@convention(thin) (Builtin.Int64) -> ()
1382+ %second = partial_apply [callee_guaranteed] [on_stack] %paable(%value) : $@convention(thin) (Builtin.Int64) -> ()
1383+ // Note that the destroy_values do not occur in an order which coincides
1384+ // with stack disciplined dealloc_stacks.
1385+ destroy_value %first : $@noescape @callee_guaranteed () -> ()
1386+ destroy_value %second : $@noescape @callee_guaranteed () -> ()
1387+ br exit(%value : $Builtin.Int64)
1388+
1389+ exit(%retval : $Builtin.Int64):
1390+ return %retval : $Builtin.Int64
1391+ }
1392+
1393+ // Verify that when inlining partial_apply_on_stack_nesting_violator, the stack
1394+ // nesting of the on_stack closures is fixed.
1395+ // CHECK-LABEL: sil @test_inline_stack_violating_ossa_func : {{.*}} {
1396+ // CHECK: [[PAABLE:%[^,]+]] = function_ref @paable
1397+ // CHECK: [[FIRST:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
1398+ // CHECK: [[SECOND:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
1399+ // CHECK: dealloc_stack [[SECOND]]
1400+ // CHECK: dealloc_stack [[FIRST]]
1401+ // CHECK-LABEL: } // end sil function 'test_inline_stack_violating_ossa_func'
1402+ sil @test_inline_stack_violating_ossa_func : $@convention(thin) (FC) -> () {
1403+ entry(%instance : $FC):
1404+ %callee = function_ref @partial_apply_on_stack_nesting_violator : $@convention(method) (@guaranteed FC) -> Builtin.Int64
1405+ %consume = function_ref @consume_int64 : $@convention(thin) (Builtin.Int64) -> ()
1406+ %first = apply %callee(%instance) : $@convention(method) (@guaranteed FC) -> Builtin.Int64
1407+ apply %consume(%first) : $@convention(thin) (Builtin.Int64) -> ()
1408+ %second = apply %callee(%instance) : $@convention(method) (@guaranteed FC) -> Builtin.Int64
1409+ apply %consume(%second) : $@convention(thin) (Builtin.Int64) -> ()
1410+ %retval = tuple ()
1411+ return %retval : $()
1412+ }
1413+
0 commit comments