Skip to content

Commit 035ceca

Browse files
committed
Patch a Source of Iterator Invalidation
getOpaqueResultTypeDecl() can wind up invoking lazy function body parsing when it runs availability checking. If any of those function bodies have opaque result types, they will be inserted. If that insertion happens to resize the SetVector, iterators will be invalidated and a non-deterministic crash results. Instead, use SetVector::takeVector() for the iteration so we have a temporary copy whose iterators cannot be invalidated in this situation. This also elegantly handles clearing out the vector for us. Resolves rdar://62976771
1 parent 9a8b91e commit 035ceca

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/AST/Module.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ SourceFile::getConfiguredReferencedNameTracker() const {
26402640
}
26412641

26422642
ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
2643-
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes) {
2643+
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes.takeVector()) {
26442644
if (auto opaqueDecl = vd->getOpaqueResultTypeDecl()) {
26452645
auto inserted = ValidatedOpaqueReturnTypes.insert(
26462646
{opaqueDecl->getOpaqueReturnTypeIdentifier().str(),
@@ -2651,7 +2651,6 @@ ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
26512651
}
26522652
}
26532653

2654-
UnvalidatedDeclsWithOpaqueReturnTypes.clear();
26552654
return OpaqueReturnTypes;
26562655
}
26572656

0 commit comments

Comments
 (0)