]> granicus.if.org Git - clang/commitdiff
Don't expose iterators into the list of types on the ASTContext; these are
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 18 Nov 2015 01:19:02 +0000 (01:19 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 18 Nov 2015 01:19:02 +0000 (01:19 +0000)
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

include/clang/AST/ASTContext.h
lib/Sema/SemaLookup.cpp

index a6d97aaec2e5c09864e23745ff2635ad743ef971..b24e7652312e228afd9294d49cd81ae680494af3 100644 (file)
@@ -2273,16 +2273,6 @@ public:
   // corresponding unsigned integer type.
   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
   //===--------------------------------------------------------------------===//
index 9b5d511818e81b8b96d41144850e7e1efcc4d414..245c5519b22153f8ffce1b3daf60d980b5327611 100644 (file)
@@ -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<TemplateSpecializationType>(TI))
       continue;
     if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {