diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 7b7cd6411098..c4c2644386e6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3319,6 +3319,16 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) { } void CGDebugInfo::finalize() { + // Creating types might create further types - invalidating the current + // element and the size(), so don't cache/reference them. + for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) { + ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i]; + E.Decl.replaceAllUsesWith(CGM.getLLVMContext(), + E.Type->getDecl()->getDefinition() + ? CreateTypeDefinition(E.Type, E.Unit) + : E.Decl); + } + for (auto p : ReplaceMap) { assert(p.second); llvm::DIType Ty(cast(p.second)); @@ -3332,16 +3342,6 @@ void CGDebugInfo::finalize() { Ty.replaceAllUsesWith(CGM.getLLVMContext(), RepTy); } - // Creating types might create further types - invalidating the current - // element and the size(), so don't cache/reference them. - for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) { - ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i]; - E.Decl.replaceAllUsesWith(CGM.getLLVMContext(), - E.Type->getDecl()->getDefinition() - ? CreateTypeDefinition(E.Type, E.Unit) - : E.Decl); - } - // We keep our own list of retained types, because we need to look // up the final type in the type cache. for (std::vector::const_iterator RI = RetainedTypes.begin(),