Skip to content

Commit 33aec98

Browse files
committed
[ownership] Assume values/operands in SILGlobalVariable blocks are not in OSSA.
Operationally it just means that in SILGlobalVariable blocks, all operands have ownership constraint: {OwnershipKind::Any, UseLifetimeConstraint::NonLifetimeEnding} and all values yield an ownership kind of: OwnershipKind::None.
1 parent f0f78a1 commit 33aec98

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,17 @@ Optional<OwnershipConstraint> Operand::getOwnershipConstraint() const {
922922
// We do not ever call this function when an instruction isn't in a block.
923923
assert(getUser()->getParent() &&
924924
"Can not lookup ownership constraint unless inserted into block");
925-
if (auto *block = getUser()->getParent())
926-
if (auto *func = block->getParent())
927-
if (!func->hasOwnership())
928-
return {{OwnershipKind::Any, UseLifetimeConstraint::NonLifetimeEnding}};
925+
if (auto *block = getUser()->getParent()) {
926+
auto *func = block->getParent();
927+
if (!func) {
928+
// If we don't have a function, then we must have a SILGlobalVariable. In
929+
// that case, we act as if we aren't in ownership.
930+
return {{OwnershipKind::Any, UseLifetimeConstraint::NonLifetimeEnding}};
931+
}
932+
933+
if (!func->hasOwnership())
934+
return {{OwnershipKind::Any, UseLifetimeConstraint::NonLifetimeEnding}};
935+
}
929936

930937
OwnershipConstraintClassifier classifier(getUser()->getModule(), *this);
931938
return classifier.visit(const_cast<SILInstruction *>(getUser()));

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,19 @@ ValueOwnershipKind SILValue::getOwnershipKind() const {
591591
//
592592
// We assume that any time we are in SILBuilder and call this without having a
593593
// value in a block yet, ossa is enabled.
594-
if (auto *block = Value->getParentBlock())
595-
if (auto *f = block->getParent())
596-
if (!f->hasOwnership())
597-
return OwnershipKind::None;
594+
if (auto *block = Value->getParentBlock()) {
595+
auto *f = block->getParent();
596+
// If our block isn't in a function, then it must be in a global
597+
// variable. We don't verify ownership there so just return
598+
// OwnershipKind::None.
599+
if (!f)
600+
return OwnershipKind::None;
601+
602+
// Now that we know that we do have a block/function, check if we have
603+
// ownership.
604+
if (!f->hasOwnership())
605+
return OwnershipKind::None;
606+
}
598607

599608
ValueOwnershipKindClassifier Classifier;
600609
auto result = Classifier.visit(const_cast<ValueBase *>(Value));

0 commit comments

Comments
 (0)