Skip to content

Commit ab3eaf2

Browse files
authored
Merge pull request #71881 from meg-gupta/fixmem2reg
Fix mem2reg of lexical enum stack locations
2 parents a4eb43e + 79acb5a commit ab3eaf2

File tree

5 files changed

+346
-87
lines changed

5 files changed

+346
-87
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,9 +1707,11 @@ class SILBuilder {
17071707

17081708
EnumInst *createEnum(SILLocation Loc, SILValue Operand,
17091709
EnumElementDecl *Element, SILType Ty) {
1710-
return createEnum(Loc, Operand, Element, Ty,
1711-
Operand ? Operand->getOwnershipKind()
1712-
: ValueOwnershipKind(OwnershipKind::None));
1710+
return createEnum(
1711+
Loc, Operand, Element, Ty,
1712+
Operand ? getSILValueOwnership({Operand}, Ty)
1713+
: (Ty.isMoveOnly() ? ValueOwnershipKind(OwnershipKind::Owned)
1714+
: ValueOwnershipKind(OwnershipKind::None)));
17131715
}
17141716

17151717
EnumInst *createEnum(SILLocation Loc, SILValue Operand,

include/swift/SIL/ValueUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
namespace swift {
1919

2020
/// Attempt to merge the ValueOwnershipKind of the passed in range's
21-
/// SILValues. Returns Optional<None> if we found an incompatibility.
21+
/// SILValues. Returns OwnershipKind::Any if we found an incompatibility.
22+
/// If \p is a move-only type, we return OwnershipKind::Owned since such
23+
/// values can have deinit side-effects.
2224
///
2325
/// NOTE: This assumes that the passed in SILValues are not values used as type
2426
/// dependent operands.

lib/SIL/Utils/ValueUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ ValueOwnershipKind swift::getSILValueOwnership(ArrayRef<SILValue> values,
2626

2727
auto mergedOwnership = ValueOwnershipKind::merge(range);
2828

29-
// If we have a move only type, and the merged ownership is none, we return
30-
// Owned ownership kind.
29+
// If we have a move only type, return owned ownership.
3130
if (ty && ty.isMoveOnly() && mergedOwnership == OwnershipKind::None) {
3231
return OwnershipKind::Owned;
3332
}

0 commit comments

Comments
 (0)