Skip to content

Commit ce5dc9a

Browse files
authored
Merge pull request #84333 from kavon/load-copy-does-retain
2 parents 56f6063 + 2dea3ca commit ce5dc9a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docs/SIL/Instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,16 +832,16 @@ load-ownership-kind ::= 'take'
832832
```
833833

834834
Loads the value at address `%0` from memory. `T` must be a loadable
835-
type. This does not affect the reference count, if any, of the loaded
835+
type. An unqualified load does not affect the reference count, if any, of the loaded
836836
value; the value must be retained explicitly if necessary. It is
837837
undefined behavior to load from uninitialized memory or to load from an
838838
address that points to deallocated storage.
839839

840840
In OSSA the ownership kind specifies how to handle ownership:
841841
- **trivial**: the loaded value is trivial and no further action must be taken
842842
than to load the raw bits of the value
843-
- **copy**: the loaded value is copied and the original value stays in the
844-
memory location.
843+
- **copy**: the loaded value is copied (e.g., retained) and the original value
844+
stays in the memory location.
845845
- **take**: the value is _moved_ from the memory location without copying.
846846
After the `load`, the memory location remains uninitialized.
847847

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
552552
case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
553553
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
554554
case SILInstructionKind::UncheckedOwnershipConversionInst:
555-
case SILInstructionKind::LoadInst:
556555
case SILInstructionKind::LoadBorrowInst:
557556
case SILInstructionKind::BeginBorrowInst:
558557
case SILInstructionKind::BorrowedFromInst:
@@ -626,6 +625,14 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
626625
case SILInstructionKind::TypeValueInst:
627626
case SILInstructionKind::IgnoredUseInst:
628627
return RuntimeEffect::NoEffect;
628+
629+
case SILInstructionKind::LoadInst: {
630+
if (cast<LoadInst>(inst)->getOwnershipQualifier() == LoadOwnershipQualifier::Copy) {
631+
return ifNonTrivial(inst->getOperand(0)->getType(),
632+
RuntimeEffect::RefCounting);
633+
}
634+
return RuntimeEffect::NoEffect;
635+
}
629636

630637
case SILInstructionKind::OpenExistentialMetatypeInst:
631638
case SILInstructionKind::OpenExistentialBoxInst:

0 commit comments

Comments
 (0)