From: Richard Smith Date: Wed, 18 Nov 2015 01:19:02 +0000 (+0000) Subject: Don't expose iterators into the list of types on the ASTContext; these are X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=355e9ff21bd7dcc4294fb830657b6eaafb050739;p=clang Don't expose iterators into the list of types on the ASTContext; these are unsafe, since many operations on the types can trigger lazy deserialization of more types and invalidate the iterators. This fixes a crasher, but I've not been able to reduce it to a reasonable testcase yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253420 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index a6d97aaec2..b24e765231 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -2273,16 +2273,6 @@ public: // corresponding unsigned integer type. QualType getCorrespondingUnsignedType(QualType T) const; - //===--------------------------------------------------------------------===// - // Type Iterators. - //===--------------------------------------------------------------------===// - typedef llvm::iterator_range::const_iterator> - type_const_range; - - type_const_range types() const { - return type_const_range(Types.begin(), Types.end()); - } - //===--------------------------------------------------------------------===// // Integer Values //===--------------------------------------------------------------------===// diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 9b5d511818..245c5519b2 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3873,7 +3873,12 @@ void TypoCorrectionConsumer::addNamespaces( if (const Type *T = NNS->getAsType()) SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization; } - for (const auto *TI : SemaRef.getASTContext().types()) { + // Do not transform this into an iterator-based loop. The loop body can + // trigger the creation of further types (through lazy deserialization) and + // invalide iterators into this list. + auto &Types = SemaRef.getASTContext().getTypes(); + for (unsigned I = 0; I != Types.size(); ++I) { + const auto *TI = Types[I]; if (!TI->isClassType() && isa(TI)) continue; if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {