@@ -94,7 +94,8 @@ class LiveValues {
94
94
// / those usages will be replaced with usages of the stored field. The
95
95
// / implementation constructs an instance to match those requirements.
96
96
static Owned toReplace (AllocStackInst *asi, SILValue replacement) {
97
- if (lexicalLifetimeEnsured (asi))
97
+ if (lexicalLifetimeEnsured (asi) &&
98
+ replacement->getOwnershipKind () != OwnershipKind::None)
98
99
return {SILValue (), replacement};
99
100
return {replacement, SILValue ()};
100
101
}
@@ -105,9 +106,10 @@ class LiveValues {
105
106
if (!lexicalLifetimeEnsured (asi)) {
106
107
return stored;
107
108
}
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;
111
113
}
112
114
113
115
bool canEndLexicalLifetime () {
@@ -146,7 +148,10 @@ class LiveValues {
146
148
// For guaranteed lexical AllocStackInsts--i.e. those that are
147
149
// store_borrow locations--we may have created a borrow if the stored
148
150
// 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);
150
155
return borrow ? borrow : stored;
151
156
}
152
157
@@ -655,6 +660,9 @@ static SILValue getLexicalValueForStore(SILInstruction *inst,
655
660
if (!lexicalLifetimeEnsured (asi)) {
656
661
return SILValue ();
657
662
}
663
+ if (stored->getOwnershipKind () == OwnershipKind::None) {
664
+ return SILValue ();
665
+ }
658
666
if (isa<StoreBorrowInst>(inst)) {
659
667
if (isGuaranteedLexicalValue (stored)) {
660
668
return SILValue ();
@@ -679,6 +687,8 @@ static StorageStateTracking<LiveValues>
679
687
beginOwnedLexicalLifetimeAfterStore (AllocStackInst *asi, StoreInst *inst) {
680
688
assert (lexicalLifetimeEnsured (asi));
681
689
SILValue stored = inst->getOperand (CopyLikeInstruction::Src);
690
+ assert (stored->getOwnershipKind () == OwnershipKind::Owned);
691
+
682
692
SILLocation loc = RegularLocation::getAutoGeneratedLocation (inst->getLoc ());
683
693
684
694
MoveValueInst *mvi = nullptr ;
@@ -698,6 +708,8 @@ beginGuaranteedLexicalLifetimeAfterStore(AllocStackInst *asi,
698
708
StoreBorrowInst *inst) {
699
709
assert (lexicalLifetimeEnsured (asi));
700
710
SILValue stored = inst->getOperand (CopyLikeInstruction::Src);
711
+ assert (stored->getOwnershipKind () != OwnershipKind::None);
712
+
701
713
SILLocation loc = RegularLocation::getAutoGeneratedLocation (inst->getLoc ());
702
714
703
715
if (isGuaranteedLexicalValue (stored)) {
@@ -1042,7 +1054,9 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
1042
1054
// The current store is now the lastStoreInst (until we see
1043
1055
// another).
1044
1056
lastStoreInst = si;
1045
- if (lexicalLifetimeEnsured (asi)) {
1057
+
1058
+ if (lexicalLifetimeEnsured (asi) &&
1059
+ si->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
1046
1060
if (oldRunningVals && oldRunningVals->isStorageValid &&
1047
1061
canEndLexicalLifetime (oldRunningVals->value )) {
1048
1062
endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
@@ -1070,7 +1084,8 @@ SILInstruction *StackAllocationPromoter::promoteAllocationInBlock(
1070
1084
/* isStorageValid=*/ true };
1071
1085
// The current store is now the lastStoreInst.
1072
1086
lastStoreInst = sbi;
1073
- if (lexicalLifetimeEnsured (asi)) {
1087
+ if (lexicalLifetimeEnsured (asi) &&
1088
+ sbi->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
1074
1089
runningVals = beginGuaranteedLexicalLifetimeAfterStore (asi, sbi);
1075
1090
}
1076
1091
continue ;
@@ -1914,7 +1929,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1914
1929
auto oldRunningVals = runningVals;
1915
1930
runningVals = {LiveValues::toReplace (asi, /* replacement=*/ si->getSrc ()),
1916
1931
/* isStorageValid=*/ true };
1917
- if (lexicalLifetimeEnsured (asi)) {
1932
+ if (lexicalLifetimeEnsured (asi) &&
1933
+ si->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
1918
1934
if (oldRunningVals && oldRunningVals->isStorageValid ) {
1919
1935
endOwnedLexicalLifetimeBeforeInst (asi, /* beforeInstruction=*/ si, ctx,
1920
1936
oldRunningVals->value .getOwned ());
@@ -1932,7 +1948,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1932
1948
}
1933
1949
runningVals = {LiveValues::toReplace (asi, /* replacement=*/ sbi->getSrc ()),
1934
1950
/* isStorageValid=*/ true };
1935
- if (lexicalLifetimeEnsured (asi)) {
1951
+ if (lexicalLifetimeEnsured (asi) &&
1952
+ sbi->getSrc ()->getOwnershipKind () != OwnershipKind::None) {
1936
1953
runningVals = beginGuaranteedLexicalLifetimeAfterStore (asi, sbi);
1937
1954
}
1938
1955
continue ;
0 commit comments