@@ -94,7 +94,8 @@ class LiveValues {
9494 // / those usages will be replaced with usages of the stored field. The
9595 // / implementation constructs an instance to match those requirements.
9696 static Owned toReplace (AllocStackInst *asi, SILValue replacement) {
97- if (lexicalLifetimeEnsured (asi))
97+ if (lexicalLifetimeEnsured (asi) &&
98+ replacement->getOwnershipKind () != OwnershipKind::None)
9899 return {SILValue (), replacement};
99100 return {replacement, SILValue ()};
100101 }
@@ -105,9 +106,10 @@ class LiveValues {
105106 if (!lexicalLifetimeEnsured (asi)) {
106107 return stored;
107108 }
108- // We should have created a move of the @owned stored value.
109- assert (move);
110- return move;
109+ assert (move || stored->getOwnershipKind () == OwnershipKind::None);
110+ // If we had a trivial value stored in a lexical non trivial enum, we may
111+ // not have created a move, return stored value in that case.
112+ return move ? move : stored;
111113 }
112114
113115 bool canEndLexicalLifetime () {
@@ -146,7 +148,10 @@ class LiveValues {
146148 // For guaranteed lexical AllocStackInsts--i.e. those that are
147149 // store_borrow locations--we may have created a borrow if the stored
148150 // value is a non-lexical guaranteed value.
149- assert (isGuaranteedLexicalValue (stored) || borrow);
151+ // We may not have created any borrow, if there was a trivial store to a
152+ // non-trivial lexical enum.
153+ assert (isGuaranteedLexicalValue (stored) || borrow ||
154+ stored->getOwnershipKind () == OwnershipKind::None);
150155 return borrow ? borrow : stored;
151156 }
152157
@@ -655,6 +660,9 @@ static SILValue getLexicalValueForStore(SILInstruction *inst,
655660 if (!lexicalLifetimeEnsured (asi)) {
656661 return SILValue ();
657662 }
663+ if (stored->getOwnershipKind () == OwnershipKind::None) {
664+ return SILValue ();
665+ }
658666 if (isa<StoreBorrowInst>(inst)) {
659667 if (isGuaranteedLexicalValue (stored)) {
660668 return SILValue ();
@@ -679,6 +687,8 @@ static StorageStateTracking<LiveValues>
679687beginOwnedLexicalLifetimeAfterStore (AllocStackInst *asi, StoreInst *inst) {
680688 assert (lexicalLifetimeEnsured (asi));
681689 SILValue stored = inst->getOperand (CopyLikeInstruction::Src);
690+ assert (stored->getOwnershipKind () == OwnershipKind::Owned);
691+
682692 SILLocation loc = RegularLocation::getAutoGeneratedLocation (inst->getLoc ());
683693
684694 MoveValueInst *mvi = nullptr ;
@@ -698,6 +708,8 @@ beginGuaranteedLexicalLifetimeAfterStore(AllocStackInst *asi,
698708 StoreBorrowInst *inst) {
699709 assert (lexicalLifetimeEnsured (asi));
700710 SILValue stored = inst->getOperand (CopyLikeInstruction::Src);
711+ assert (stored->getOwnershipKind () != OwnershipKind::None);
712+
701713 SILLocation loc = RegularLocation::getAutoGeneratedLocation (inst->getLoc ());
702714
703715 if (isGuaranteedLexicalValue (stored)) {
@@ -1042,7 +1054,9 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
10421054 // The current store is now the lastStoreInst (until we see
10431055 // another).
10441056 lastStoreInst = si;
1045- if (lexicalLifetimeEnsured (asi)) {
1057+
1058+ if (lexicalLifetimeEnsured (asi) &&
1059+ si->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
10461060 if (oldRunningVals && oldRunningVals->isStorageValid &&
10471061 canEndLexicalLifetime (oldRunningVals->value )) {
10481062 endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
@@ -1070,7 +1084,8 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
10701084 /* isStorageValid=*/ true };
10711085 // The current store is now the lastStoreInst.
10721086 lastStoreInst = sbi;
1073- if (lexicalLifetimeEnsured (asi)) {
1087+ if (lexicalLifetimeEnsured (asi) &&
1088+ sbi->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
10741089 runningVals = beginGuaranteedLexicalLifetimeAfterStore (asi, sbi);
10751090 }
10761091 continue ;
@@ -1914,7 +1929,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
19141929 auto oldRunningVals = runningVals;
19151930 runningVals = {LiveValues::toReplace (asi, /* replacement=*/ si->getSrc ()),
19161931 /* isStorageValid=*/ true };
1917- if (lexicalLifetimeEnsured (asi)) {
1932+ if (lexicalLifetimeEnsured (asi) &&
1933+ si->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
19181934 if (oldRunningVals && oldRunningVals->isStorageValid ) {
19191935 endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
19201936 oldRunningVals->value .getOwned ());
@@ -1932,7 +1948,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
19321948 }
19331949 runningVals = {LiveValues::toReplace (asi, /* replacement=*/ sbi->getSrc ()),
19341950 /* isStorageValid=*/ true };
1935- if (lexicalLifetimeEnsured (asi)) {
1951+ if (lexicalLifetimeEnsured (asi) &&
1952+ sbi->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
19361953 runningVals = beginGuaranteedLexicalLifetimeAfterStore (asi, sbi);
19371954 }
19381955 continue ;
0 commit comments