@@ -449,50 +449,58 @@ void SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
449449
450450 SmallVector<SILValue, 4 > entryArgs;
451451 entryArgs.reserve (AppliedArgs.size ());
452+
453+ auto calleeConv = getCalleeFunction ()->getConventions ();
452454 SmallBitVector borrowedArgs (AppliedArgs.size ());
453455 SmallBitVector copiedArgs (AppliedArgs.size ());
456+ if (!Apply->getFunction ()->hasOwnership ()) {
454457
455- auto calleeConv = getCalleeFunction ()->getConventions ();
456- for (auto p : llvm::enumerate (AppliedArgs)) {
457- SILValue callArg = p.value ();
458- SWIFT_DEFER { entryArgs.push_back (callArg); };
459- unsigned idx = p.index ();
460- if (idx >= calleeConv.getSILArgIndexOfFirstParam ()) {
461- auto paramInfo = calleeConv.getParamInfoForSILArg (idx);
462- if (callArg->getType ().isAddress ()) {
463- // If lexical lifetimes are enabled, any alloc_stacks in the caller that
464- // are passed to the callee being inlined (except mutating exclusive
465- // accesses) need to be promoted to be lexical. Otherwise,
466- // destroy_addrs could be hoisted through the body of the newly inlined
467- // function without regard to the deinit barriers it contains.
468- //
469- // TODO: [begin_borrow_addr] Instead of marking the alloc_stack as a
470- // whole lexical, just mark the inlined range lexical via
471- // begin_borrow_addr [lexical]/end_borrow_addr just as is done
472- // with values.
473- auto &module = Apply.getFunction ()->getModule ();
474- auto enableLexicalLifetimes =
475- module .getASTContext ().SILOpts .supportsLexicalLifetimes (module );
476- if (!enableLexicalLifetimes)
477- continue ;
478-
479- // Exclusive mutating accesses don't entail a lexical scope.
480- if (paramInfo.getConvention () == ParameterConvention::Indirect_Inout)
481- continue ;
482-
483- auto storage = AccessStorageWithBase::compute (callArg);
484- if (auto *asi = dyn_cast_or_null<AllocStackInst>(storage.base ))
485- asi->setIsLexical ();
486- } else {
487- // Insert begin/end borrow for guaranteed arguments.
488- if (paramInfo.isGuaranteed ()) {
489- if (SILValue newValue = borrowFunctionArgument (callArg, idx)) {
490- callArg = newValue;
491- borrowedArgs[idx] = true ;
492- }
493- } else if (paramInfo.isConsumed ()) {
494- if (SILValue newValue = moveFunctionArgument (callArg, idx)) {
495- callArg = newValue;
458+ for (auto p : llvm::enumerate (AppliedArgs)) {
459+ SILValue callArg = p.value ();
460+ entryArgs.push_back (callArg);
461+ }
462+ } else {
463+ for (auto p : llvm::enumerate (AppliedArgs)) {
464+ SILValue callArg = p.value ();
465+ SWIFT_DEFER { entryArgs.push_back (callArg); };
466+ unsigned idx = p.index ();
467+ if (idx >= calleeConv.getSILArgIndexOfFirstParam ()) {
468+ auto paramInfo = calleeConv.getParamInfoForSILArg (idx);
469+ if (callArg->getType ().isAddress ()) {
470+ // If lexical lifetimes are enabled, any alloc_stacks in the caller
471+ // that are passed to the callee being inlined (except mutating
472+ // exclusive accesses) need to be promoted to be lexical. Otherwise,
473+ // destroy_addrs could be hoisted through the body of the newly
474+ // inlined function without regard to the deinit barriers it contains.
475+ //
476+ // TODO: [begin_borrow_addr] Instead of marking the alloc_stack as a
477+ // whole lexical, just mark the inlined range lexical via
478+ // begin_borrow_addr [lexical]/end_borrow_addr just as is done
479+ // with values.
480+ auto &module = Apply.getFunction ()->getModule ();
481+ auto enableLexicalLifetimes =
482+ module .getASTContext ().SILOpts .supportsLexicalLifetimes (module );
483+ if (!enableLexicalLifetimes)
484+ continue ;
485+
486+ // Exclusive mutating accesses don't entail a lexical scope.
487+ if (paramInfo.getConvention () == ParameterConvention::Indirect_Inout)
488+ continue ;
489+
490+ auto storage = AccessStorageWithBase::compute (callArg);
491+ if (auto *asi = dyn_cast_or_null<AllocStackInst>(storage.base ))
492+ asi->setIsLexical ();
493+ } else {
494+ // Insert begin/end borrow for guaranteed arguments.
495+ if (paramInfo.isGuaranteed ()) {
496+ if (SILValue newValue = borrowFunctionArgument (callArg, idx)) {
497+ callArg = newValue;
498+ borrowedArgs[idx] = true ;
499+ }
500+ } else if (paramInfo.isConsumed ()) {
501+ if (SILValue newValue = moveFunctionArgument (callArg, idx)) {
502+ callArg = newValue;
503+ }
496504 }
497505 }
498506 }
0 commit comments