Skip to content

Commit 7d271cb

Browse files
committed
[SILDiagnostics] Fix an invalidation crash in DiagnoseStaticExclusivity.
Fix a crash when re-hashing the basic-block map would leave behind a dangling mutable reference. The irony that the language feature this pass implements would have caught this issue statically is not lost on me.
1 parent fe310f5 commit 7d271cb

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ static void checkStaticExclusivity(SILFunction &Fn) {
295295
// state for that predecessor as our in state. The SIL verifier guarantees
296296
// that all incoming edges must have the same current accesses.
297297
for (auto *Pred : BB->getPredecessorBlocks()) {
298-
const Optional<StorageMap> &PredAccesses = BlockOutAccesses[Pred];
298+
auto it = BlockOutAccesses.find(Pred);
299+
if (it == BlockOutAccesses.end())
300+
continue;
301+
302+
const Optional<StorageMap> &PredAccesses = it->getSecond();
299303
if (PredAccesses) {
300304
BBState = PredAccesses;
301305
break;

test/SILOptimizer/exclusivity_static_diagnostics.sil

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,64 @@ bb0(%0 : $Int):
341341
%9 = tuple ()
342342
return %9 : $()
343343
}
344+
345+
// Check for iterator invalidation issues when the hash from
346+
// basic blocks to analysis state is re-hashed. The number of
347+
// blocks in this test is determined by the initial size of the
348+
// 'BlockOutAccesses' DenseMap in the implementation.
349+
//
350+
// The unreachable block below must branch to bN where
351+
// N = 3/4 * INITIAL_SIZE - 2
352+
sil @blockMapRehash : $@convention(method) (Builtin.Int1) -> () {
353+
bb0(%0: $Builtin.Int1):
354+
br bb1
355+
bb1:
356+
br bb2
357+
bb2:
358+
br bb3
359+
bb3:
360+
br bb4
361+
bb4:
362+
br bb5
363+
bb5:
364+
br bb6
365+
bb6:
366+
br bb7
367+
bb7:
368+
br bb8
369+
bb8:
370+
br bb9
371+
bb9:
372+
br bb10
373+
bb10:
374+
br bb11
375+
bb11:
376+
br bb12
377+
bb12:
378+
br bb13
379+
bb13:
380+
br bb14
381+
bb14:
382+
br bb15
383+
bb15:
384+
br bb16
385+
bb16:
386+
br bb17
387+
bb17:
388+
br bb18
389+
bb18:
390+
br bb19
391+
bb19:
392+
br bb20
393+
bb20:
394+
br bb21
395+
bb21:
396+
br bb22
397+
bb22:
398+
br bb23 // no-crash
399+
bb23:
400+
%1 = tuple ()
401+
return %1 : $()
402+
bbUnreachable:
403+
br bb22
404+
}

0 commit comments

Comments
 (0)