Skip to content

Commit 7b6fb3f

Browse files
committed
[DI] See through alloc_box borrows.
1 parent 5e23e98 commit 7b6fb3f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ static void gatherDestroysOfContainer(const DIMemoryObjectInfo &memoryInfo,
5151
// TODO: This should really be tracked separately from other destroys so that
5252
// we distinguish the lifetime of the container from the value itself.
5353
assert(isa<ProjectBoxInst>(uninitMemory));
54-
auto *mui = cast<MarkUninitializedInst>(uninitMemory->getOperand(0));
54+
auto value = uninitMemory->getOperand(0);
55+
if (auto *bbi = dyn_cast<BeginBorrowInst>(value)) {
56+
value = bbi->getOperand();
57+
}
58+
auto *mui = cast<MarkUninitializedInst>(value);
5559
for (auto *user : mui->getUsersOfType<DestroyValueInst>()) {
5660
useInfo.trackDestroy(user);
5761
}
@@ -114,6 +118,12 @@ DIMemoryObjectInfo::DIMemoryObjectInfo(MarkUninitializedInst *MI)
114118
auto &Module = MI->getModule();
115119

116120
SILValue Address = MemoryInst;
121+
if (auto BBI = MemoryInst->getSingleUserOfType<BeginBorrowInst>()) {
122+
if (auto PBI = BBI->getSingleUserOfType<ProjectBoxInst>()) {
123+
IsBox = true;
124+
Address = PBI;
125+
}
126+
}
117127
if (auto PBI = MemoryInst->getSingleUserOfType<ProjectBoxInst>()) {
118128
IsBox = true;
119129
Address = PBI;

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ class DIMemoryObjectInfo {
102102
/// with the memory info.
103103
SingleValueInstruction *getUninitializedValue() const {
104104
if (IsBox) {
105+
SILValue inst = MemoryInst;
106+
if (auto *bbi = MemoryInst->getSingleUserOfType<BeginBorrowInst>()) {
107+
inst = bbi;
108+
}
105109
// TODO: consider just storing the ProjectBoxInst in this case.
106-
auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>();
107-
assert(pbi);
108-
return pbi;
110+
SingleValueInstruction *svi = inst->getSingleUserOfType<ProjectBoxInst>();
111+
assert(svi);
112+
return svi;
109113
}
110114
return MemoryInst;
111115
}

lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ const ParamDecl *getParamDeclFromOperand(SILValue value) {
157157

158158
bool isUseOfSelfInInitializer(Operand *oper) {
159159
if (auto *PBI = dyn_cast<ProjectBoxInst>(oper->get())) {
160-
if (auto *MUI = dyn_cast<MarkUninitializedInst>(PBI->getOperand())) {
160+
SILValue value = PBI->getOperand();
161+
if (auto *bbi = dyn_cast<BeginBorrowInst>(value)) {
162+
value = bbi->getOperand();
163+
}
164+
if (auto *MUI = dyn_cast<MarkUninitializedInst>(value)) {
161165
switch (MUI->getMarkUninitializedKind()) {
162166
case MarkUninitializedInst::Kind::Var:
163167
return false;

0 commit comments

Comments
 (0)