Skip to content

Commit f4d9c7b

Browse files
committed
Add getDeclContextOrNull to AssignOrInitInst
1 parent afe83fe commit f4d9c7b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5310,6 +5310,7 @@ class AssignOrInitInst
53105310

53115311
StringRef getPropertyName() const;
53125312
AccessorDecl *getReferencedInitAccessor() const;
5313+
DeclContext *getDeclContextOrNull() const;
53135314
};
53145315

53155316
/// Indicates that a memory location is uninitialized at this point and needs to

lib/SIL/IR/SILInstructions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,12 @@ AccessorDecl *AssignOrInitInst::getReferencedInitAccessor() const {
13551355
return Property->getOpaqueAccessor(AccessorKind::Init);
13561356
}
13571357

1358+
DeclContext *AssignOrInitInst::getDeclContextOrNull() const {
1359+
if (auto accessorDecl = getReferencedInitAccessor())
1360+
return accessorDecl->getDeclContext();
1361+
return getProperty()->getDeclContext();
1362+
}
1363+
13581364
unsigned AssignOrInitInst::getNumInitializedProperties() const {
13591365
return getInitializedProperties().size();
13601366
}

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,8 @@ ElementUseCollector::collectAssignOrInitUses(AssignOrInitInst *Inst,
12421242
llvm::SaveAndRestore<bool> X(IsSelfOfNonDelegatingInitializer, false);
12431243

12441244
NominalTypeDecl *typeDC = nullptr;
1245-
if (auto accessorDecl = Inst->getReferencedInitAccessor()) {
1246-
typeDC = accessorDecl->getDeclContext()->getSelfNominalTypeDecl();
1247-
} else {
1248-
typeDC = Inst->getProperty()->getDeclContext()->getSelfNominalTypeDecl();
1249-
}
1245+
if (auto declContext = Inst->getDeclContextOrNull()->getSelfNominalTypeDecl())
1246+
typeDC = declContext;
12501247

12511248
auto expansionContext = TypeExpansionContext(TheMemory.getFunction());
12521249
auto selfOrLocalTy = Inst->getSelfOrLocalOperand()->getType();

0 commit comments

Comments
 (0)