File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -922,10 +922,17 @@ Optional<OwnershipConstraint> Operand::getOwnershipConstraint() const {
922
922
// We do not ever call this function when an instruction isn't in a block.
923
923
assert (getUser ()->getParent () &&
924
924
" 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
+ }
929
936
930
937
OwnershipConstraintClassifier classifier (getUser ()->getModule (), *this );
931
938
return classifier.visit (const_cast <SILInstruction *>(getUser ()));
Original file line number Diff line number Diff line change @@ -591,10 +591,19 @@ ValueOwnershipKind SILValue::getOwnershipKind() const {
591
591
//
592
592
// We assume that any time we are in SILBuilder and call this without having a
593
593
// 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
+ }
598
607
599
608
ValueOwnershipKindClassifier Classifier;
600
609
auto result = Classifier.visit (const_cast <ValueBase *>(Value));
You can’t perform that action at this time.
0 commit comments