File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -427,13 +427,16 @@ class HoistAllocStack {
427
427
};
428
428
} // end anonymous namespace
429
429
430
- bool indicatesDynamicAvailabilityCheckUse (SILInstruction *I) {
430
+ bool inhibitsAllocStackHoisting (SILInstruction *I) {
431
431
if (auto *Apply = dyn_cast<ApplyInst>(I)) {
432
432
return Apply->hasSemantics (semantics::AVAILABILITY_OSVERSION);
433
433
}
434
434
if (auto *bi = dyn_cast<BuiltinInst>(I)) {
435
435
return bi->getBuiltinInfo ().ID == BuiltinValueKind::TargetOSVersionAtLeast;
436
436
}
437
+ if (isa<HasSymbolInst>(I)) {
438
+ return true ;
439
+ }
437
440
return false ;
438
441
}
439
442
@@ -453,8 +456,10 @@ void HoistAllocStack::collectHoistableInstructions() {
453
456
FunctionExits.push_back (Term);
454
457
continue ;
455
458
}
456
- // Don't perform alloc_stack hoisting in functions with availability.
457
- if (indicatesDynamicAvailabilityCheckUse (&Inst)) {
459
+ // Don't perform alloc_stack hoisting in functions containing
460
+ // instructions that indicate hoisting may be unsafe (e.g. `if
461
+ // #available(...)` or `if #_hasSymbol(...)`.
462
+ if (inhibitsAllocStackHoisting (&Inst)) {
458
463
AllocStackToHoist.clear ();
459
464
return ;
460
465
}
Original file line number Diff line number Diff line change @@ -257,3 +257,26 @@ bb3:
257
257
return %3 : $()
258
258
}
259
259
260
+ // CHECK-LABEL: sil @dont_hoist_with_has_symbol_checks
261
+ // CHECK-NOT: alloc_stack
262
+ // CHECK: cond_br
263
+ // CHECK: bb1:
264
+ // CHECK: alloc_stack
265
+ // CHECK: } // end sil function 'dont_hoist_with_has_symbol_checks'
266
+ sil @dont_hoist_with_has_symbol_checks : $@convention(thin) <T> (@in T, Builtin.Int1) -> () {
267
+ bb0(%0 : $*T, %1: $Builtin.Int1):
268
+ %5 = has_symbol #FixedSize.init
269
+ cond_br %5, bb1, bb2
270
+ bb1:
271
+ %2 = alloc_stack $T
272
+ copy_addr [take] %0 to [init] %2 : $*T
273
+ destroy_addr %2 : $*T
274
+ dealloc_stack %2 : $*T
275
+ br bb3
276
+ bb2:
277
+ destroy_addr %0 : $*T
278
+ br bb3
279
+ bb3:
280
+ %3 = tuple ()
281
+ return %3 : $()
282
+ }
You can’t perform that action at this time.
0 commit comments