Skip to content

Commit f8029c7

Browse files
committed
A temporary workaround for a use-after-free issue related to debug scopes.
This fix is just to unblock the subsequent commit. Adrian is working on a proper solution for this issue. rdar://22017421 and rdar://23306385
1 parent a4669a2 commit f8029c7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/SILGen/SILGenFunction.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,20 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
515515
/// Set the debug scope for all SILInstructions that where emitted
516516
/// from when we entered the last scope up to the current one.
517517
void setDebugScopeForInsertedInstrs(SILDebugScope *DS) {
518-
while (LastInsnWithoutScope < InsertedInstrs.size()) {
519-
InsertedInstrs[LastInsnWithoutScope++]->setDebugScope(DS);
518+
// This is just a workaround.
519+
// Check that instruction really belongs to a function being processed.
520+
unsigned LastIdx = LastInsnWithoutScope, EndIdx = InsertedInstrs.size();
521+
for (auto &BB: F) {
522+
for (auto &I: BB) {
523+
for (unsigned i = LastIdx; i < EndIdx; ++i) {
524+
if (&I == InsertedInstrs[i]) {
525+
InsertedInstrs[i]->setDebugScope(DS);
526+
break;
527+
}
528+
}
529+
}
520530
}
531+
LastInsnWithoutScope = EndIdx;
521532
}
522533

523534
//===--------------------------------------------------------------------===//

0 commit comments

Comments
 (0)