Skip to content

Commit adfdfd8

Browse files
committed
fix a crash in AccessEnforementWMO
1 parent 9a240e8 commit adfdfd8

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/SILOptimizer/Transforms/AccessEnforcementWMO.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class GlobalAccessRemoval {
164164
void perform();
165165

166166
protected:
167-
void visitInstruction(SILInstruction *I);
167+
bool visitInstruction(SILInstruction *I);
168168
void recordAccess(SILInstruction *beginAccess, DisjointAccessLocationKey key,
169169
AccessStorage::Kind storageKind, bool hasNoNestedConflict);
170170
void removeNonreentrantAccess();
@@ -180,27 +180,33 @@ void GlobalAccessRemoval::perform() {
180180
continue;
181181

182182
for (auto &BB : F) {
183-
for (auto &I : BB)
184-
visitInstruction(&I);
183+
for (auto &I : BB) {
184+
if (!visitInstruction(&I))
185+
return;
186+
}
185187
}
186188
}
187189
removeNonreentrantAccess();
188190
}
189191

190-
void GlobalAccessRemoval::visitInstruction(SILInstruction *I) {
192+
bool GlobalAccessRemoval::visitInstruction(SILInstruction *I) {
191193
if (auto *BAI = dyn_cast<BeginAccessInst>(I)) {
192194
auto storageAndBase = AccessStorageWithBase::compute(BAI->getSource());
195+
if (!storageAndBase.base)
196+
return false;
193197
auto key = getDisjointAccessLocation(storageAndBase);
194198
recordAccess(BAI, key, storageAndBase.storage.getKind(),
195199
BAI->hasNoNestedConflict());
196-
return;
200+
return true;
197201
}
198202
if (auto *BUAI = dyn_cast<BeginUnpairedAccessInst>(I)) {
199203
auto storageAndBase = AccessStorageWithBase::compute(BUAI->getSource());
204+
if (!storageAndBase.base)
205+
return false;
200206
auto key = getDisjointAccessLocation(storageAndBase);
201207
recordAccess(BUAI, key, storageAndBase.storage.getKind(),
202208
BUAI->hasNoNestedConflict());
203-
return;
209+
return true;
204210
}
205211
if (auto *KPI = dyn_cast<KeyPathInst>(I)) {
206212
for (const KeyPathPatternComponent &component :
@@ -219,8 +225,8 @@ void GlobalAccessRemoval::visitInstruction(SILInstruction *I) {
219225
break;
220226
}
221227
}
222-
return;
223228
}
229+
return true;
224230
}
225231

226232
// Record an access in the disjointAccessMap.

0 commit comments

Comments
 (0)