Author: rsmith Date: Tue Nov 17 19:19:02 2015 New Revision: 253420 URL: http://llvm.org/viewvc/llvm-project?rev=253420&view=rev Log: 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.
Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/lib/Sema/SemaLookup.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=253420&r1=253419&r2=253420&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Tue Nov 17 19:19:02 2015 @@ -2274,16 +2274,6 @@ public: QualType getCorrespondingUnsignedType(QualType T) const; //===--------------------------------------------------------------------===// - // Type Iterators. - //===--------------------------------------------------------------------===// - typedef llvm::iterator_range<SmallVectorImpl<Type *>::const_iterator> - type_const_range; - - type_const_range types() const { - return type_const_range(Types.begin(), Types.end()); - } - - //===--------------------------------------------------------------------===// // Integer Values //===--------------------------------------------------------------------===// Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=253420&r1=253419&r2=253420&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Nov 17 19:19:02 2015 @@ -3873,7 +3873,12 @@ void TypoCorrectionConsumer::addNamespac 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<TemplateSpecializationType>(TI)) continue; if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits