diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4514,13 +4514,17 @@ // Adjust the canonical function result type. CanQualType CanResultTy = getCanonicalFunctionResultType(ResultTy); + const auto OrigCapacity = FunctionProtoTypes.capacity(); Canonical = getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI, true); - // Get the new insert position for the node we care about. - FunctionProtoType *NewIP = - FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); - assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; + // Get the new insert position for the node we care about, if the recursive + // call invalidated InsertPos. + if (FunctionProtoTypes.capacity() != OrigCapacity) { + FunctionProtoType *NewIP = + FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); + assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; + } } // Compute the needed size to hold this FunctionProtoType and the