From 2a40fb78c0ae8ba9a46cd63fad2ed50c6f5ec31e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 18 Nov 2015 01:19:02 +0000 Subject: 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. llvm-svn: 253420 --- clang/lib/Sema/SemaLookup.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'clang/lib/Sema/SemaLookup.cpp') diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 9b5d511818e..245c5519b22 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/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()) { -- cgit v1.2.3