Skip to content

Commit eff4985

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 cfdb65f commit eff4985

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
@@ -2697,7 +2697,7 @@ SourceFile::getConfiguredReferencedNameTracker() const {
26972697
}
26982698

26992699
ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
2700-
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes) {
2700+
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes.takeVector()) {
27012701
if (auto opaqueDecl = vd->getOpaqueResultTypeDecl()) {
27022702
auto inserted = ValidatedOpaqueReturnTypes.insert(
27032703
{opaqueDecl->getOpaqueReturnTypeIdentifier().str(),
@@ -2708,7 +2708,6 @@ ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
27082708
}
27092709
}
27102710

2711-
UnvalidatedDeclsWithOpaqueReturnTypes.clear();
27122711
return OpaqueReturnTypes;
27132712
}
27142713

0 commit comments

Comments
 (0)