[clang] move ASTImporter into separate library (PR #140913)

via cfe-commits cfe-commits at lists.llvm.org
Wed May 21 08:20:02 PDT 2025


=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/140913 at github.com>


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/CrossTU/CrossTranslationUnit.h clang/lib/AST/ExternalASTSource.cpp clang/lib/CrossTU/CrossTranslationUnit.cpp clang/lib/Frontend/ASTMerge.cpp clang/lib/Interpreter/CodeCompletion.cpp clang/tools/clang-import-test/clang-import-test.cpp clang/unittests/AST/ASTImporterFixtures.cpp clang/unittests/AST/ASTImporterFixtures.h clang/include/clang/ASTImporter/ASTImportError.h clang/include/clang/ASTImporter/ASTImporter.h clang/include/clang/ASTImporter/ASTImporterLookupTable.h clang/include/clang/ASTImporter/ASTImporterSharedState.h clang/include/clang/ASTImporter/ExternalASTMerger.h clang/lib/ASTImporter/ASTImporter.cpp clang/lib/ASTImporter/ASTImporterLookupTable.cpp clang/lib/ASTImporter/ExternalASTMerger.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/ASTImporter/ASTImporter.h b/clang/include/clang/ASTImporter/ASTImporter.h
index 78e44c2fc..959287bc9 100644
--- a/clang/include/clang/ASTImporter/ASTImporter.h
+++ b/clang/include/clang/ASTImporter/ASTImporter.h
@@ -48,553 +48,548 @@ class TagDecl;
 class TranslationUnitDecl;
 class TypeSourceInfo;
 
-  // \brief Returns with a list of declarations started from the canonical decl
-  // then followed by subsequent decls in the translation unit.
-  // This gives a canonical list for each entry in the redecl chain.
-  // `Decl::redecls()` gives a list of decls which always start from the
-  // previous decl and the next item is actually the previous item in the order
-  // of source locations.  Thus, `Decl::redecls()` gives different lists for
-  // the different entries in a given redecl chain.
-  llvm::SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D);
-
-  /// Imports selected nodes from one AST context into another context,
-  /// merging AST nodes where appropriate.
-  class ASTImporter {
-    friend class ASTNodeImporter;
+// \brief Returns with a list of declarations started from the canonical decl
+// then followed by subsequent decls in the translation unit.
+// This gives a canonical list for each entry in the redecl chain.
+// `Decl::redecls()` gives a list of decls which always start from the
+// previous decl and the next item is actually the previous item in the order
+// of source locations.  Thus, `Decl::redecls()` gives different lists for
+// the different entries in a given redecl chain.
+llvm::SmallVector<Decl *, 2> getCanonicalForwardRedeclChain(Decl *D);
+
+/// Imports selected nodes from one AST context into another context,
+/// merging AST nodes where appropriate.
+class ASTImporter {
+  friend class ASTNodeImporter;
+
+public:
+  using NonEquivalentDeclSet = llvm::DenseSet<std::tuple<Decl *, Decl *, int>>;
+  using ImportedCXXBaseSpecifierMap =
+      llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
+
+  enum class ODRHandlingType { Conservative, Liberal };
+
+  // An ImportPath is the list of the AST nodes which we visit during an
+  // Import call.
+  // If node `A` depends on node `B` then the path contains an `A`->`B` edge.
+  // From the call stack of the import functions we can read the very same
+  // path.
+  //
+  // Now imagine the following AST, where the `->` represents dependency in
+  // therms of the import.
+  // ```
+  // A->B->C->D
+  //    `->E
+  // ```
+  // We would like to import A.
+  // The import behaves like a DFS, so we will visit the nodes in this order:
+  // ABCDE.
+  // During the visitation we will have the following ImportPaths:
+  // ```
+  // A
+  // AB
+  // ABC
+  // ABCD
+  // ABC
+  // AB
+  // ABE
+  // AB
+  // A
+  // ```
+  // If during the visit of E there is an error then we set an error for E,
+  // then as the call stack shrinks for B, then for A:
+  // ```
+  // A
+  // AB
+  // ABC
+  // ABCD
+  // ABC
+  // AB
+  // ABE // Error! Set an error to E
+  // AB  // Set an error to B
+  // A   // Set an error to A
+  // ```
+  // However, during the import we could import C and D without any error and
+  // they are independent from A,B and E.
+  // We must not set up an error for C and D.
+  // So, at the end of the import we have an entry in `ImportDeclErrors` for
+  // A,B,E but not for C,D.
+  //
+  // Now what happens if there is a cycle in the import path?
+  // Let's consider this AST:
+  // ```
+  // A->B->C->A
+  //    `->E
+  // ```
+  // During the visitation we will have the below ImportPaths and if during
+  // the visit of E there is an error then we will set up an error for E,B,A.
+  // But what's up with C?
+  // ```
+  // A
+  // AB
+  // ABC
+  // ABCA
+  // ABC
+  // AB
+  // ABE // Error! Set an error to E
+  // AB  // Set an error to B
+  // A   // Set an error to A
+  // ```
+  // This time we know that both B and C are dependent on A.
+  // This means we must set up an error for C too.
+  // As the call stack reverses back we get to A and we must set up an error
+  // to all nodes which depend on A (this includes C).
+  // But C is no longer on the import path, it just had been previously.
+  // Such situation can happen only if during the visitation we had a cycle.
+  // If we didn't have any cycle, then the normal way of passing an Error
+  // object through the call stack could handle the situation.
+  // This is why we must track cycles during the import process for each
+  // visited declaration.
+  class ImportPathTy {
   public:
-    using NonEquivalentDeclSet =
-        llvm::DenseSet<std::tuple<Decl *, Decl *, int>>;
-    using ImportedCXXBaseSpecifierMap =
-        llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
-
-    enum class ODRHandlingType { Conservative, Liberal };
-
-    // An ImportPath is the list of the AST nodes which we visit during an
-    // Import call.
-    // If node `A` depends on node `B` then the path contains an `A`->`B` edge.
-    // From the call stack of the import functions we can read the very same
-    // path.
-    //
-    // Now imagine the following AST, where the `->` represents dependency in
-    // therms of the import.
-    // ```
-    // A->B->C->D
-    //    `->E
-    // ```
-    // We would like to import A.
-    // The import behaves like a DFS, so we will visit the nodes in this order:
-    // ABCDE.
-    // During the visitation we will have the following ImportPaths:
-    // ```
-    // A
-    // AB
-    // ABC
-    // ABCD
-    // ABC
-    // AB
-    // ABE
-    // AB
-    // A
-    // ```
-    // If during the visit of E there is an error then we set an error for E,
-    // then as the call stack shrinks for B, then for A:
-    // ```
-    // A
-    // AB
-    // ABC
-    // ABCD
-    // ABC
-    // AB
-    // ABE // Error! Set an error to E
-    // AB  // Set an error to B
-    // A   // Set an error to A
-    // ```
-    // However, during the import we could import C and D without any error and
-    // they are independent from A,B and E.
-    // We must not set up an error for C and D.
-    // So, at the end of the import we have an entry in `ImportDeclErrors` for
-    // A,B,E but not for C,D.
-    //
-    // Now what happens if there is a cycle in the import path?
-    // Let's consider this AST:
-    // ```
-    // A->B->C->A
-    //    `->E
-    // ```
-    // During the visitation we will have the below ImportPaths and if during
-    // the visit of E there is an error then we will set up an error for E,B,A.
-    // But what's up with C?
-    // ```
-    // A
-    // AB
-    // ABC
-    // ABCA
-    // ABC
-    // AB
-    // ABE // Error! Set an error to E
-    // AB  // Set an error to B
-    // A   // Set an error to A
-    // ```
-    // This time we know that both B and C are dependent on A.
-    // This means we must set up an error for C too.
-    // As the call stack reverses back we get to A and we must set up an error
-    // to all nodes which depend on A (this includes C).
-    // But C is no longer on the import path, it just had been previously.
-    // Such situation can happen only if during the visitation we had a cycle.
-    // If we didn't have any cycle, then the normal way of passing an Error
-    // object through the call stack could handle the situation.
-    // This is why we must track cycles during the import process for each
-    // visited declaration.
-    class ImportPathTy {
-    public:
-      using VecTy = llvm::SmallVector<Decl *, 32>;
-
-      void push(Decl *D) {
-        Nodes.push_back(D);
-        ++Aux[D];
-      }
-
-      void pop() {
-        if (Nodes.empty())
-          return;
-        --Aux[Nodes.back()];
-        Nodes.pop_back();
-      }
-
-      /// Returns true if the last element can be found earlier in the path.
-      bool hasCycleAtBack() const {
-        auto Pos = Aux.find(Nodes.back());
-        return Pos != Aux.end() && Pos->second > 1;
-      }
-
-      using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>;
-      Cycle getCycleAtBack() const {
-        assert(Nodes.size() >= 2);
-        return Cycle(Nodes.rbegin(),
-                     std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) +
-                         1);
-      }
-
-      /// Returns the copy of the cycle.
-      VecTy copyCycleAtBack() const {
-        auto R = getCycleAtBack();
-        return VecTy(R.begin(), R.end());
-      }
-
-    private:
-      // All nodes of the path.
-      VecTy Nodes;
-      // Auxiliary container to be able to answer "Do we have a cycle ending
-      // at last element?" as fast as possible.
-      // We count each Decl's occurrence over the path.
-      llvm::SmallDenseMap<Decl *, int, 32> Aux;
-    };
+    using VecTy = llvm::SmallVector<Decl *, 32>;
 
-  private:
-    std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
-
-    /// The path which we go through during the import of a given AST node.
-    ImportPathTy ImportPath;
-    /// Sometimes we have to save some part of an import path, so later we can
-    /// set up properties to the saved nodes.
-    /// We may have several of these import paths associated to one Decl.
-    using SavedImportPathsForOneDecl =
-        llvm::SmallVector<ImportPathTy::VecTy, 32>;
-    using SavedImportPathsTy =
-        llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>;
-    SavedImportPathsTy SavedImportPaths;
-
-    /// The contexts we're importing to and from.
-    ASTContext &ToContext, &FromContext;
-
-    /// The file managers we're importing to and from.
-    FileManager &ToFileManager, &FromFileManager;
-
-    /// Whether to perform a minimal import.
-    bool Minimal;
-
-    ODRHandlingType ODRHandling;
-
-    /// Whether the last diagnostic came from the "from" context.
-    bool LastDiagFromFrom = false;
-
-    /// Mapping from the already-imported types in the "from" context
-    /// to the corresponding types in the "to" context.
-    llvm::DenseMap<const Type *, const Type *> ImportedTypes;
-
-    /// Mapping from the already-imported declarations in the "from"
-    /// context to the corresponding declarations in the "to" context.
-    llvm::DenseMap<Decl *, Decl *> ImportedDecls;
-
-    /// Mapping from the already-imported declarations in the "from"
-    /// context to the error status of the import of that declaration.
-    /// This map contains only the declarations that were not correctly
-    /// imported. The same declaration may or may not be included in
-    /// ImportedDecls. This map is updated continuously during imports and never
-    /// cleared (like ImportedDecls).
-    llvm::DenseMap<Decl *, ASTImportError> ImportDeclErrors;
-
-    /// Mapping from the already-imported declarations in the "to"
-    /// context to the corresponding declarations in the "from" context.
-    llvm::DenseMap<Decl *, Decl *> ImportedFromDecls;
-
-    /// Mapping from the already-imported statements in the "from"
-    /// context to the corresponding statements in the "to" context.
-    llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
-
-    /// Mapping from the already-imported FileIDs in the "from" source
-    /// manager to the corresponding FileIDs in the "to" source manager.
-    llvm::DenseMap<FileID, FileID> ImportedFileIDs;
-
-    /// Mapping from the already-imported CXXBasesSpecifier in
-    ///  the "from" source manager to the corresponding CXXBasesSpecifier
-    ///  in the "to" source manager.
-    ImportedCXXBaseSpecifierMap ImportedCXXBaseSpecifiers;
-
-    /// Declaration (from, to) pairs that are known not to be equivalent
-    /// (which we have already complained about).
-    NonEquivalentDeclSet NonEquivalentDecls;
-
-    using FoundDeclsTy = SmallVector<NamedDecl *, 2>;
-    FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
-
-    void AddToLookupTable(Decl *ToD);
-
-  protected:
-    /// Can be overwritten by subclasses to implement their own import logic.
-    /// The overwritten method should call this method if it didn't import the
-    /// decl on its own.
-    virtual Expected<Decl *> ImportImpl(Decl *From);
-
-    /// Used only in unittests to verify the behaviour of the error handling.
-    virtual bool returnWithErrorInTest() { return false; };
+    void push(Decl *D) {
+      Nodes.push_back(D);
+      ++Aux[D];
+    }
 
-  public:
+    void pop() {
+      if (Nodes.empty())
+        return;
+      --Aux[Nodes.back()];
+      Nodes.pop_back();
+    }
 
-    /// \param ToContext The context we'll be importing into.
-    ///
-    /// \param ToFileManager The file manager we'll be importing into.
-    ///
-    /// \param FromContext The context we'll be importing from.
-    ///
-    /// \param FromFileManager The file manager we'll be importing into.
-    ///
-    /// \param MinimalImport If true, the importer will attempt to import
-    /// as little as it can, e.g., by importing declarations as forward
-    /// declarations that can be completed at a later point.
-    ///
-    /// \param SharedState The importer specific lookup table which may be
-    /// shared amongst several ASTImporter objects.
-    /// If not set then the original C/C++ lookup is used.
-    ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
-                ASTContext &FromContext, FileManager &FromFileManager,
-                bool MinimalImport,
-                std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
-
-    virtual ~ASTImporter();
-
-    /// Whether the importer will perform a minimal import, creating
-    /// to-be-completed forward declarations when possible.
-    bool isMinimalImport() const { return Minimal; }
-
-    void setODRHandling(ODRHandlingType T) { ODRHandling = T; }
-
-    /// \brief Import the given object, returns the result.
-    ///
-    /// \param To Import the object into this variable.
-    /// \param From Object to import.
-    /// \return Error information (success or error).
-    template <typename ImportT>
-    [[nodiscard]] llvm::Error importInto(ImportT &To, const ImportT &From) {
-      auto ToOrErr = Import(From);
-      if (ToOrErr)
-        To = *ToOrErr;
-      return ToOrErr.takeError();
+    /// Returns true if the last element can be found earlier in the path.
+    bool hasCycleAtBack() const {
+      auto Pos = Aux.find(Nodes.back());
+      return Pos != Aux.end() && Pos->second > 1;
     }
 
-    /// Import cleanup objects owned by ExprWithCleanup.
-    llvm::Expected<ExprWithCleanups::CleanupObject>
-    Import(ExprWithCleanups::CleanupObject From);
-
-    /// Import the given type from the "from" context into the "to"
-    /// context.
-    ///
-    /// \returns The equivalent type in the "to" context, or the import error.
-    llvm::Expected<const Type *> Import(const Type *FromT);
-
-    /// Import the given qualified type from the "from" context into the "to"
-    /// context. A null type is imported as a null type (no error).
-    ///
-    /// \returns The equivalent type in the "to" context, or the import error.
-    llvm::Expected<QualType> Import(QualType FromT);
-
-    /// Import the given type source information from the
-    /// "from" context into the "to" context.
-    ///
-    /// \returns The equivalent type source information in the "to"
-    /// context, or the import error.
-    llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI);
-
-    /// Import the given attribute from the "from" context into the
-    /// "to" context.
-    ///
-    /// \returns The equivalent attribute in the "to" context, or the import
-    /// error.
-    llvm::Expected<Attr *> Import(const Attr *FromAttr);
-
-    /// Import the given declaration from the "from" context into the
-    /// "to" context.
-    ///
-    /// \returns The equivalent declaration in the "to" context, or the import
-    /// error.
-    llvm::Expected<Decl *> Import(Decl *FromD);
-    llvm::Expected<const Decl *> Import(const Decl *FromD) {
-      return Import(const_cast<Decl *>(FromD));
+    using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>;
+    Cycle getCycleAtBack() const {
+      assert(Nodes.size() >= 2);
+      return Cycle(Nodes.rbegin(),
+                   std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) +
+                       1);
     }
 
-    llvm::Expected<InheritedConstructor>
-    Import(const InheritedConstructor &From);
-
-    /// Return the copy of the given declaration in the "to" context if
-    /// it has already been imported from the "from" context.  Otherwise return
-    /// nullptr.
-    Decl *GetAlreadyImportedOrNull(const Decl *FromD) const;
-
-    /// Return the translation unit from where the declaration was
-    /// imported. If it does not exist nullptr is returned.
-    TranslationUnitDecl *GetFromTU(Decl *ToD);
-
-    /// Return the declaration in the "from" context from which the declaration
-    /// in the "to" context was imported. If it was not imported or of the wrong
-    /// type a null value is returned.
-    template <typename DeclT>
-    std::optional<DeclT *> getImportedFromDecl(const DeclT *ToD) const {
-      auto FromI = ImportedFromDecls.find(ToD);
-      if (FromI == ImportedFromDecls.end())
-        return {};
-      auto *FromD = dyn_cast<DeclT>(FromI->second);
-      if (!FromD)
-        return {};
-      return FromD;
+    /// Returns the copy of the cycle.
+    VecTy copyCycleAtBack() const {
+      auto R = getCycleAtBack();
+      return VecTy(R.begin(), R.end());
     }
 
-    /// Import the given declaration context from the "from"
-    /// AST context into the "to" AST context.
-    ///
-    /// \returns the equivalent declaration context in the "to"
-    /// context, or error value.
-    llvm::Expected<DeclContext *> ImportContext(DeclContext *FromDC);
-
-    /// Import the given expression from the "from" context into the
-    /// "to" context.
-    ///
-    /// \returns The equivalent expression in the "to" context, or the import
-    /// error.
-    llvm::Expected<Expr *> Import(Expr *FromE);
-
-    /// Import the given statement from the "from" context into the
-    /// "to" context.
-    ///
-    /// \returns The equivalent statement in the "to" context, or the import
-    /// error.
-    llvm::Expected<Stmt *> Import(Stmt *FromS);
-
-    /// Import the given nested-name-specifier from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent nested-name-specifier in the "to"
-    /// context, or the import error.
-    llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS);
-
-    /// Import the given nested-name-specifier-loc from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent nested-name-specifier-loc in the "to"
-    /// context, or the import error.
-    llvm::Expected<NestedNameSpecifierLoc>
-    Import(NestedNameSpecifierLoc FromNNS);
-
-    /// Import the given template name from the "from" context into the
-    /// "to" context, or the import error.
-    llvm::Expected<TemplateName> Import(TemplateName From);
-
-    /// Import the given source location from the "from" context into
-    /// the "to" context.
-    ///
-    /// \returns The equivalent source location in the "to" context, or the
-    /// import error.
-    llvm::Expected<SourceLocation> Import(SourceLocation FromLoc);
-
-    /// Import the given source range from the "from" context into
-    /// the "to" context.
-    ///
-    /// \returns The equivalent source range in the "to" context, or the import
-    /// error.
-    llvm::Expected<SourceRange> Import(SourceRange FromRange);
-
-    /// Import the given declaration name from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent declaration name in the "to" context, or the
-    /// import error.
-    llvm::Expected<DeclarationName> Import(DeclarationName FromName);
-
-    /// Import the given identifier from the "from" context
-    /// into the "to" context.
-    ///
-    /// \returns The equivalent identifier in the "to" context. Note: It
-    /// returns nullptr only if the FromId was nullptr.
-    IdentifierInfo *Import(const IdentifierInfo *FromId);
-
-    /// Import the given identifier or overloaded operator from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent identifier or overloaded operator in the "to"
-    /// context.
-    IdentifierOrOverloadedOperator
-    Import(IdentifierOrOverloadedOperator FromIO);
-
-    /// Import the given Objective-C selector from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent selector in the "to" context, or the import
-    /// error.
-    llvm::Expected<Selector> Import(Selector FromSel);
-
-    /// Import the given file ID from the "from" context into the
-    /// "to" context.
-    ///
-    /// \returns The equivalent file ID in the source manager of the "to"
-    /// context, or the import error.
-    llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false);
-
-    /// Import the given C++ constructor initializer from the "from"
-    /// context into the "to" context.
-    ///
-    /// \returns The equivalent initializer in the "to" context, or the import
-    /// error.
-    llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit);
-
-    /// Import the given CXXBaseSpecifier from the "from" context into
-    /// the "to" context.
-    ///
-    /// \returns The equivalent CXXBaseSpecifier in the source manager of the
-    /// "to" context, or the import error.
-    llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec);
-
-    /// Import the given APValue from the "from" context into
-    /// the "to" context.
-    ///
-    /// \return the equivalent APValue in the "to" context or the import
-    /// error.
-    llvm::Expected<APValue> Import(const APValue &FromValue);
-
-    /// Import the definition of the given declaration, including all of
-    /// the declarations it contains.
-    [[nodiscard]] llvm::Error ImportDefinition(Decl *From);
-
-    llvm::Error
-    ImportTemplateArguments(ArrayRef<TemplateArgument> FromArgs,
-                            SmallVectorImpl<TemplateArgument> &ToArgs);
-    Expected<TemplateArgument> Import(const TemplateArgument &From);
-
-    /// Cope with a name conflict when importing a declaration into the
-    /// given context.
-    ///
-    /// This routine is invoked whenever there is a name conflict while
-    /// importing a declaration. The returned name will become the name of the
-    /// imported declaration. By default, the returned name is the same as the
-    /// original name, leaving the conflict unresolve such that name lookup
-    /// for this name is likely to find an ambiguity later.
-    ///
-    /// Subclasses may override this routine to resolve the conflict, e.g., by
-    /// renaming the declaration being imported.
-    ///
-    /// \param Name the name of the declaration being imported, which conflicts
-    /// with other declarations.
-    ///
-    /// \param DC the declaration context (in the "to" AST context) in which
-    /// the name is being imported.
-    ///
-    /// \param IDNS the identifier namespace in which the name will be found.
-    ///
-    /// \param Decls the set of declarations with the same name as the
-    /// declaration being imported.
-    ///
-    /// \param NumDecls the number of conflicting declarations in \p Decls.
-    ///
-    /// \returns the name that the newly-imported declaration should have. Or
-    /// an error if we can't handle the name conflict.
-    virtual Expected<DeclarationName>
-    HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS,
-                       NamedDecl **Decls, unsigned NumDecls);
-
-    /// Retrieve the context that AST nodes are being imported into.
-    ASTContext &getToContext() const { return ToContext; }
-
-    /// Retrieve the context that AST nodes are being imported from.
-    ASTContext &getFromContext() const { return FromContext; }
-
-    /// Retrieve the file manager that AST nodes are being imported into.
-    FileManager &getToFileManager() const { return ToFileManager; }
-
-    /// Retrieve the file manager that AST nodes are being imported from.
-    FileManager &getFromFileManager() const { return FromFileManager; }
-
-    /// Report a diagnostic in the "to" context.
-    DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID);
-
-    /// Report a diagnostic in the "from" context.
-    DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID);
-
-    /// Return the set of declarations that we know are not equivalent.
-    NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; }
-
-    /// Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
-    /// Mark the Decl as complete, filling it in as much as possible.
-    ///
-    /// \param D A declaration in the "to" context.
-    virtual void CompleteDecl(Decl* D);
-
-    /// Subclasses can override this function to observe all of the \c From ->
-    /// \c To declaration mappings as they are imported.
-    virtual void Imported(Decl *From, Decl *To) {}
-
-    void RegisterImportedDecl(Decl *FromD, Decl *ToD);
-
-    /// Store and assign the imported declaration to its counterpart.
-    /// It may happen that several decls from the 'from' context are mapped to
-    /// the same decl in the 'to' context.
-    Decl *MapImported(Decl *From, Decl *To);
-
-    /// Called by StructuralEquivalenceContext.  If a RecordDecl is
-    /// being compared to another RecordDecl as part of import, completing the
-    /// other RecordDecl may trigger importation of the first RecordDecl. This
-    /// happens especially for anonymous structs.  If the original of the second
-    /// RecordDecl can be found, we can complete it without the need for
-    /// importation, eliminating this loop.
-    virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; }
-
-    /// Return if import of the given declaration has failed and if yes
-    /// the kind of the problem. This gives the first error encountered with
-    /// the node.
-    std::optional<ASTImportError> getImportDeclErrorIfAny(Decl *FromD) const;
-
-    /// Mark (newly) imported declaration with error.
-    void setImportDeclError(Decl *From, ASTImportError Error);
-
-    /// Determine whether the given types are structurally
-    /// equivalent.
-    bool IsStructurallyEquivalent(QualType From, QualType To,
-                                  bool Complain = true);
-
-    /// Determine the index of a field in its parent record.
-    /// F should be a field (or indirect field) declaration.
-    /// \returns The index of the field in its parent context (starting from 0).
-    /// On error `std::nullopt` is returned (parent context is non-record).
-    static UnsignedOrNone getFieldIndex(Decl *F);
+  private:
+    // All nodes of the path.
+    VecTy Nodes;
+    // Auxiliary container to be able to answer "Do we have a cycle ending
+    // at last element?" as fast as possible.
+    // We count each Decl's occurrence over the path.
+    llvm::SmallDenseMap<Decl *, int, 32> Aux;
   };
 
+private:
+  std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
+
+  /// The path which we go through during the import of a given AST node.
+  ImportPathTy ImportPath;
+  /// Sometimes we have to save some part of an import path, so later we can
+  /// set up properties to the saved nodes.
+  /// We may have several of these import paths associated to one Decl.
+  using SavedImportPathsForOneDecl = llvm::SmallVector<ImportPathTy::VecTy, 32>;
+  using SavedImportPathsTy =
+      llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>;
+  SavedImportPathsTy SavedImportPaths;
+
+  /// The contexts we're importing to and from.
+  ASTContext &ToContext, &FromContext;
+
+  /// The file managers we're importing to and from.
+  FileManager &ToFileManager, &FromFileManager;
+
+  /// Whether to perform a minimal import.
+  bool Minimal;
+
+  ODRHandlingType ODRHandling;
+
+  /// Whether the last diagnostic came from the "from" context.
+  bool LastDiagFromFrom = false;
+
+  /// Mapping from the already-imported types in the "from" context
+  /// to the corresponding types in the "to" context.
+  llvm::DenseMap<const Type *, const Type *> ImportedTypes;
+
+  /// Mapping from the already-imported declarations in the "from"
+  /// context to the corresponding declarations in the "to" context.
+  llvm::DenseMap<Decl *, Decl *> ImportedDecls;
+
+  /// Mapping from the already-imported declarations in the "from"
+  /// context to the error status of the import of that declaration.
+  /// This map contains only the declarations that were not correctly
+  /// imported. The same declaration may or may not be included in
+  /// ImportedDecls. This map is updated continuously during imports and never
+  /// cleared (like ImportedDecls).
+  llvm::DenseMap<Decl *, ASTImportError> ImportDeclErrors;
+
+  /// Mapping from the already-imported declarations in the "to"
+  /// context to the corresponding declarations in the "from" context.
+  llvm::DenseMap<Decl *, Decl *> ImportedFromDecls;
+
+  /// Mapping from the already-imported statements in the "from"
+  /// context to the corresponding statements in the "to" context.
+  llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
+
+  /// Mapping from the already-imported FileIDs in the "from" source
+  /// manager to the corresponding FileIDs in the "to" source manager.
+  llvm::DenseMap<FileID, FileID> ImportedFileIDs;
+
+  /// Mapping from the already-imported CXXBasesSpecifier in
+  ///  the "from" source manager to the corresponding CXXBasesSpecifier
+  ///  in the "to" source manager.
+  ImportedCXXBaseSpecifierMap ImportedCXXBaseSpecifiers;
+
+  /// Declaration (from, to) pairs that are known not to be equivalent
+  /// (which we have already complained about).
+  NonEquivalentDeclSet NonEquivalentDecls;
+
+  using FoundDeclsTy = SmallVector<NamedDecl *, 2>;
+  FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
+
+  void AddToLookupTable(Decl *ToD);
+
+protected:
+  /// Can be overwritten by subclasses to implement their own import logic.
+  /// The overwritten method should call this method if it didn't import the
+  /// decl on its own.
+  virtual Expected<Decl *> ImportImpl(Decl *From);
+
+  /// Used only in unittests to verify the behaviour of the error handling.
+  virtual bool returnWithErrorInTest() { return false; };
+
+public:
+  /// \param ToContext The context we'll be importing into.
+  ///
+  /// \param ToFileManager The file manager we'll be importing into.
+  ///
+  /// \param FromContext The context we'll be importing from.
+  ///
+  /// \param FromFileManager The file manager we'll be importing into.
+  ///
+  /// \param MinimalImport If true, the importer will attempt to import
+  /// as little as it can, e.g., by importing declarations as forward
+  /// declarations that can be completed at a later point.
+  ///
+  /// \param SharedState The importer specific lookup table which may be
+  /// shared amongst several ASTImporter objects.
+  /// If not set then the original C/C++ lookup is used.
+  ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
+              ASTContext &FromContext, FileManager &FromFileManager,
+              bool MinimalImport,
+              std::shared_ptr<ASTImporterSharedState> SharedState = nullptr);
+
+  virtual ~ASTImporter();
+
+  /// Whether the importer will perform a minimal import, creating
+  /// to-be-completed forward declarations when possible.
+  bool isMinimalImport() const { return Minimal; }
+
+  void setODRHandling(ODRHandlingType T) { ODRHandling = T; }
+
+  /// \brief Import the given object, returns the result.
+  ///
+  /// \param To Import the object into this variable.
+  /// \param From Object to import.
+  /// \return Error information (success or error).
+  template <typename ImportT>
+  [[nodiscard]] llvm::Error importInto(ImportT &To, const ImportT &From) {
+    auto ToOrErr = Import(From);
+    if (ToOrErr)
+      To = *ToOrErr;
+    return ToOrErr.takeError();
+  }
+
+  /// Import cleanup objects owned by ExprWithCleanup.
+  llvm::Expected<ExprWithCleanups::CleanupObject>
+  Import(ExprWithCleanups::CleanupObject From);
+
+  /// Import the given type from the "from" context into the "to"
+  /// context.
+  ///
+  /// \returns The equivalent type in the "to" context, or the import error.
+  llvm::Expected<const Type *> Import(const Type *FromT);
+
+  /// Import the given qualified type from the "from" context into the "to"
+  /// context. A null type is imported as a null type (no error).
+  ///
+  /// \returns The equivalent type in the "to" context, or the import error.
+  llvm::Expected<QualType> Import(QualType FromT);
+
+  /// Import the given type source information from the
+  /// "from" context into the "to" context.
+  ///
+  /// \returns The equivalent type source information in the "to"
+  /// context, or the import error.
+  llvm::Expected<TypeSourceInfo *> Import(TypeSourceInfo *FromTSI);
+
+  /// Import the given attribute from the "from" context into the
+  /// "to" context.
+  ///
+  /// \returns The equivalent attribute in the "to" context, or the import
+  /// error.
+  llvm::Expected<Attr *> Import(const Attr *FromAttr);
+
+  /// Import the given declaration from the "from" context into the
+  /// "to" context.
+  ///
+  /// \returns The equivalent declaration in the "to" context, or the import
+  /// error.
+  llvm::Expected<Decl *> Import(Decl *FromD);
+  llvm::Expected<const Decl *> Import(const Decl *FromD) {
+    return Import(const_cast<Decl *>(FromD));
+  }
+
+  llvm::Expected<InheritedConstructor> Import(const InheritedConstructor &From);
+
+  /// Return the copy of the given declaration in the "to" context if
+  /// it has already been imported from the "from" context.  Otherwise return
+  /// nullptr.
+  Decl *GetAlreadyImportedOrNull(const Decl *FromD) const;
+
+  /// Return the translation unit from where the declaration was
+  /// imported. If it does not exist nullptr is returned.
+  TranslationUnitDecl *GetFromTU(Decl *ToD);
+
+  /// Return the declaration in the "from" context from which the declaration
+  /// in the "to" context was imported. If it was not imported or of the wrong
+  /// type a null value is returned.
+  template <typename DeclT>
+  std::optional<DeclT *> getImportedFromDecl(const DeclT *ToD) const {
+    auto FromI = ImportedFromDecls.find(ToD);
+    if (FromI == ImportedFromDecls.end())
+      return {};
+    auto *FromD = dyn_cast<DeclT>(FromI->second);
+    if (!FromD)
+      return {};
+    return FromD;
+  }
+
+  /// Import the given declaration context from the "from"
+  /// AST context into the "to" AST context.
+  ///
+  /// \returns the equivalent declaration context in the "to"
+  /// context, or error value.
+  llvm::Expected<DeclContext *> ImportContext(DeclContext *FromDC);
+
+  /// Import the given expression from the "from" context into the
+  /// "to" context.
+  ///
+  /// \returns The equivalent expression in the "to" context, or the import
+  /// error.
+  llvm::Expected<Expr *> Import(Expr *FromE);
+
+  /// Import the given statement from the "from" context into the
+  /// "to" context.
+  ///
+  /// \returns The equivalent statement in the "to" context, or the import
+  /// error.
+  llvm::Expected<Stmt *> Import(Stmt *FromS);
+
+  /// Import the given nested-name-specifier from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent nested-name-specifier in the "to"
+  /// context, or the import error.
+  llvm::Expected<NestedNameSpecifier *> Import(NestedNameSpecifier *FromNNS);
+
+  /// Import the given nested-name-specifier-loc from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent nested-name-specifier-loc in the "to"
+  /// context, or the import error.
+  llvm::Expected<NestedNameSpecifierLoc> Import(NestedNameSpecifierLoc FromNNS);
+
+  /// Import the given template name from the "from" context into the
+  /// "to" context, or the import error.
+  llvm::Expected<TemplateName> Import(TemplateName From);
+
+  /// Import the given source location from the "from" context into
+  /// the "to" context.
+  ///
+  /// \returns The equivalent source location in the "to" context, or the
+  /// import error.
+  llvm::Expected<SourceLocation> Import(SourceLocation FromLoc);
+
+  /// Import the given source range from the "from" context into
+  /// the "to" context.
+  ///
+  /// \returns The equivalent source range in the "to" context, or the import
+  /// error.
+  llvm::Expected<SourceRange> Import(SourceRange FromRange);
+
+  /// Import the given declaration name from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent declaration name in the "to" context, or the
+  /// import error.
+  llvm::Expected<DeclarationName> Import(DeclarationName FromName);
+
+  /// Import the given identifier from the "from" context
+  /// into the "to" context.
+  ///
+  /// \returns The equivalent identifier in the "to" context. Note: It
+  /// returns nullptr only if the FromId was nullptr.
+  IdentifierInfo *Import(const IdentifierInfo *FromId);
+
+  /// Import the given identifier or overloaded operator from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent identifier or overloaded operator in the "to"
+  /// context.
+  IdentifierOrOverloadedOperator Import(IdentifierOrOverloadedOperator FromIO);
+
+  /// Import the given Objective-C selector from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent selector in the "to" context, or the import
+  /// error.
+  llvm::Expected<Selector> Import(Selector FromSel);
+
+  /// Import the given file ID from the "from" context into the
+  /// "to" context.
+  ///
+  /// \returns The equivalent file ID in the source manager of the "to"
+  /// context, or the import error.
+  llvm::Expected<FileID> Import(FileID, bool IsBuiltin = false);
+
+  /// Import the given C++ constructor initializer from the "from"
+  /// context into the "to" context.
+  ///
+  /// \returns The equivalent initializer in the "to" context, or the import
+  /// error.
+  llvm::Expected<CXXCtorInitializer *> Import(CXXCtorInitializer *FromInit);
+
+  /// Import the given CXXBaseSpecifier from the "from" context into
+  /// the "to" context.
+  ///
+  /// \returns The equivalent CXXBaseSpecifier in the source manager of the
+  /// "to" context, or the import error.
+  llvm::Expected<CXXBaseSpecifier *> Import(const CXXBaseSpecifier *FromSpec);
+
+  /// Import the given APValue from the "from" context into
+  /// the "to" context.
+  ///
+  /// \return the equivalent APValue in the "to" context or the import
+  /// error.
+  llvm::Expected<APValue> Import(const APValue &FromValue);
+
+  /// Import the definition of the given declaration, including all of
+  /// the declarations it contains.
+  [[nodiscard]] llvm::Error ImportDefinition(Decl *From);
+
+  llvm::Error
+  ImportTemplateArguments(ArrayRef<TemplateArgument> FromArgs,
+                          SmallVectorImpl<TemplateArgument> &ToArgs);
+  Expected<TemplateArgument> Import(const TemplateArgument &From);
+
+  /// Cope with a name conflict when importing a declaration into the
+  /// given context.
+  ///
+  /// This routine is invoked whenever there is a name conflict while
+  /// importing a declaration. The returned name will become the name of the
+  /// imported declaration. By default, the returned name is the same as the
+  /// original name, leaving the conflict unresolve such that name lookup
+  /// for this name is likely to find an ambiguity later.
+  ///
+  /// Subclasses may override this routine to resolve the conflict, e.g., by
+  /// renaming the declaration being imported.
+  ///
+  /// \param Name the name of the declaration being imported, which conflicts
+  /// with other declarations.
+  ///
+  /// \param DC the declaration context (in the "to" AST context) in which
+  /// the name is being imported.
+  ///
+  /// \param IDNS the identifier namespace in which the name will be found.
+  ///
+  /// \param Decls the set of declarations with the same name as the
+  /// declaration being imported.
+  ///
+  /// \param NumDecls the number of conflicting declarations in \p Decls.
+  ///
+  /// \returns the name that the newly-imported declaration should have. Or
+  /// an error if we can't handle the name conflict.
+  virtual Expected<DeclarationName>
+  HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS,
+                     NamedDecl **Decls, unsigned NumDecls);
+
+  /// Retrieve the context that AST nodes are being imported into.
+  ASTContext &getToContext() const { return ToContext; }
+
+  /// Retrieve the context that AST nodes are being imported from.
+  ASTContext &getFromContext() const { return FromContext; }
+
+  /// Retrieve the file manager that AST nodes are being imported into.
+  FileManager &getToFileManager() const { return ToFileManager; }
+
+  /// Retrieve the file manager that AST nodes are being imported from.
+  FileManager &getFromFileManager() const { return FromFileManager; }
+
+  /// Report a diagnostic in the "to" context.
+  DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID);
+
+  /// Report a diagnostic in the "from" context.
+  DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID);
+
+  /// Return the set of declarations that we know are not equivalent.
+  NonEquivalentDeclSet &getNonEquivalentDecls() { return NonEquivalentDecls; }
+
+  /// Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
+  /// Mark the Decl as complete, filling it in as much as possible.
+  ///
+  /// \param D A declaration in the "to" context.
+  virtual void CompleteDecl(Decl *D);
+
+  /// Subclasses can override this function to observe all of the \c From ->
+  /// \c To declaration mappings as they are imported.
+  virtual void Imported(Decl *From, Decl *To) {}
+
+  void RegisterImportedDecl(Decl *FromD, Decl *ToD);
+
+  /// Store and assign the imported declaration to its counterpart.
+  /// It may happen that several decls from the 'from' context are mapped to
+  /// the same decl in the 'to' context.
+  Decl *MapImported(Decl *From, Decl *To);
+
+  /// Called by StructuralEquivalenceContext.  If a RecordDecl is
+  /// being compared to another RecordDecl as part of import, completing the
+  /// other RecordDecl may trigger importation of the first RecordDecl. This
+  /// happens especially for anonymous structs.  If the original of the second
+  /// RecordDecl can be found, we can complete it without the need for
+  /// importation, eliminating this loop.
+  virtual Decl *GetOriginalDecl(Decl *To) { return nullptr; }
+
+  /// Return if import of the given declaration has failed and if yes
+  /// the kind of the problem. This gives the first error encountered with
+  /// the node.
+  std::optional<ASTImportError> getImportDeclErrorIfAny(Decl *FromD) const;
+
+  /// Mark (newly) imported declaration with error.
+  void setImportDeclError(Decl *From, ASTImportError Error);
+
+  /// Determine whether the given types are structurally
+  /// equivalent.
+  bool IsStructurallyEquivalent(QualType From, QualType To,
+                                bool Complain = true);
+
+  /// Determine the index of a field in its parent record.
+  /// F should be a field (or indirect field) declaration.
+  /// \returns The index of the field in its parent context (starting from 0).
+  /// On error `std::nullopt` is returned (parent context is non-record).
+  static UnsignedOrNone getFieldIndex(Decl *F);
+};
+
 } // namespace clang
 
 #endif // LLVM_CLANG_ASTIMPORTER_ASTIMPORTER_H
diff --git a/clang/include/clang/ASTImporter/ExternalASTMerger.h b/clang/include/clang/ASTImporter/ExternalASTMerger.h
index 734db7529..5164822f4 100644
--- a/clang/include/clang/ASTImporter/ExternalASTMerger.h
+++ b/clang/include/clang/ASTImporter/ExternalASTMerger.h
@@ -56,6 +56,7 @@ public:
 
   typedef std::map<const DeclContext *, DCOrigin> OriginMap;
   typedef std::vector<std::unique_ptr<ASTImporter>> ImporterVector;
+
 private:
   /// One importer exists for each source.
   ImporterVector Importers;
@@ -181,10 +182,11 @@ public:
 
   /// Sets the current log stream.
   void SetLogStream(llvm::raw_string_ostream &Stream) { LogStream = &Stream; }
+
 private:
   /// Records and origin in Origins.
   void RecordOriginImpl(const DeclContext *ToDC, DCOrigin Origin,
-                                  ASTImporter &importer);
+                        ASTImporter &importer);
 
   /// Performs an action for every DeclContext that is identified as
   /// corresponding (either by forced origin or by name lookup) to DC.
diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp
index 1c7ce10f7..e8c100408 100644
--- a/clang/lib/AST/ExternalASTSource.cpp
+++ b/clang/lib/AST/ExternalASTSource.cpp
@@ -12,9 +12,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclarationName.h"
-#include "clang/AST/ExternalASTSource.h"
 #include "clang/Basic/ASTSourceDescriptor.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
diff --git a/clang/lib/ASTImporter/ASTImporter.cpp b/clang/lib/ASTImporter/ASTImporter.cpp
index 54f6bd928..1206b47be 100644
--- a/clang/lib/ASTImporter/ASTImporter.cpp
+++ b/clang/lib/ASTImporter/ASTImporter.cpp
@@ -71,671 +71,664 @@
 
 namespace clang {
 
-  using llvm::make_error;
-  using llvm::Error;
-  using llvm::Expected;
-  using ExpectedTypePtr = llvm::Expected<const Type *>;
-  using ExpectedType = llvm::Expected<QualType>;
-  using ExpectedStmt = llvm::Expected<Stmt *>;
-  using ExpectedExpr = llvm::Expected<Expr *>;
-  using ExpectedDecl = llvm::Expected<Decl *>;
-  using ExpectedSLoc = llvm::Expected<SourceLocation>;
-  using ExpectedName = llvm::Expected<DeclarationName>;
-
-  std::string ASTImportError::toString() const {
-    // FIXME: Improve error texts.
-    switch (Error) {
-    case NameConflict:
-      return "NameConflict";
-    case UnsupportedConstruct:
-      return "UnsupportedConstruct";
-    case Unknown:
-      return "Unknown error";
-    }
-    llvm_unreachable("Invalid error code.");
-    return "Invalid error code.";
-  }
+using llvm::Error;
+using llvm::Expected;
+using llvm::make_error;
+using ExpectedTypePtr = llvm::Expected<const Type *>;
+using ExpectedType = llvm::Expected<QualType>;
+using ExpectedStmt = llvm::Expected<Stmt *>;
+using ExpectedExpr = llvm::Expected<Expr *>;
+using ExpectedDecl = llvm::Expected<Decl *>;
+using ExpectedSLoc = llvm::Expected<SourceLocation>;
+using ExpectedName = llvm::Expected<DeclarationName>;
+
+std::string ASTImportError::toString() const {
+  // FIXME: Improve error texts.
+  switch (Error) {
+  case NameConflict:
+    return "NameConflict";
+  case UnsupportedConstruct:
+    return "UnsupportedConstruct";
+  case Unknown:
+    return "Unknown error";
+  }
+  llvm_unreachable("Invalid error code.");
+  return "Invalid error code.";
+}
+
+void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
+
+std::error_code ASTImportError::convertToErrorCode() const {
+  llvm_unreachable("Function not implemented.");
+}
+
+char ASTImportError::ID;
+
+template <class T>
+static SmallVector<Decl *, 2>
+getCanonicalForwardRedeclChain(Redeclarable<T> *D) {
+  SmallVector<Decl *, 2> Redecls;
+  for (auto *R : D->getFirstDecl()->redecls()) {
+    if (R != D->getFirstDecl())
+      Redecls.push_back(R);
+  }
+  Redecls.push_back(D->getFirstDecl());
+  std::reverse(Redecls.begin(), Redecls.end());
+  return Redecls;
+}
+
+SmallVector<Decl *, 2> getCanonicalForwardRedeclChain(Decl *D) {
+  if (auto *FD = dyn_cast<FunctionDecl>(D))
+    return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
+  if (auto *VD = dyn_cast<VarDecl>(D))
+    return getCanonicalForwardRedeclChain<VarDecl>(VD);
+  if (auto *TD = dyn_cast<TagDecl>(D))
+    return getCanonicalForwardRedeclChain<TagDecl>(TD);
+  llvm_unreachable("Bad declaration kind");
+}
+
+static void updateFlags(const Decl *From, Decl *To) {
+  // Check if some flags or attrs are new in 'From' and copy into 'To'.
+  // FIXME: Other flags or attrs?
+  if (From->isUsed(false) && !To->isUsed(false))
+    To->setIsUsed();
+}
+
+/// How to handle import errors that occur when import of a child declaration
+/// of a DeclContext fails.
+class ChildErrorHandlingStrategy {
+  /// This context is imported (in the 'from' domain).
+  /// It is nullptr if a non-DeclContext is imported.
+  const DeclContext *const FromDC;
+  /// Ignore import errors of the children.
+  /// If true, the context can be imported successfully if a child
+  /// of it failed to import. Otherwise the import errors of the child nodes
+  /// are accumulated (joined) into the import error object of the parent.
+  /// (Import of a parent can fail in other ways.)
+  bool const IgnoreChildErrors;
 
-  void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
+public:
+  ChildErrorHandlingStrategy(const DeclContext *FromDC)
+      : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
+  ChildErrorHandlingStrategy(const Decl *FromD)
+      : FromDC(dyn_cast<DeclContext>(FromD)),
+        IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
+
+  /// Process the import result of a child (of the current declaration).
+  /// \param ResultErr The import error that can be used as result of
+  /// importing the parent. This may be changed by the function.
+  /// \param ChildErr Result of importing a child. Can be success or error.
+  void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
+    if (ChildErr && !IgnoreChildErrors)
+      ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
+    else
+      consumeError(std::move(ChildErr));
+  }
 
-  std::error_code ASTImportError::convertToErrorCode() const {
-    llvm_unreachable("Function not implemented.");
+  /// Determine if import failure of a child does not cause import failure of
+  /// its parent.
+  bool ignoreChildErrorOnParent(Decl *FromChildD) const {
+    if (!IgnoreChildErrors || !FromDC)
+      return false;
+    return FromDC->containsDecl(FromChildD);
   }
+};
 
-  char ASTImportError::ID;
+class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
+                        public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
+                        public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
+  ASTImporter &Importer;
 
-  template <class T>
-  static SmallVector<Decl *, 2>
-  getCanonicalForwardRedeclChain(Redeclarable<T> *D) {
-    SmallVector<Decl *, 2> Redecls;
-    for (auto *R : D->getFirstDecl()->redecls()) {
-      if (R != D->getFirstDecl())
-        Redecls.push_back(R);
-    }
-    Redecls.push_back(D->getFirstDecl());
-    std::reverse(Redecls.begin(), Redecls.end());
-    return Redecls;
-  }
-
-  SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) {
-    if (auto *FD = dyn_cast<FunctionDecl>(D))
-      return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
-    if (auto *VD = dyn_cast<VarDecl>(D))
-      return getCanonicalForwardRedeclChain<VarDecl>(VD);
-    if (auto *TD = dyn_cast<TagDecl>(D))
-      return getCanonicalForwardRedeclChain<TagDecl>(TD);
-    llvm_unreachable("Bad declaration kind");
-  }
-
-  static void updateFlags(const Decl *From, Decl *To) {
-    // Check if some flags or attrs are new in 'From' and copy into 'To'.
-    // FIXME: Other flags or attrs?
-    if (From->isUsed(false) && !To->isUsed(false))
-      To->setIsUsed();
-  }
-
-  /// How to handle import errors that occur when import of a child declaration
-  /// of a DeclContext fails.
-  class ChildErrorHandlingStrategy {
-    /// This context is imported (in the 'from' domain).
-    /// It is nullptr if a non-DeclContext is imported.
-    const DeclContext *const FromDC;
-    /// Ignore import errors of the children.
-    /// If true, the context can be imported successfully if a child
-    /// of it failed to import. Otherwise the import errors of the child nodes
-    /// are accumulated (joined) into the import error object of the parent.
-    /// (Import of a parent can fail in other ways.)
-    bool const IgnoreChildErrors;
-
-  public:
-    ChildErrorHandlingStrategy(const DeclContext *FromDC)
-        : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
-    ChildErrorHandlingStrategy(const Decl *FromD)
-        : FromDC(dyn_cast<DeclContext>(FromD)),
-          IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
-
-    /// Process the import result of a child (of the current declaration).
-    /// \param ResultErr The import error that can be used as result of
-    /// importing the parent. This may be changed by the function.
-    /// \param ChildErr Result of importing a child. Can be success or error.
-    void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
-      if (ChildErr && !IgnoreChildErrors)
-        ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
-      else
-        consumeError(std::move(ChildErr));
-    }
+  // Use this instead of Importer.importInto .
+  template <typename ImportT>
+  [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
+    return Importer.importInto(To, From);
+  }
 
-    /// Determine if import failure of a child does not cause import failure of
-    /// its parent.
-    bool ignoreChildErrorOnParent(Decl *FromChildD) const {
-      if (!IgnoreChildErrors || !FromDC)
-        return false;
-      return FromDC->containsDecl(FromChildD);
-    }
-  };
+  // Use this to import pointers of specific type.
+  template <typename ImportT>
+  [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
+    auto ToOrErr = Importer.Import(From);
+    if (ToOrErr)
+      To = cast_or_null<ImportT>(*ToOrErr);
+    return ToOrErr.takeError();
+  }
 
-  class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
-                          public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
-                          public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
-    ASTImporter &Importer;
+  // Call the import function of ASTImporter for a baseclass of type `T` and
+  // cast the return value to `T`.
+  template <typename T>
+  auto import(T *From)
+      -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
+                            Expected<T *>> {
+    auto ToOrErr = Importer.Import(From);
+    if (!ToOrErr)
+      return ToOrErr.takeError();
+    return cast_or_null<T>(*ToOrErr);
+  }
 
-    // Use this instead of Importer.importInto .
-    template <typename ImportT>
-    [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
-      return Importer.importInto(To, From);
-    }
+  template <typename T> auto import(const T *From) {
+    return import(const_cast<T *>(From));
+  }
 
-    // Use this to import pointers of specific type.
-    template <typename ImportT>
-    [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
-      auto ToOrErr = Importer.Import(From);
-      if (ToOrErr)
-        To = cast_or_null<ImportT>(*ToOrErr);
-      return ToOrErr.takeError();
-    }
+  // Call the import function of ASTImporter for type `T`.
+  template <typename T> Expected<T> import(const T &From) {
+    return Importer.Import(From);
+  }
 
-    // Call the import function of ASTImporter for a baseclass of type `T` and
-    // cast the return value to `T`.
-    template <typename T>
-    auto import(T *From)
-        -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
-                              Expected<T *>> {
-      auto ToOrErr = Importer.Import(From);
-      if (!ToOrErr)
-        return ToOrErr.takeError();
-      return cast_or_null<T>(*ToOrErr);
-    }
+  // Import an std::optional<T> by importing the contained T, if any.
+  template <typename T>
+  Expected<std::optional<T>> import(std::optional<T> From) {
+    if (!From)
+      return std::nullopt;
+    return import(*From);
+  }
 
-    template <typename T>
-    auto import(const T *From) {
-      return import(const_cast<T *>(From));
-    }
+  ExplicitSpecifier importExplicitSpecifier(Error &Err,
+                                            ExplicitSpecifier ESpec);
 
-    // Call the import function of ASTImporter for type `T`.
-    template <typename T>
-    Expected<T> import(const T &From) {
-      return Importer.Import(From);
+  // Wrapper for an overload set.
+  template <typename ToDeclT> struct CallOverloadedCreateFun {
+    template <typename... Args> decltype(auto) operator()(Args &&...args) {
+      return ToDeclT::Create(std::forward<Args>(args)...);
     }
+  };
 
-    // Import an std::optional<T> by importing the contained T, if any.
-    template <typename T>
-    Expected<std::optional<T>> import(std::optional<T> From) {
-      if (!From)
-        return std::nullopt;
-      return import(*From);
+  // Always use these functions to create a Decl during import. There are
+  // certain tasks which must be done after the Decl was created, e.g. we
+  // must immediately register that as an imported Decl.  The parameter `ToD`
+  // will be set to the newly created Decl or if had been imported before
+  // then to the already imported Decl.  Returns a bool value set to true if
+  // the `FromD` had been imported before.
+  template <typename ToDeclT, typename FromDeclT, typename... Args>
+  [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
+                                             Args &&...args) {
+    // There may be several overloads of ToDeclT::Create. We must make sure
+    // to call the one which would be chosen by the arguments, thus we use a
+    // wrapper for the overload set.
+    CallOverloadedCreateFun<ToDeclT> OC;
+    return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
+                                          std::forward<Args>(args)...);
+  }
+  // Use this overload if a special Type is needed to be created.  E.g if we
+  // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
+  // then:
+  // TypedefNameDecl *ToTypedef;
+  // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
+  template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
+            typename... Args>
+  [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
+                                             Args &&...args) {
+    CallOverloadedCreateFun<NewDeclT> OC;
+    return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
+                                          std::forward<Args>(args)...);
+  }
+  // Use this version if a special create function must be
+  // used, e.g. CXXRecordDecl::CreateLambda .
+  template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
+            typename... Args>
+  [[nodiscard]] bool
+  GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
+                                 FromDeclT *FromD, Args &&...args) {
+    if (Importer.getImportDeclErrorIfAny(FromD)) {
+      ToD = nullptr;
+      return true; // Already imported but with error.
     }
+    ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
+    if (ToD)
+      return true; // Already imported.
+    ToD = CreateFun(std::forward<Args>(args)...);
+    // Keep track of imported Decls.
+    Importer.RegisterImportedDecl(FromD, ToD);
+    Importer.SharedState->markAsNewDecl(ToD);
+    InitializeImportedDecl(FromD, ToD);
+    return false; // A new Decl is created.
+  }
+
+  void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
+    ToD->IdentifierNamespace = FromD->IdentifierNamespace;
+    if (FromD->isUsed())
+      ToD->setIsUsed();
+    if (FromD->isImplicit())
+      ToD->setImplicit();
+  }
+
+  // Check if we have found an existing definition.  Returns with that
+  // definition if yes, otherwise returns null.
+  Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
+    const FunctionDecl *Definition = nullptr;
+    if (D->doesThisDeclarationHaveABody() && FoundFunction->hasBody(Definition))
+      return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
+    return nullptr;
+  }
 
-    ExplicitSpecifier importExplicitSpecifier(Error &Err,
-                                              ExplicitSpecifier ESpec);
+  void addDeclToContexts(Decl *FromD, Decl *ToD) {
+    if (Importer.isMinimalImport()) {
+      // In minimal import case the decl must be added even if it is not
+      // contained in original context, for LLDB compatibility.
+      // FIXME: Check if a better solution is possible.
+      if (!FromD->getDescribedTemplate() &&
+          FromD->getFriendObjectKind() == Decl::FOK_None)
+        ToD->getLexicalDeclContext()->addDeclInternal(ToD);
+      return;
+    }
 
-    // Wrapper for an overload set.
-    template <typename ToDeclT> struct CallOverloadedCreateFun {
-      template <typename... Args> decltype(auto) operator()(Args &&... args) {
-        return ToDeclT::Create(std::forward<Args>(args)...);
-      }
-    };
+    DeclContext *FromDC = FromD->getDeclContext();
+    DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
+    DeclContext *ToDC = ToD->getDeclContext();
+    DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
 
-    // Always use these functions to create a Decl during import. There are
-    // certain tasks which must be done after the Decl was created, e.g. we
-    // must immediately register that as an imported Decl.  The parameter `ToD`
-    // will be set to the newly created Decl or if had been imported before
-    // then to the already imported Decl.  Returns a bool value set to true if
-    // the `FromD` had been imported before.
-    template <typename ToDeclT, typename FromDeclT, typename... Args>
-    [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
-                                               Args &&...args) {
-      // There may be several overloads of ToDeclT::Create. We must make sure
-      // to call the one which would be chosen by the arguments, thus we use a
-      // wrapper for the overload set.
-      CallOverloadedCreateFun<ToDeclT> OC;
-      return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
-                                            std::forward<Args>(args)...);
+    bool Visible = false;
+    if (FromDC->containsDeclAndLoad(FromD)) {
+      ToDC->addDeclInternal(ToD);
+      Visible = true;
     }
-    // Use this overload if a special Type is needed to be created.  E.g if we
-    // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
-    // then:
-    // TypedefNameDecl *ToTypedef;
-    // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
-    template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
-              typename... Args>
-    [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
-                                               Args &&...args) {
-      CallOverloadedCreateFun<NewDeclT> OC;
-      return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
-                                            std::forward<Args>(args)...);
+    if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
+      ToLexicalDC->addDeclInternal(ToD);
+      Visible = true;
     }
-    // Use this version if a special create function must be
-    // used, e.g. CXXRecordDecl::CreateLambda .
-    template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
-              typename... Args>
-    [[nodiscard]] bool
-    GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
-                                   FromDeclT *FromD, Args &&...args) {
-      if (Importer.getImportDeclErrorIfAny(FromD)) {
-        ToD = nullptr;
-        return true; // Already imported but with error.
+
+    // If the Decl was added to any context, it was made already visible.
+    // Otherwise it is still possible that it should be visible.
+    if (!Visible) {
+      if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
+        auto *ToNamed = cast<NamedDecl>(ToD);
+        DeclContextLookupResult FromLookup =
+            FromDC->lookup(FromNamed->getDeclName());
+        if (llvm::is_contained(FromLookup, FromNamed))
+          ToDC->makeDeclVisibleInContext(ToNamed);
       }
-      ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
-      if (ToD)
-        return true; // Already imported.
-      ToD = CreateFun(std::forward<Args>(args)...);
-      // Keep track of imported Decls.
-      Importer.RegisterImportedDecl(FromD, ToD);
-      Importer.SharedState->markAsNewDecl(ToD);
-      InitializeImportedDecl(FromD, ToD);
-      return false; // A new Decl is created.
     }
+  }
 
-    void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
-      ToD->IdentifierNamespace = FromD->IdentifierNamespace;
-      if (FromD->isUsed())
-        ToD->setIsUsed();
-      if (FromD->isImplicit())
-        ToD->setImplicit();
-    }
+  void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
+                                              DeclContext *OldDC) {
+    ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
+    if (!LT)
+      return;
 
-    // Check if we have found an existing definition.  Returns with that
-    // definition if yes, otherwise returns null.
-    Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
-      const FunctionDecl *Definition = nullptr;
-      if (D->doesThisDeclarationHaveABody() &&
-          FoundFunction->hasBody(Definition))
-        return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
-      return nullptr;
+    for (NamedDecl *TP : Params)
+      LT->update(TP, OldDC);
+  }
+
+  void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
+    updateLookupTableForTemplateParameters(
+        Params, Importer.getToContext().getTranslationUnitDecl());
+  }
+
+  template <typename TemplateParmDeclT>
+  Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
+                                               TemplateParmDeclT *ToD) {
+    if (D->hasDefaultArgument()) {
+      if (D->defaultArgumentWasInherited()) {
+        Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
+            import(D->getDefaultArgStorage().getInheritedFrom());
+        if (!ToInheritedFromOrErr)
+          return ToInheritedFromOrErr.takeError();
+        TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
+        if (!ToInheritedFrom->hasDefaultArgument()) {
+          // Resolve possible circular dependency between default value of the
+          // template argument and the template declaration.
+          Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
+              import(D->getDefaultArgStorage()
+                         .getInheritedFrom()
+                         ->getDefaultArgument());
+          if (!ToInheritedDefaultArgOrErr)
+            return ToInheritedDefaultArgOrErr.takeError();
+          ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
+                                              *ToInheritedDefaultArgOrErr);
+        }
+        ToD->setInheritedDefaultArgument(ToD->getASTContext(), ToInheritedFrom);
+      } else {
+        Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
+            import(D->getDefaultArgument());
+        if (!ToDefaultArgOrErr)
+          return ToDefaultArgOrErr.takeError();
+        // Default argument could have been set in the
+        // '!ToInheritedFrom->hasDefaultArgument()' branch above.
+        if (!ToD->hasDefaultArgument())
+          ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+      }
     }
+    return Error::success();
+  }
 
-    void addDeclToContexts(Decl *FromD, Decl *ToD) {
-      if (Importer.isMinimalImport()) {
-        // In minimal import case the decl must be added even if it is not
-        // contained in original context, for LLDB compatibility.
-        // FIXME: Check if a better solution is possible.
-        if (!FromD->getDescribedTemplate() &&
-            FromD->getFriendObjectKind() == Decl::FOK_None)
-          ToD->getLexicalDeclContext()->addDeclInternal(ToD);
-        return;
-      }
+public:
+  explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
 
-      DeclContext *FromDC = FromD->getDeclContext();
-      DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
-      DeclContext *ToDC = ToD->getDeclContext();
-      DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
+  using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit;
+  using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit;
+  using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit;
 
-      bool Visible = false;
-      if (FromDC->containsDeclAndLoad(FromD)) {
-        ToDC->addDeclInternal(ToD);
-        Visible = true;
-      }
-      if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
-        ToLexicalDC->addDeclInternal(ToD);
-        Visible = true;
-      }
+  // Importing types
+  ExpectedType VisitType(const Type *T);
+#define TYPE(Class, Base) ExpectedType Visit##Class##Type(const Class##Type *T);
+#include "clang/AST/TypeNodes.inc"
 
-      // If the Decl was added to any context, it was made already visible.
-      // Otherwise it is still possible that it should be visible.
-      if (!Visible) {
-        if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
-          auto *ToNamed = cast<NamedDecl>(ToD);
-          DeclContextLookupResult FromLookup =
-              FromDC->lookup(FromNamed->getDeclName());
-          if (llvm::is_contained(FromLookup, FromNamed))
-            ToDC->makeDeclVisibleInContext(ToNamed);
-        }
-      }
-    }
+  // Importing declarations
+  Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
+                        SourceLocation &Loc);
+  Error ImportDeclParts(NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
+                        DeclarationName &Name, NamedDecl *&ToD,
+                        SourceLocation &Loc);
+  Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
+  Error ImportDeclarationNameLoc(const DeclarationNameInfo &From,
+                                 DeclarationNameInfo &To);
+  Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
+  Error ImportDeclContext(Decl *From, DeclContext *&ToDC,
+                          DeclContext *&ToLexicalDC);
+  Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
+
+  Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
+  Expected<CXXCastPath> ImportCastPath(CastExpr *E);
+  Expected<APValue> ImportAPValue(const APValue &FromValue);
+
+  using Designator = DesignatedInitExpr::Designator;
+
+  /// What we should import from the definition.
+  enum ImportDefinitionKind {
+    /// Import the default subset of the definition, which might be
+    /// nothing (if minimal import is set) or might be everything (if minimal
+    /// import is not set).
+    IDK_Default,
+    /// Import everything.
+    IDK_Everything,
+    /// Import only the bare bones needed to establish a valid
+    /// DeclContext.
+    IDK_Basic
+  };
 
-    void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
-                                                DeclContext *OldDC) {
-      ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
-      if (!LT)
-        return;
+  bool shouldForceImportDeclContext(ImportDefinitionKind IDK) {
+    return IDK == IDK_Everything ||
+           (IDK == IDK_Default && !Importer.isMinimalImport());
+  }
 
-      for (NamedDecl *TP : Params)
-        LT->update(TP, OldDC);
-    }
+  Error ImportInitializer(VarDecl *From, VarDecl *To);
+  Error ImportDefinition(RecordDecl *From, RecordDecl *To,
+                         ImportDefinitionKind Kind = IDK_Default);
+  Error ImportDefinition(EnumDecl *From, EnumDecl *To,
+                         ImportDefinitionKind Kind = IDK_Default);
+  Error ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
+                         ImportDefinitionKind Kind = IDK_Default);
+  Error ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To,
+                         ImportDefinitionKind Kind = IDK_Default);
+  Error ImportTemplateArguments(ArrayRef<TemplateArgument> FromArgs,
+                                SmallVectorImpl<TemplateArgument> &ToArgs);
+  Expected<TemplateArgument>
+  ImportTemplateArgument(const TemplateArgument &From);
 
-    void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
-      updateLookupTableForTemplateParameters(
-          Params, Importer.getToContext().getTranslationUnitDecl());
-    }
+  template <typename InContainerTy>
+  Error ImportTemplateArgumentListInfo(const InContainerTy &Container,
+                                       TemplateArgumentListInfo &ToTAInfo);
 
-    template <typename TemplateParmDeclT>
-    Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
-                                                 TemplateParmDeclT *ToD) {
-      if (D->hasDefaultArgument()) {
-        if (D->defaultArgumentWasInherited()) {
-          Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
-              import(D->getDefaultArgStorage().getInheritedFrom());
-          if (!ToInheritedFromOrErr)
-            return ToInheritedFromOrErr.takeError();
-          TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
-          if (!ToInheritedFrom->hasDefaultArgument()) {
-            // Resolve possible circular dependency between default value of the
-            // template argument and the template declaration.
-            Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
-                import(D->getDefaultArgStorage()
-                           .getInheritedFrom()
-                           ->getDefaultArgument());
-            if (!ToInheritedDefaultArgOrErr)
-              return ToInheritedDefaultArgOrErr.takeError();
-            ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
-                                                *ToInheritedDefaultArgOrErr);
-          }
-          ToD->setInheritedDefaultArgument(ToD->getASTContext(),
-                                           ToInheritedFrom);
-        } else {
-          Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
-              import(D->getDefaultArgument());
-          if (!ToDefaultArgOrErr)
-            return ToDefaultArgOrErr.takeError();
-          // Default argument could have been set in the
-          // '!ToInheritedFrom->hasDefaultArgument()' branch above.
-          if (!ToD->hasDefaultArgument())
-            ToD->setDefaultArgument(Importer.getToContext(),
-                                    *ToDefaultArgOrErr);
-        }
-      }
-      return Error::success();
-    }
+  template <typename InContainerTy>
+  Error ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc,
+                                       SourceLocation FromRAngleLoc,
+                                       const InContainerTy &Container,
+                                       TemplateArgumentListInfo &Result);
 
-  public:
-    explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
+  using TemplateArgsTy = SmallVector<TemplateArgument, 8>;
+  using FunctionTemplateAndArgsTy =
+      std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
+  Expected<FunctionTemplateAndArgsTy>
+  ImportFunctionTemplateWithTemplateArgsFromSpecialization(
+      FunctionDecl *FromFD);
 
-    using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit;
-    using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit;
-    using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit;
+  template <typename DeclTy>
+  Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
 
-    // Importing types
-    ExpectedType VisitType(const Type *T);
-#define TYPE(Class, Base)                                                    \
-    ExpectedType Visit##Class##Type(const Class##Type *T);
-#include "clang/AST/TypeNodes.inc"
+  Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
 
-    // Importing declarations
-    Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
-                          SourceLocation &Loc);
-    Error ImportDeclParts(
-        NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
-        DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
-    Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
-    Error ImportDeclarationNameLoc(
-        const DeclarationNameInfo &From, DeclarationNameInfo &To);
-    Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
-    Error ImportDeclContext(
-        Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
-    Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
-
-    Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
-    Expected<CXXCastPath> ImportCastPath(CastExpr *E);
-    Expected<APValue> ImportAPValue(const APValue &FromValue);
-
-    using Designator = DesignatedInitExpr::Designator;
-
-    /// What we should import from the definition.
-    enum ImportDefinitionKind {
-      /// Import the default subset of the definition, which might be
-      /// nothing (if minimal import is set) or might be everything (if minimal
-      /// import is not set).
-      IDK_Default,
-      /// Import everything.
-      IDK_Everything,
-      /// Import only the bare bones needed to establish a valid
-      /// DeclContext.
-      IDK_Basic
-    };
+  Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD);
 
-    bool shouldForceImportDeclContext(ImportDefinitionKind IDK) {
-      return IDK == IDK_Everything ||
-             (IDK == IDK_Default && !Importer.isMinimalImport());
-    }
+  Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
+                                      ParmVarDecl *ToParam);
 
-    Error ImportInitializer(VarDecl *From, VarDecl *To);
-    Error ImportDefinition(
-        RecordDecl *From, RecordDecl *To,
-        ImportDefinitionKind Kind = IDK_Default);
-    Error ImportDefinition(
-        EnumDecl *From, EnumDecl *To,
-        ImportDefinitionKind Kind = IDK_Default);
-    Error ImportDefinition(
-        ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
-        ImportDefinitionKind Kind = IDK_Default);
-    Error ImportDefinition(
-        ObjCProtocolDecl *From, ObjCProtocolDecl *To,
-        ImportDefinitionKind Kind = IDK_Default);
-    Error ImportTemplateArguments(ArrayRef<TemplateArgument> FromArgs,
-                                  SmallVectorImpl<TemplateArgument> &ToArgs);
-    Expected<TemplateArgument>
-    ImportTemplateArgument(const TemplateArgument &From);
-
-    template <typename InContainerTy>
-    Error ImportTemplateArgumentListInfo(
-        const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
-
-    template<typename InContainerTy>
-    Error ImportTemplateArgumentListInfo(
-      SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
-      const InContainerTy &Container, TemplateArgumentListInfo &Result);
-
-    using TemplateArgsTy = SmallVector<TemplateArgument, 8>;
-    using FunctionTemplateAndArgsTy =
-        std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
-    Expected<FunctionTemplateAndArgsTy>
-    ImportFunctionTemplateWithTemplateArgsFromSpecialization(
-        FunctionDecl *FromFD);
-
-    template <typename DeclTy>
-    Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
-
-    Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD);
-
-    Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD);
-
-    Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
-                                        ParmVarDecl *ToParam);
-
-    Expected<InheritedConstructor>
-    ImportInheritedConstructor(const InheritedConstructor &From);
-
-    template <typename T>
-    bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
-
-    bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
-                           bool IgnoreTemplateParmDepth = false);
-    ExpectedDecl VisitDecl(Decl *D);
-    ExpectedDecl VisitImportDecl(ImportDecl *D);
-    ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
-    ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
-    ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
-    ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
-    ExpectedDecl VisitBindingDecl(BindingDecl *D);
-    ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
-    ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
-    ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
-    ExpectedDecl VisitTypedefDecl(TypedefDecl *D);
-    ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D);
-    ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
-    ExpectedDecl VisitLabelDecl(LabelDecl *D);
-    ExpectedDecl VisitEnumDecl(EnumDecl *D);
-    ExpectedDecl VisitRecordDecl(RecordDecl *D);
-    ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D);
-    ExpectedDecl VisitFunctionDecl(FunctionDecl *D);
-    ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D);
-    ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D);
-    ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D);
-    ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D);
-    ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
-    ExpectedDecl VisitFieldDecl(FieldDecl *D);
-    ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D);
-    ExpectedDecl VisitFriendDecl(FriendDecl *D);
-    ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D);
-    ExpectedDecl VisitVarDecl(VarDecl *D);
-    ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D);
-    ExpectedDecl VisitParmVarDecl(ParmVarDecl *D);
-    ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D);
-    ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
-    ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D);
-    ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D);
-    ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D);
-    ExpectedDecl VisitUsingDecl(UsingDecl *D);
-    ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D);
-    ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
-    ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D);
-    ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI);
-    ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D);
-    ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
-    ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
-    ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
-    ExpectedDecl
-    VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
-
-    Expected<ObjCTypeParamList *>
-    ImportObjCTypeParamList(ObjCTypeParamList *list);
-
-    ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
-    ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
-    ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D);
-    ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D);
-    ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
-    ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
-    ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
-    ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
-    ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D);
-    ExpectedDecl VisitClassTemplateSpecializationDecl(
-                                            ClassTemplateSpecializationDecl *D);
-    ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D);
-    ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
-    ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
-
-    // Importing statements
-    ExpectedStmt VisitStmt(Stmt *S);
-    ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S);
-    ExpectedStmt VisitDeclStmt(DeclStmt *S);
-    ExpectedStmt VisitNullStmt(NullStmt *S);
-    ExpectedStmt VisitCompoundStmt(CompoundStmt *S);
-    ExpectedStmt VisitCaseStmt(CaseStmt *S);
-    ExpectedStmt VisitDefaultStmt(DefaultStmt *S);
-    ExpectedStmt VisitLabelStmt(LabelStmt *S);
-    ExpectedStmt VisitAttributedStmt(AttributedStmt *S);
-    ExpectedStmt VisitIfStmt(IfStmt *S);
-    ExpectedStmt VisitSwitchStmt(SwitchStmt *S);
-    ExpectedStmt VisitWhileStmt(WhileStmt *S);
-    ExpectedStmt VisitDoStmt(DoStmt *S);
-    ExpectedStmt VisitForStmt(ForStmt *S);
-    ExpectedStmt VisitGotoStmt(GotoStmt *S);
-    ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S);
-    ExpectedStmt VisitContinueStmt(ContinueStmt *S);
-    ExpectedStmt VisitBreakStmt(BreakStmt *S);
-    ExpectedStmt VisitReturnStmt(ReturnStmt *S);
-    // FIXME: MSAsmStmt
-    // FIXME: SEHExceptStmt
-    // FIXME: SEHFinallyStmt
-    // FIXME: SEHTryStmt
-    // FIXME: SEHLeaveStmt
-    // FIXME: CapturedStmt
-    ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S);
-    ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S);
-    ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S);
-    // FIXME: MSDependentExistsStmt
-    ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
-    ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
-    ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
-    ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S);
-    ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
-    ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
-    ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
-
-    // Importing expressions
-    ExpectedStmt VisitExpr(Expr *E);
-    ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
-    ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
-    ExpectedStmt VisitChooseExpr(ChooseExpr *E);
-    ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
-    ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
-    ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
-    ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
-    ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
-    ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
-    ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
-    ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E);
-    ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
-    ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
-    ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
-    ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
-    ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
-    ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
-    ExpectedStmt VisitStringLiteral(StringLiteral *E);
-    ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
-    ExpectedStmt VisitAtomicExpr(AtomicExpr *E);
-    ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E);
-    ExpectedStmt VisitConstantExpr(ConstantExpr *E);
-    ExpectedStmt VisitParenExpr(ParenExpr *E);
-    ExpectedStmt VisitParenListExpr(ParenListExpr *E);
-    ExpectedStmt VisitStmtExpr(StmtExpr *E);
-    ExpectedStmt VisitUnaryOperator(UnaryOperator *E);
-    ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
-    ExpectedStmt VisitBinaryOperator(BinaryOperator *E);
-    ExpectedStmt VisitConditionalOperator(ConditionalOperator *E);
-    ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
-    ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E);
-    ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E);
-    ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
-    ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E);
-    ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E);
-    ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E);
-    ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E);
-    ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E);
-    ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE);
-    ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E);
-    ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
-    ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
-    ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
-    ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
-    ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
-    ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
-    ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E);
-    ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E);
-    ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E);
-    ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E);
-    ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E);
-    ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
-    ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
-    ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
-    ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
-    ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
-    ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
-    ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E);
-    ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E);
-    ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
-    ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
-    ExpectedStmt VisitMemberExpr(MemberExpr *E);
-    ExpectedStmt VisitCallExpr(CallExpr *E);
-    ExpectedStmt VisitLambdaExpr(LambdaExpr *LE);
-    ExpectedStmt VisitInitListExpr(InitListExpr *E);
-    ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
-    ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
-    ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
-    ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
-    ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
-    ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
-    ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
-    ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
-    ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
-    ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
-
-    // Helper for chaining together multiple imports. If an error is detected,
-    // subsequent imports will return default constructed nodes, so that failure
-    // can be detected with a single conditional branch after a sequence of
-    // imports.
-    template <typename T> T importChecked(Error &Err, const T &From) {
-      // Don't attempt to import nodes if we hit an error earlier.
-      if (Err)
-        return T{};
-      Expected<T> MaybeVal = import(From);
-      if (!MaybeVal) {
-        Err = MaybeVal.takeError();
-        return T{};
-      }
-      return *MaybeVal;
-    }
+  Expected<InheritedConstructor>
+  ImportInheritedConstructor(const InheritedConstructor &From);
 
-    template<typename IIter, typename OIter>
-    Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
-      using ItemT = std::remove_reference_t<decltype(*Obegin)>;
-      for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
-        Expected<ItemT> ToOrErr = import(*Ibegin);
-        if (!ToOrErr)
-          return ToOrErr.takeError();
-        *Obegin = *ToOrErr;
-      }
-      return Error::success();
+  template <typename T>
+  bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
+
+  bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
+                         bool IgnoreTemplateParmDepth = false);
+  ExpectedDecl VisitDecl(Decl *D);
+  ExpectedDecl VisitImportDecl(ImportDecl *D);
+  ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
+  ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
+  ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
+  ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
+  ExpectedDecl VisitBindingDecl(BindingDecl *D);
+  ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
+  ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
+  ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
+  ExpectedDecl VisitTypedefDecl(TypedefDecl *D);
+  ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D);
+  ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
+  ExpectedDecl VisitLabelDecl(LabelDecl *D);
+  ExpectedDecl VisitEnumDecl(EnumDecl *D);
+  ExpectedDecl VisitRecordDecl(RecordDecl *D);
+  ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D);
+  ExpectedDecl VisitFunctionDecl(FunctionDecl *D);
+  ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D);
+  ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D);
+  ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D);
+  ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D);
+  ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
+  ExpectedDecl VisitFieldDecl(FieldDecl *D);
+  ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D);
+  ExpectedDecl VisitFriendDecl(FriendDecl *D);
+  ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D);
+  ExpectedDecl VisitVarDecl(VarDecl *D);
+  ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D);
+  ExpectedDecl VisitParmVarDecl(ParmVarDecl *D);
+  ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D);
+  ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
+  ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D);
+  ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D);
+  ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D);
+  ExpectedDecl VisitUsingDecl(UsingDecl *D);
+  ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D);
+  ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+  ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D);
+  ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI);
+  ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D);
+  ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
+  ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
+  ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
+  ExpectedDecl
+  VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
+
+  Expected<ObjCTypeParamList *>
+  ImportObjCTypeParamList(ObjCTypeParamList *list);
+
+  ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
+  ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
+  ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D);
+  ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D);
+  ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
+  ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
+  ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
+  ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
+  ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D);
+  ExpectedDecl
+  VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D);
+  ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D);
+  ExpectedDecl
+  VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
+  ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
+
+  // Importing statements
+  ExpectedStmt VisitStmt(Stmt *S);
+  ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S);
+  ExpectedStmt VisitDeclStmt(DeclStmt *S);
+  ExpectedStmt VisitNullStmt(NullStmt *S);
+  ExpectedStmt VisitCompoundStmt(CompoundStmt *S);
+  ExpectedStmt VisitCaseStmt(CaseStmt *S);
+  ExpectedStmt VisitDefaultStmt(DefaultStmt *S);
+  ExpectedStmt VisitLabelStmt(LabelStmt *S);
+  ExpectedStmt VisitAttributedStmt(AttributedStmt *S);
+  ExpectedStmt VisitIfStmt(IfStmt *S);
+  ExpectedStmt VisitSwitchStmt(SwitchStmt *S);
+  ExpectedStmt VisitWhileStmt(WhileStmt *S);
+  ExpectedStmt VisitDoStmt(DoStmt *S);
+  ExpectedStmt VisitForStmt(ForStmt *S);
+  ExpectedStmt VisitGotoStmt(GotoStmt *S);
+  ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S);
+  ExpectedStmt VisitContinueStmt(ContinueStmt *S);
+  ExpectedStmt VisitBreakStmt(BreakStmt *S);
+  ExpectedStmt VisitReturnStmt(ReturnStmt *S);
+  // FIXME: MSAsmStmt
+  // FIXME: SEHExceptStmt
+  // FIXME: SEHFinallyStmt
+  // FIXME: SEHTryStmt
+  // FIXME: SEHLeaveStmt
+  // FIXME: CapturedStmt
+  ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S);
+  ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S);
+  ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S);
+  // FIXME: MSDependentExistsStmt
+  ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S);
+  ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S);
+  ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S);
+  ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S);
+  ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S);
+  ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S);
+  ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S);
+
+  // Importing expressions
+  ExpectedStmt VisitExpr(Expr *E);
+  ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
+  ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
+  ExpectedStmt VisitChooseExpr(ChooseExpr *E);
+  ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
+  ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
+  ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
+  ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
+  ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
+  ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
+  ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
+  ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E);
+  ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
+  ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
+  ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
+  ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+  ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
+  ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
+  ExpectedStmt VisitStringLiteral(StringLiteral *E);
+  ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
+  ExpectedStmt VisitAtomicExpr(AtomicExpr *E);
+  ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E);
+  ExpectedStmt VisitConstantExpr(ConstantExpr *E);
+  ExpectedStmt VisitParenExpr(ParenExpr *E);
+  ExpectedStmt VisitParenListExpr(ParenListExpr *E);
+  ExpectedStmt VisitStmtExpr(StmtExpr *E);
+  ExpectedStmt VisitUnaryOperator(UnaryOperator *E);
+  ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
+  ExpectedStmt VisitBinaryOperator(BinaryOperator *E);
+  ExpectedStmt VisitConditionalOperator(ConditionalOperator *E);
+  ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
+  ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E);
+  ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E);
+  ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E);
+  ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E);
+  ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E);
+  ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E);
+  ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E);
+  ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E);
+  ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE);
+  ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E);
+  ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E);
+  ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
+  ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
+  ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
+  ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
+  ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E);
+  ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E);
+  ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E);
+  ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E);
+  ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E);
+  ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E);
+  ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E);
+  ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E);
+  ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E);
+  ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E);
+  ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E);
+  ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
+  ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E);
+  ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E);
+  ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E);
+  ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
+  ExpectedStmt VisitMemberExpr(MemberExpr *E);
+  ExpectedStmt VisitCallExpr(CallExpr *E);
+  ExpectedStmt VisitLambdaExpr(LambdaExpr *LE);
+  ExpectedStmt VisitInitListExpr(InitListExpr *E);
+  ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E);
+  ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E);
+  ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E);
+  ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E);
+  ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
+  ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
+  ExpectedStmt
+  VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+  ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
+  ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
+  ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
+
+  // Helper for chaining together multiple imports. If an error is detected,
+  // subsequent imports will return default constructed nodes, so that failure
+  // can be detected with a single conditional branch after a sequence of
+  // imports.
+  template <typename T> T importChecked(Error &Err, const T &From) {
+    // Don't attempt to import nodes if we hit an error earlier.
+    if (Err)
+      return T{};
+    Expected<T> MaybeVal = import(From);
+    if (!MaybeVal) {
+      Err = MaybeVal.takeError();
+      return T{};
     }
+    return *MaybeVal;
+  }
 
-    // Import every item from a container structure into an output container.
-    // If error occurs, stops at first error and returns the error.
-    // The output container should have space for all needed elements (it is not
-    // expanded, new items are put into from the beginning).
-    template<typename InContainerTy, typename OutContainerTy>
-    Error ImportContainerChecked(
-        const InContainerTy &InContainer, OutContainerTy &OutContainer) {
-      return ImportArrayChecked(
-          InContainer.begin(), InContainer.end(), OutContainer.begin());
+  template <typename IIter, typename OIter>
+  Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
+    using ItemT = std::remove_reference_t<decltype(*Obegin)>;
+    for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
+      Expected<ItemT> ToOrErr = import(*Ibegin);
+      if (!ToOrErr)
+        return ToOrErr.takeError();
+      *Obegin = *ToOrErr;
     }
+    return Error::success();
+  }
 
-    template<typename InContainerTy, typename OIter>
-    Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
-      return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
-    }
+  // Import every item from a container structure into an output container.
+  // If error occurs, stops at first error and returns the error.
+  // The output container should have space for all needed elements (it is not
+  // expanded, new items are put into from the beginning).
+  template <typename InContainerTy, typename OutContainerTy>
+  Error ImportContainerChecked(const InContainerTy &InContainer,
+                               OutContainerTy &OutContainer) {
+    return ImportArrayChecked(InContainer.begin(), InContainer.end(),
+                              OutContainer.begin());
+  }
+
+  template <typename InContainerTy, typename OIter>
+  Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
+    return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
+  }
 
-    Error ImportOverriddenMethods(CXXMethodDecl *ToMethod,
-                                  CXXMethodDecl *FromMethod);
+  Error ImportOverriddenMethods(CXXMethodDecl *ToMethod,
+                                CXXMethodDecl *FromMethod);
 
-    Expected<FunctionDecl *> FindFunctionTemplateSpecialization(
-        FunctionDecl *FromFD);
+  Expected<FunctionDecl *>
+  FindFunctionTemplateSpecialization(FunctionDecl *FromFD);
 
-    // Returns true if the given function has a placeholder return type and
-    // that type is declared inside the body of the function.
-    // E.g. auto f() { struct X{}; return X(); }
-    bool hasReturnTypeDeclaredInside(FunctionDecl *D);
-  };
+  // Returns true if the given function has a placeholder return type and
+  // that type is declared inside the body of the function.
+  // E.g. auto f() { struct X{}; return X(); }
+  bool hasReturnTypeDeclaredInside(FunctionDecl *D);
+};
 
 template <typename InContainerTy>
 Error ASTNodeImporter::ImportTemplateArgumentListInfo(
@@ -764,18 +757,17 @@ Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
 
 template <>
 Error ASTNodeImporter::ImportTemplateArgumentListInfo<
-    ASTTemplateArgumentListInfo>(
-        const ASTTemplateArgumentListInfo &From,
-        TemplateArgumentListInfo &Result) {
-  return ImportTemplateArgumentListInfo(
-      From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
+    ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From,
+                                 TemplateArgumentListInfo &Result) {
+  return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc,
+                                        From.arguments(), Result);
 }
 
 Expected<ASTNodeImporter::FunctionTemplateAndArgsTy>
 ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization(
     FunctionDecl *FromFD) {
   assert(FromFD->getTemplatedKind() ==
-      FunctionDecl::TK_FunctionTemplateSpecialization);
+         FunctionDecl::TK_FunctionTemplateSpecialization);
 
   FunctionTemplateAndArgsTy Result;
 
@@ -813,12 +805,8 @@ ASTNodeImporter::import(TemplateParameterList *From) {
     return ToRAngleLocOrErr.takeError();
 
   return TemplateParameterList::Create(
-      Importer.getToContext(),
-      *ToTemplateLocOrErr,
-      *ToLAngleLocOrErr,
-      To,
-      *ToRAngleLocOrErr,
-      *ToRequiresClause);
+      Importer.getToContext(), *ToTemplateLocOrErr, *ToLAngleLocOrErr, To,
+      *ToRAngleLocOrErr, *ToRequiresClause);
 }
 
 template <>
@@ -941,8 +929,7 @@ ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
     auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
     if (!ToTemplateNameLocOrErr)
       return ToTemplateNameLocOrErr.takeError();
-    auto ToTemplateEllipsisLocOrErr =
-        import(FromInfo.getTemplateEllipsisLoc());
+    auto ToTemplateEllipsisLocOrErr = import(FromInfo.getTemplateEllipsisLoc());
     if (!ToTemplateEllipsisLocOrErr)
       return ToTemplateEllipsisLocOrErr.takeError();
     ToInfo = TemplateArgumentLocInfo(
@@ -966,8 +953,7 @@ Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
     else
       return ToDOrErr.takeError();
   }
-  return DeclGroupRef::Create(Importer.getToContext(),
-                              ToDecls.begin(),
+  return DeclGroupRef::Create(Importer.getToContext(), ToDecls.begin(),
                               NumDecls);
 }
 
@@ -998,9 +984,8 @@ ASTNodeImporter::import(const Designator &D) {
     return ToRBracketLocOrErr.takeError();
 
   if (D.isArrayDesignator())
-    return Designator::CreateArrayDesignator(D.getArrayIndex(),
-                                             *ToLBracketLocOrErr,
-                                             *ToRBracketLocOrErr);
+    return Designator::CreateArrayDesignator(
+        D.getArrayIndex(), *ToLBracketLocOrErr, *ToRBracketLocOrErr);
 
   ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
   if (!ToEllipsisLocOrErr)
@@ -1058,9 +1043,8 @@ Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
     if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
       return std::move(Err);
 
-  return LambdaCapture(
-      *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
-      EllipsisLoc);
+  return LambdaCapture(*LocationOrErr, From.isImplicit(), From.getCaptureKind(),
+                       Var, EllipsisLoc);
 }
 
 template <typename T>
@@ -1080,8 +1064,8 @@ bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) {
 }
 
 template <>
-bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found,
-                                               TypedefNameDecl *From) {
+bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(
+    TypedefNameDecl *Found, TypedefNameDecl *From) {
   if (Found->getLinkageInternal() != From->getLinkageInternal())
     return false;
 
@@ -1100,11 +1084,11 @@ using namespace clang;
 
 ExpectedType ASTNodeImporter::VisitType(const Type *T) {
   Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
-    << T->getTypeClassName();
+      << T->getTypeClassName();
   return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
 }
 
-ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
+ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T) {
   ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
   if (!UnderlyingTypeOrErr)
     return UnderlyingTypeOrErr.takeError();
@@ -1114,20 +1098,20 @@ ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
 
 ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
   switch (T->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-  case BuiltinType::Id: \
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)                   \
+  case BuiltinType::Id:                                                        \
     return Importer.getToContext().SingletonId;
 #include "clang/Basic/OpenCLImageTypes.def"
-#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
-  case BuiltinType::Id: \
+#define EXT_OPAQUE_TYPE(ExtType, Id, Ext)                                      \
+  case BuiltinType::Id:                                                        \
     return Importer.getToContext().Id##Ty;
 #include "clang/Basic/OpenCLExtensionTypes.def"
-#define SVE_TYPE(Name, Id, SingletonId) \
-  case BuiltinType::Id: \
+#define SVE_TYPE(Name, Id, SingletonId)                                        \
+  case BuiltinType::Id:                                                        \
     return Importer.getToContext().SingletonId;
 #include "clang/Basic/AArch64SVEACLETypes.def"
-#define PPC_VECTOR_TYPE(Name, Id, Size) \
-  case BuiltinType::Id: \
+#define PPC_VECTOR_TYPE(Name, Id, Size)                                        \
+  case BuiltinType::Id:                                                        \
     return Importer.getToContext().Id##Ty;
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId)                                        \
@@ -1147,15 +1131,16 @@ ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
     return Importer.getToContext().SingletonId;
 #include "clang/Basic/HLSLIntangibleTypes.def"
 #define SHARED_SINGLETON_TYPE(Expansion)
-#define BUILTIN_TYPE(Id, SingletonId) \
-  case BuiltinType::Id: return Importer.getToContext().SingletonId;
+#define BUILTIN_TYPE(Id, SingletonId)                                          \
+  case BuiltinType::Id:                                                        \
+    return Importer.getToContext().SingletonId;
 #include "clang/AST/BuiltinTypes.def"
 
-  // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
-  // context supports C++.
+    // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
+    // context supports C++.
 
-  // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
-  // context supports ObjC.
+    // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
+    // context supports ObjC.
 
   case BuiltinType::Char_U:
     // The context we're importing from has an unsigned 'char'. If we're
@@ -1285,9 +1270,9 @@ ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
   if (!ToElementTypeOrErr)
     return ToElementTypeOrErr.takeError();
 
-  return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
-                                                        T->getSizeModifier(),
-                                                T->getIndexTypeCVRQualifiers());
+  return Importer.getToContext().getIncompleteArrayType(
+      *ToElementTypeOrErr, T->getSizeModifier(),
+      T->getIndexTypeCVRQualifiers());
 }
 
 ExpectedType
@@ -1334,9 +1319,8 @@ ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
   if (!ToElementTypeOrErr)
     return ToElementTypeOrErr.takeError();
 
-  return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
-                                               T->getNumElements(),
-                                               T->getVectorKind());
+  return Importer.getToContext().getVectorType(
+      *ToElementTypeOrErr, T->getNumElements(), T->getVectorKind());
 }
 
 ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
@@ -1404,12 +1388,12 @@ ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
   if (Err)
     return std::move(Err);
 
-  return Importer.getToContext().getFunctionType(
-      *ToReturnTypeOrErr, ArgTypes, ToEPI);
+  return Importer.getToContext().getFunctionType(*ToReturnTypeOrErr, ArgTypes,
+                                                 ToEPI);
 }
 
-ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
-    const UnresolvedUsingType *T) {
+ExpectedType
+ASTNodeImporter::VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
   Error Err = Error::success();
   auto ToD = importChecked(Err, T->getDecl());
   auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
@@ -1492,8 +1476,8 @@ ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
   if (!ToUnderlyingTypeOrErr)
     return ToUnderlyingTypeOrErr.takeError();
 
-  return Importer.getToContext().getDecltypeType(
-      *ToExprOrErr, *ToUnderlyingTypeOrErr);
+  return Importer.getToContext().getDecltypeType(*ToExprOrErr,
+                                                 *ToUnderlyingTypeOrErr);
 }
 
 ExpectedType
@@ -1526,7 +1510,7 @@ ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
     return std::move(Err);
 
   return Importer.getToContext().getAutoType(
-      *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
+      *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/ false,
       /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
       ToTemplateArgs);
 }
@@ -1545,8 +1529,8 @@ ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
       *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
 }
 
-ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
-    const InjectedClassNameType *T) {
+ExpectedType
+ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
   Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
   if (!ToDeclOrErr)
     return ToDeclOrErr.takeError();
@@ -1609,8 +1593,8 @@ ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
       ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
 }
 
-ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
-    const TemplateTypeParmType *T) {
+ExpectedType
+ASTNodeImporter::VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
   Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
   if (!ToDeclOrErr)
     return ToDeclOrErr.takeError();
@@ -1649,7 +1633,7 @@ ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
 }
 
 ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
-                                       const TemplateSpecializationType *T) {
+    const TemplateSpecializationType *T) {
   auto ToTemplateOrErr = import(T->getTemplateName());
   if (!ToTemplateOrErr)
     return ToTemplateOrErr.takeError();
@@ -1681,10 +1665,9 @@ ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
   if (!ToOwnedTagDeclOrErr)
     return ToOwnedTagDeclOrErr.takeError();
 
-  return Importer.getToContext().getElaboratedType(T->getKeyword(),
-                                                   *ToQualifierOrErr,
-                                                   *ToNamedTypeOrErr,
-                                                   *ToOwnedTagDeclOrErr);
+  return Importer.getToContext().getElaboratedType(
+      T->getKeyword(), *ToQualifierOrErr, *ToNamedTypeOrErr,
+      *ToOwnedTagDeclOrErr);
 }
 
 ExpectedType
@@ -1756,12 +1739,10 @@ ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
       Protocols.push_back(*ProtocolOrErr);
     else
       return ProtocolOrErr.takeError();
-
   }
 
-  return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
-                                                   Protocols,
-                                                   T->isKindOfTypeAsWritten());
+  return Importer.getToContext().getObjCObjectType(
+      *ToBaseTypeOrErr, TypeArgs, Protocols, T->isKindOfTypeAsWritten());
 }
 
 ExpectedType
@@ -1917,9 +1898,10 @@ ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
 //----------------------------------------------------------------------------
 // Import Declarations
 //----------------------------------------------------------------------------
-Error ASTNodeImporter::ImportDeclParts(
-    NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
-    DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
+Error ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC,
+                                       DeclContext *&LexicalDC,
+                                       DeclarationName &Name, NamedDecl *&ToD,
+                                       SourceLocation &Loc) {
   // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
   // example: int struct_in_proto(struct data_t{int a;int b;} *d);
   // FIXME: We could support these constructs by importing a different type of
@@ -2019,9 +2001,8 @@ Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) {
   return Error::success();
 }
 
-Error
-ASTNodeImporter::ImportDeclarationNameLoc(
-    const DeclarationNameInfo &From, DeclarationNameInfo& To) {
+Error ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From,
+                                                DeclarationNameInfo &To) {
   // NOTE: To.Name and To.Loc are already imported.
   // We only have to import To.LocInfo.
   switch (To.getName().getNameKind()) {
@@ -2060,8 +2041,8 @@ ASTNodeImporter::ImportDeclarationNameLoc(
   llvm_unreachable("Unknown name kind.");
 }
 
-Error
-ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
+Error ASTNodeImporter::ImportDeclContext(DeclContext *FromDC,
+                                         bool ForceImport) {
   if (Importer.isMinimalImport() && !ForceImport) {
     auto ToDCOrErr = Importer.ImportContext(FromDC);
     return ToDCOrErr.takeError();
@@ -2207,16 +2188,16 @@ Error ASTNodeImporter::ImportFieldDeclDefinition(const FieldDecl *From,
   return Error::success();
 }
 
-Error ASTNodeImporter::ImportDeclContext(
-    Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
+Error ASTNodeImporter::ImportDeclContext(Decl *FromD, DeclContext *&ToDC,
+                                         DeclContext *&ToLexicalDC) {
   auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
   if (!ToDCOrErr)
     return ToDCOrErr.takeError();
   ToDC = *ToDCOrErr;
 
   if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
-    auto ToLexicalDCOrErr = Importer.ImportContext(
-        FromD->getLexicalDeclContext());
+    auto ToLexicalDCOrErr =
+        Importer.ImportContext(FromD->getLexicalDeclContext());
     if (!ToLexicalDCOrErr)
       return ToLexicalDCOrErr.takeError();
     ToLexicalDC = *ToLexicalDCOrErr;
@@ -2226,10 +2207,10 @@ Error ASTNodeImporter::ImportDeclContext(
   return Error::success();
 }
 
-Error ASTNodeImporter::ImportImplicitMethods(
-    const CXXRecordDecl *From, CXXRecordDecl *To) {
+Error ASTNodeImporter::ImportImplicitMethods(const CXXRecordDecl *From,
+                                             CXXRecordDecl *To) {
   assert(From->isCompleteDefinition() && To->getDefinition() == To &&
-      "Import implicit methods to or from non-definition");
+         "Import implicit methods to or from non-definition");
 
   for (CXXMethodDecl *FromM : From->methods())
     if (FromM->isImplicit()) {
@@ -2252,8 +2233,8 @@ static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To,
   return Error::success();
 }
 
-Error ASTNodeImporter::ImportDefinition(
-    RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
+Error ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To,
+                                        ImportDefinitionKind Kind) {
   auto DefinitionCompleter = [To]() {
     // There are cases in LLDB when we first import a class without its
     // members. The class will have DefinitionData, but no members. Then,
@@ -2322,9 +2303,8 @@ Error ASTNodeImporter::ImportDefinition(
     struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
     struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
 
-    #define FIELD(Name, Width, Merge) \
-    ToData.Name = FromData.Name;
-    #include "clang/AST/CXXRecordDeclDefinitionBits.def"
+#define FIELD(Name, Width, Merge) ToData.Name = FromData.Name;
+#include "clang/AST/CXXRecordDeclDefinitionBits.def"
 
     // Copy over the data stored in RecordDeclBits
     ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
@@ -2345,7 +2325,7 @@ Error ASTNodeImporter::ImportDefinition(
 
       // Ensure that we have a definition for the base.
       if (Error Err =
-          ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
+              ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
         return Err;
 
       auto RangeOrErr = import(Base1.getSourceRange());
@@ -2356,14 +2336,9 @@ Error ASTNodeImporter::ImportDefinition(
       if (!TSIOrErr)
         return TSIOrErr.takeError();
 
-      Bases.push_back(
-          new (Importer.getToContext()) CXXBaseSpecifier(
-              *RangeOrErr,
-              Base1.isVirtual(),
-              Base1.isBaseOfClass(),
-              Base1.getAccessSpecifierAsWritten(),
-              *TSIOrErr,
-              EllipsisLoc));
+      Bases.push_back(new (Importer.getToContext()) CXXBaseSpecifier(
+          *RangeOrErr, Base1.isVirtual(), Base1.isBaseOfClass(),
+          Base1.getAccessSpecifierAsWritten(), *TSIOrErr, EllipsisLoc));
     }
     if (!Bases.empty())
       ToCXX->setBases(Bases.data(), Bases.size());
@@ -2401,8 +2376,8 @@ Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) {
   return Error::success();
 }
 
-Error ASTNodeImporter::ImportDefinition(
-    EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
+Error ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To,
+                                        ImportDefinitionKind Kind) {
   if (To->getDefinition() || To->isBeingDefined()) {
     if (Kind == IDK_Everything)
       return ImportDeclContext(From, /*ForceImport=*/true);
@@ -2492,7 +2467,7 @@ bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
 
 ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) {
   Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
-    << D->getDeclKindName();
+      << D->getDeclKindName();
   return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
 }
 
@@ -2523,8 +2498,7 @@ ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) {
 }
 
 ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
-  TranslationUnitDecl *ToD =
-    Importer.getToContext().getTranslationUnitDecl();
+  TranslationUnitDecl *ToD = Importer.getToContext().getTranslationUnitDecl();
 
   Importer.MapImported(D, ToD);
 
@@ -2603,9 +2577,9 @@ ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) {
     return std::move(Err);
 
   StaticAssertDecl *ToD;
-  if (GetImportedOrCreateDecl(
-      ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
-      ToRParenLoc, D->isFailed()))
+  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
+                              ToAssertExpr, ToMessage, ToRParenLoc,
+                              D->isFailed()))
     return ToD;
 
   ToD->setLexicalDeclContext(LexicalDC);
@@ -2722,9 +2696,9 @@ ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
   IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
 
   NamespaceAliasDecl *ToD;
-  if (GetImportedOrCreateDecl(
-      ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
-      ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
+  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC,
+                              ToNamespaceLoc, ToAliasLoc, ToIdentifier,
+                              ToQualifierLoc, ToTargetNameLoc, ToNamespace))
     return ToD;
 
   ToD->setLexicalDeclContext(LexicalDC);
@@ -2733,8 +2707,8 @@ ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
   return ToD;
 }
 
-ExpectedDecl
-ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) {
+ExpectedDecl ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D,
+                                                   bool IsAlias) {
   // Import the major distinguishing characteristics of this typedef.
   DeclarationName Name;
   SourceLocation Loc;
@@ -2823,12 +2797,12 @@ ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) {
   TypedefNameDecl *ToTypedef;
   if (IsAlias) {
     if (GetImportedOrCreateDecl<TypeAliasDecl>(
-        ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
-        Name.getAsIdentifierInfo(), ToTypeSourceInfo))
+            ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
+            Name.getAsIdentifierInfo(), ToTypeSourceInfo))
       return ToTypedef;
   } else if (GetImportedOrCreateDecl<TypedefDecl>(
-      ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
-      Name.getAsIdentifierInfo(), ToTypeSourceInfo))
+                 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
+                 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
     return ToTypedef;
 
   // Import the DeclContext and set it to the Typedef.
@@ -2943,7 +2917,6 @@ ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) {
     if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
                                 Name.getAsIdentifierInfo()))
       return ToLabel;
-
   }
 
   Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
@@ -2971,8 +2944,8 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
   unsigned IDNS = Decl::IDNS_Tag;
   DeclarationName SearchName = Name;
   if (!SearchName && D->getTypedefNameForAnonDecl()) {
-    if (Error Err = importInto(
-        SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
+    if (Error Err = importInto(SearchName,
+                               D->getTypedefNameForAnonDecl()->getDeclName()))
       return std::move(Err);
     IDNS = Decl::IDNS_Ordinary;
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
@@ -2982,8 +2955,7 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
   EnumDecl *PrevDecl = nullptr;
   if (!DC->isFunctionOrMethod()) {
     SmallVector<NamedDecl *, 4> ConflictingDecls;
-    auto FoundDecls =
-        Importer.findDeclsInToCtx(DC, SearchName);
+    auto FoundDecls = Importer.findDeclsInToCtx(DC, SearchName);
     for (auto *FoundDecl : FoundDecls) {
       if (!FoundDecl->isInIdentifierNamespace(IDNS))
         continue;
@@ -3033,10 +3005,10 @@ ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) {
 
   // Create the enum declaration.
   EnumDecl *D2;
-  if (GetImportedOrCreateDecl(
-          D2, D, Importer.getToContext(), DC, ToBeginLoc,
-          Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
-          D->isScopedUsingClassTag(), D->isFixed()))
+  if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, ToBeginLoc,
+                              Loc, Name.getAsIdentifierInfo(), PrevDecl,
+                              D->isScoped(), D->isScopedUsingClassTag(),
+                              D->isFixed()))
     return D2;
 
   D2->setQualifierInfo(ToQualifierLoc);
@@ -3090,8 +3062,8 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
   unsigned IDNS = Decl::IDNS_Tag;
   DeclarationName SearchName = Name;
   if (!SearchName && D->getTypedefNameForAnonDecl()) {
-    if (Error Err = importInto(
-        SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
+    if (Error Err = importInto(SearchName,
+                               D->getTypedefNameForAnonDecl()->getDeclName()))
       return std::move(Err);
     IDNS = Decl::IDNS_Ordinary;
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
@@ -3105,8 +3077,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
   RecordDecl *PrevDecl = nullptr;
   if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
     SmallVector<NamedDecl *, 4> ConflictingDecls;
-    auto FoundDecls =
-        Importer.findDeclsInToCtx(DC, SearchName);
+    auto FoundDecls = Importer.findDeclsInToCtx(DC, SearchName);
     if (!FoundDecls.empty()) {
       // We're going to have to compare D against potentially conflicting Decls,
       // so complete it.
@@ -3200,7 +3171,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
         return CDeclOrErr.takeError();
       Numbering.ContextDecl = *CDeclOrErr;
       D2CXX->setLambdaNumbering(Numbering);
-   } else if (DCXX->isInjectedClassName()) {
+    } else if (DCXX->isInjectedClassName()) {
       // We have to be careful to do a similar dance to the one in
       // Sema::ActOnStartCXXMemberDeclarations
       const bool DelayTypeCreation = true;
@@ -3209,8 +3180,8 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
               *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
               cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
         return D2CXX;
-      Importer.getToContext().getTypeDeclType(
-          D2CXX, dyn_cast<CXXRecordDecl>(DC));
+      Importer.getToContext().getTypeDeclType(D2CXX,
+                                              dyn_cast<CXXRecordDecl>(DC));
     } else {
       if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
                                   D->getTagKind(), DC, *BeginLocOrErr, Loc,
@@ -3224,8 +3195,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
     D2->setLexicalDeclContext(LexicalDC);
     addDeclToContexts(D, D2);
 
-    if (ClassTemplateDecl *FromDescribed =
-        DCXX->getDescribedClassTemplate()) {
+    if (ClassTemplateDecl *FromDescribed = DCXX->getDescribedClassTemplate()) {
       ClassTemplateDecl *ToDescribed;
       if (Error Err = importInto(ToDescribed, FromDescribed))
         return std::move(Err);
@@ -3248,8 +3218,7 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
         // if yes this should be reused. We must ensure that only one type
         // object exists for the injected type (including the injected record
         // declaration), ASTContext does not check it.
-        SmallVector<Decl *, 2> Redecls =
-            getCanonicalForwardRedeclChain(D2CXX);
+        SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D2CXX);
         const Type *FrontTy =
             cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
         QualType InjSpec;
@@ -3277,26 +3246,25 @@ ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) {
       }
     } else if (MemberSpecializationInfo *MemberInfo =
                    DCXX->getMemberSpecializationInfo()) {
-        TemplateSpecializationKind SK =
-            MemberInfo->getTemplateSpecializationKind();
-        CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass();
+      TemplateSpecializationKind SK =
+          MemberInfo->getTemplateSpecializationKind();
+      CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass();
 
-        if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
-          D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
-        else
-          return ToInstOrErr.takeError();
+      if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
+        D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
+      else
+        return ToInstOrErr.takeError();
 
-        if (ExpectedSLoc POIOrErr =
-            import(MemberInfo->getPointOfInstantiation()))
-          D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation(
+      if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+        D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation(
             *POIOrErr);
-        else
-          return POIOrErr.takeError();
+      else
+        return POIOrErr.takeError();
     }
 
   } else {
-    if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
-                                D->getTagKind(), DC, *BeginLocOrErr, Loc,
+    if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
+                                DC, *BeginLocOrErr, Loc,
                                 Name.getAsIdentifierInfo(), PrevDecl))
       return D2;
     D2->setLexicalDeclContext(LexicalDC);
@@ -3397,8 +3365,8 @@ Error ASTNodeImporter::ImportTemplateParameterLists(const DeclTy *FromD,
   return Error::success();
 }
 
-Error ASTNodeImporter::ImportTemplateInformation(
-    FunctionDecl *FromFD, FunctionDecl *ToFD) {
+Error ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD,
+                                                 FunctionDecl *ToFD) {
   switch (FromFD->getTemplatedKind()) {
   case FunctionDecl::TK_NonTemplate:
   case FunctionDecl::TK_FunctionTemplate:
@@ -3413,13 +3381,13 @@ Error ASTNodeImporter::ImportTemplateInformation(
     TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind();
 
     if (Expected<FunctionDecl *> InstFDOrErr =
-        import(FromFD->getInstantiatedFromMemberFunction()))
+            import(FromFD->getInstantiatedFromMemberFunction()))
       ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
     else
       return InstFDOrErr.takeError();
 
     if (ExpectedSLoc POIOrErr = import(
-        FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()))
+            FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()))
       ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
     else
       return POIOrErr.takeError();
@@ -3434,14 +3402,14 @@ Error ASTNodeImporter::ImportTemplateInformation(
       return FunctionAndArgsOrErr.takeError();
 
     TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy(
-          Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
+        Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
 
     auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
     TemplateArgumentListInfo ToTAInfo;
     const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
     if (FromTAArgsAsWritten)
-      if (Error Err = ImportTemplateArgumentListInfo(
-          *FromTAArgsAsWritten, ToTAInfo))
+      if (Error Err =
+              ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
         return Err;
 
     ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
@@ -4010,8 +3978,8 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
 
   // Connect the redecl chain.
   if (FoundByLookup) {
-    auto *Recent = const_cast<FunctionDecl *>(
-          FoundByLookup->getMostRecentDecl());
+    auto *Recent =
+        const_cast<FunctionDecl *>(FoundByLookup->getMostRecentDecl());
     ToFunction->setPreviousDecl(Recent);
     // FIXME Probably we should merge exception specifications.  E.g. In the
     // "To" context the existing function may have exception specification with
@@ -4063,7 +4031,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
   // params it refers to.
   if (TInfo) {
     if (auto ProtoLoc =
-        TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
+            TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
       for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
         ProtoLoc.setParam(I, Parameters[I]);
     }
@@ -4081,8 +4049,8 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
     if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
       SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
       // Import first, then allocate memory and copy if there was no error.
-      if (Error Err = ImportContainerChecked(
-          FromConstructor->inits(), CtorInitializers))
+      if (Error Err = ImportContainerChecked(FromConstructor->inits(),
+                                             CtorInitializers))
         return std::move(Err);
       auto **Memory =
           new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
@@ -4172,9 +4140,8 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
   for (auto *FoundDecl : FoundDecls) {
     if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
       // For anonymous fields, match up by index.
-      if (!Name &&
-          ASTImporter::getFieldIndex(D) !=
-          ASTImporter::getFieldIndex(FoundField))
+      if (!Name && ASTImporter::getFieldIndex(D) !=
+                       ASTImporter::getFieldIndex(FoundField))
         continue;
 
       if (Importer.IsStructurallyEquivalent(D->getType(),
@@ -4196,7 +4163,7 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
             if (!FoundField->getInClassInitializer())
               FoundField->setInClassInitializer(*ToInitializerOrErr);
           } else {
-              return ToInitializerOrErr.takeError();
+            return ToInitializerOrErr.takeError();
           }
         }
         return FoundField;
@@ -4204,9 +4171,9 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
 
       // FIXME: Why is this case not handled with calling HandleNameConflict?
       Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
-        << Name << D->getType() << FoundField->getType();
+          << Name << D->getType() << FoundField->getType();
       Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
-        << FoundField->getType();
+          << FoundField->getType();
 
       return make_error<ASTImportError>(ASTImportError::NameConflict);
     }
@@ -4270,27 +4237,25 @@ ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
   for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
     if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
       // For anonymous indirect fields, match up by index.
-      if (!Name &&
-          ASTImporter::getFieldIndex(D) !=
-          ASTImporter::getFieldIndex(FoundField))
+      if (!Name && ASTImporter::getFieldIndex(D) !=
+                       ASTImporter::getFieldIndex(FoundField))
         continue;
 
-      if (Importer.IsStructurallyEquivalent(D->getType(),
-                                            FoundField->getType(),
+      if (Importer.IsStructurallyEquivalent(D->getType(), FoundField->getType(),
                                             !Name.isEmpty())) {
         Importer.MapImported(D, FoundField);
         return FoundField;
       }
 
       // If there are more anonymous fields to check, continue.
-      if (!Name && I < N-1)
+      if (!Name && I < N - 1)
         continue;
 
       // FIXME: Why is this case not handled with calling HandleNameConflict?
       Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
-        << Name << D->getType() << FoundField->getType();
+          << Name << D->getType() << FoundField->getType();
       Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
-        << FoundField->getType();
+          << FoundField->getType();
 
       return make_error<ASTImportError>(ASTImportError::NameConflict);
     }
@@ -4302,7 +4267,7 @@ ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
     return TypeOrErr.takeError();
 
   auto **NamedChain =
-    new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
+      new (Importer.getToContext()) NamedDecl *[D->getChainingSize()];
 
   unsigned i = 0;
   for (auto *PI : D->chain())
@@ -4467,9 +4432,9 @@ ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
       }
 
       Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
-        << Name << D->getType() << FoundIvar->getType();
+          << Name << D->getType() << FoundIvar->getType();
       Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
-        << FoundIvar->getType();
+          << FoundIvar->getType();
 
       return make_error<ASTImportError>(ASTImportError::NameConflict);
     }
@@ -4484,11 +4449,11 @@ ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
     return std::move(Err);
 
   ObjCIvarDecl *ToIvar;
-  if (GetImportedOrCreateDecl(
-          ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
-          ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
-          ToType, ToTypeSourceInfo,
-          D->getAccessControl(),ToBitWidth, D->getSynthesize()))
+  if (GetImportedOrCreateDecl(ToIvar, D, Importer.getToContext(),
+                              cast<ObjCContainerDecl>(DC), ToInnerLocStart, Loc,
+                              Name.getAsIdentifierInfo(), ToType,
+                              ToTypeSourceInfo, D->getAccessControl(),
+                              ToBitWidth, D->getSynthesize()))
     return ToIvar;
 
   ToIvar->setLexicalDeclContext(LexicalDC);
@@ -4498,7 +4463,7 @@ ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
 
 ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
 
-  SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D);
+  SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D);
   auto RedeclIt = Redecls.begin();
   // Import the first part of the decl chain. I.e. import all previous
   // declarations starting from the canonical decl.
@@ -4549,16 +4514,16 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
           const VarDecl *FoundDInit = nullptr;
           if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
             // FIXME Diagnose ODR error if the two initializers are different?
-            return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
+            return Importer.MapImported(D, const_cast<VarDecl *>(FoundDInit));
 
           FoundByLookup = FoundVar;
           break;
         }
 
-        const ArrayType *FoundArray
-          = Importer.getToContext().getAsArrayType(FoundVar->getType());
-        const ArrayType *TArray
-          = Importer.getToContext().getAsArrayType(D->getType());
+        const ArrayType *FoundArray =
+            Importer.getToContext().getAsArrayType(FoundVar->getType());
+        const ArrayType *TArray =
+            Importer.getToContext().getAsArrayType(D->getType());
         if (FoundArray && TArray) {
           if (isa<IncompleteArrayType>(FoundArray) &&
               isa<ConstantArrayType>(TArray)) {
@@ -4578,9 +4543,9 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
         }
 
         Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
-          << Name << D->getType() << FoundVar->getType();
+            << Name << D->getType() << FoundVar->getType();
         Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
-          << FoundVar->getType();
+            << FoundVar->getType();
         ConflictingDecls.push_back(FoundDecl);
       }
     }
@@ -4793,12 +4758,13 @@ ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
       // Check return types.
       if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
                                              FoundMethod->getReturnType())) {
-        Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
+        Importer.ToDiag(Loc,
+                        diag::warn_odr_objc_method_result_type_inconsistent)
             << D->isInstanceMethod() << Name << D->getReturnType()
             << FoundMethod->getReturnType();
         Importer.ToDiag(FoundMethod->getLocation(),
                         diag::note_odr_objc_method_here)
-          << D->isInstanceMethod() << Name;
+            << D->isInstanceMethod() << Name;
 
         return make_error<ASTImportError>(ASTImportError::NameConflict);
       }
@@ -4806,27 +4772,28 @@ ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
       // Check the number of parameters.
       if (D->param_size() != FoundMethod->param_size()) {
         Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
-          << D->isInstanceMethod() << Name
-          << D->param_size() << FoundMethod->param_size();
+            << D->isInstanceMethod() << Name << D->param_size()
+            << FoundMethod->param_size();
         Importer.ToDiag(FoundMethod->getLocation(),
                         diag::note_odr_objc_method_here)
-          << D->isInstanceMethod() << Name;
+            << D->isInstanceMethod() << Name;
 
         return make_error<ASTImportError>(ASTImportError::NameConflict);
       }
 
       // Check parameter types.
       for (ObjCMethodDecl::param_iterator P = D->param_begin(),
-             PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
+                                          PEnd = D->param_end(),
+                                          FoundP = FoundMethod->param_begin();
            P != PEnd; ++P, ++FoundP) {
         if (!Importer.IsStructurallyEquivalent((*P)->getType(),
                                                (*FoundP)->getType())) {
           Importer.FromDiag((*P)->getLocation(),
                             diag::warn_odr_objc_method_param_type_inconsistent)
-            << D->isInstanceMethod() << Name
-            << (*P)->getType() << (*FoundP)->getType();
+              << D->isInstanceMethod() << Name << (*P)->getType()
+              << (*FoundP)->getType();
           Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
-            << (*FoundP)->getType();
+              << (*FoundP)->getType();
 
           return make_error<ASTImportError>(ASTImportError::NameConflict);
         }
@@ -4836,10 +4803,10 @@ ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
       // Check the number of parameters.
       if (D->isVariadic() != FoundMethod->isVariadic()) {
         Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
-          << D->isInstanceMethod() << Name;
+            << D->isInstanceMethod() << Name;
         Importer.ToDiag(FoundMethod->getLocation(),
                         diag::note_odr_objc_method_here)
-          << D->isInstanceMethod() << Name;
+            << D->isInstanceMethod() << Name;
 
         return make_error<ASTImportError>(ASTImportError::NameConflict);
       }
@@ -4925,11 +4892,10 @@ ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
     return std::move(Err);
 
   ObjCTypeParamDecl *Result;
-  if (GetImportedOrCreateDecl(
-          Result, D, Importer.getToContext(), DC, D->getVariance(),
-          ToVarianceLoc, D->getIndex(),
-          ToLocation, Name.getAsIdentifierInfo(),
-          ToColonLoc, ToTypeSourceInfo))
+  if (GetImportedOrCreateDecl(Result, D, Importer.getToContext(), DC,
+                              D->getVariance(), ToVarianceLoc, D->getIndex(),
+                              ToLocation, Name.getAsIdentifierInfo(),
+                              ToColonLoc, ToTypeSourceInfo))
     return Result;
 
   // Only import 'ObjCTypeParamType' after the decl is created.
@@ -4957,8 +4923,8 @@ ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
     return std::move(Err);
 
   // Determine if we've already encountered this category.
-  ObjCCategoryDecl *MergeWithCategory
-    = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
+  ObjCCategoryDecl *MergeWithCategory =
+      ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
   ObjCCategoryDecl *ToCategory = MergeWithCategory;
   if (!ToCategory) {
 
@@ -4970,13 +4936,10 @@ ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
     if (Err)
       return std::move(Err);
 
-    if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
-                                ToAtStartLoc, Loc,
-                                ToCategoryNameLoc,
-                                Name.getAsIdentifierInfo(), ToInterface,
-                                /*TypeParamList=*/nullptr,
-                                ToIvarLBraceLoc,
-                                ToIvarRBraceLoc))
+    if (GetImportedOrCreateDecl(
+            ToCategory, D, Importer.getToContext(), DC, ToAtStartLoc, Loc,
+            ToCategoryNameLoc, Name.getAsIdentifierInfo(), ToInterface,
+            /*TypeParamList=*/nullptr, ToIvarLBraceLoc, ToIvarRBraceLoc))
       return ToCategory;
 
     ToCategory->setLexicalDeclContext(LexicalDC);
@@ -4991,12 +4954,11 @@ ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
     // Import protocols
     SmallVector<ObjCProtocolDecl *, 4> Protocols;
     SmallVector<SourceLocation, 4> ProtocolLocs;
-    ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc
-      = D->protocol_loc_begin();
+    ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc =
+        D->protocol_loc_begin();
     for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
-                                          FromProtoEnd = D->protocol_end();
-         FromProto != FromProtoEnd;
-         ++FromProto, ++FromProtoLoc) {
+                                             FromProtoEnd = D->protocol_end();
+         FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) {
       if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
         Protocols.push_back(*ToProtoOrErr);
       else
@@ -5023,7 +4985,7 @@ ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
   // If we have an implementation, import it as well.
   if (D->getImplementation()) {
     if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
-        import(D->getImplementation()))
+            import(D->getImplementation()))
       ToCategory->setImplementation(*ToImplOrErr);
     else
       return ToImplOrErr.takeError();
@@ -5032,8 +4994,9 @@ ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
   return ToCategory;
 }
 
-Error ASTNodeImporter::ImportDefinition(
-    ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) {
+Error ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From,
+                                        ObjCProtocolDecl *To,
+                                        ImportDefinitionKind Kind) {
   if (To->getDefinition()) {
     if (shouldForceImportDeclContext(Kind))
       if (Error Err = ImportDeclContext(From))
@@ -5050,9 +5013,8 @@ Error ASTNodeImporter::ImportDefinition(
   ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc =
       From->protocol_loc_begin();
   for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
-                                        FromProtoEnd = From->protocol_end();
-       FromProto != FromProtoEnd;
-       ++FromProto, ++FromProtoLoc) {
+                                           FromProtoEnd = From->protocol_end();
+       FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) {
     if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
       Protocols.push_back(*ToProtoOrErr);
     else
@@ -5062,12 +5024,11 @@ Error ASTNodeImporter::ImportDefinition(
       ProtocolLocs.push_back(*ToProtoLocOrErr);
     else
       return ToProtoLocOrErr.takeError();
-
   }
 
   // FIXME: If we're merging, make sure that the protocol list is the same.
-  To->setProtocolList(Protocols.data(), Protocols.size(),
-                      ProtocolLocs.data(), Importer.getToContext());
+  To->setProtocolList(Protocols.data(), Protocols.size(), ProtocolLocs.data(),
+                      Importer.getToContext());
 
   if (shouldForceImportDeclContext(Kind)) {
     // Import all of the members of this protocol.
@@ -5150,8 +5111,8 @@ ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
 
   LinkageSpecDecl *ToLinkageSpec;
   if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
-                              *ExternLocOrErr, *LangLocOrErr,
-                              D->getLanguage(), HasBraces))
+                              *ExternLocOrErr, *LangLocOrErr, D->getLanguage(),
+                              HasBraces))
     return ToLinkageSpec;
 
   if (HasBraces) {
@@ -5211,10 +5172,10 @@ ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) {
   LexicalDC->addDeclInternal(ToUsing);
 
   if (NamedDecl *FromPattern =
-      Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
+          Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
     if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
-      Importer.getToContext().setInstantiatedFromUsingDecl(
-          ToUsing, *ToPatternOrErr);
+      Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing,
+                                                           *ToPatternOrErr);
     else
       return ToPatternOrErr.takeError();
   }
@@ -5307,7 +5268,7 @@ ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) {
   ToShadow->setAccess(D->getAccess());
 
   if (UsingShadowDecl *FromPattern =
-      Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
+          Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
     if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
       Importer.getToContext().setInstantiatedFromUsingShadowDecl(
           ToShadow, *ToPatternOrErr);
@@ -5348,10 +5309,8 @@ ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
 
   UsingDirectiveDecl *ToUsingDir;
   if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
-                              ToUsingLoc,
-                              ToNamespaceKeyLocation,
-                              ToQualifierLoc,
-                              ToIdentLocation,
+                              ToUsingLoc, ToNamespaceKeyLocation,
+                              ToQualifierLoc, ToIdentLocation,
                               ToNominatedNamespace, *ToComAncestorOrErr))
     return ToUsingDir;
 
@@ -5390,8 +5349,8 @@ ExpectedDecl ASTNodeImporter::VisitUsingPackDecl(UsingPackDecl *D) {
   return ToUsingPack;
 }
 
-ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl(
-    UnresolvedUsingValueDecl *D) {
+ExpectedDecl
+ASTNodeImporter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
   DeclContext *DC, *LexicalDC;
   DeclarationName Name;
   SourceLocation Loc;
@@ -5447,8 +5406,8 @@ ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl(
 
   UnresolvedUsingTypenameDecl *ToUsing;
   if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
-                              ToUsingLoc, ToTypenameLoc,
-                              ToQualifierLoc, Loc, Name, ToEllipsisLoc))
+                              ToUsingLoc, ToTypenameLoc, ToQualifierLoc, Loc,
+                              Name, ToEllipsisLoc))
     return ToUsing;
 
   ToUsing->setAccess(D->getAccess());
@@ -5459,7 +5418,7 @@ ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl(
 }
 
 ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
-  Decl* ToD = nullptr;
+  Decl *ToD = nullptr;
   switch (D->getBuiltinTemplateKind()) {
 #define BuiltinTemplate(BTName)                                                \
   case BuiltinTemplateKind::BTK##BTName:                                       \
@@ -5472,8 +5431,9 @@ ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
   return ToD;
 }
 
-Error ASTNodeImporter::ImportDefinition(
-    ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) {
+Error ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From,
+                                        ObjCInterfaceDecl *To,
+                                        ImportDefinitionKind Kind) {
   if (To->getDefinition()) {
     // Check consistency of superclass.
     ObjCInterfaceDecl *FromSuper = From->getSuperClass();
@@ -5489,17 +5449,17 @@ Error ASTNodeImporter::ImportDefinition(
         (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
       Importer.ToDiag(To->getLocation(),
                       diag::warn_odr_objc_superclass_inconsistent)
-        << To->getDeclName();
+          << To->getDeclName();
       if (ToSuper)
         Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
-          << To->getSuperClass()->getDeclName();
+            << To->getSuperClass()->getDeclName();
       else
         Importer.ToDiag(To->getLocation(),
                         diag::note_odr_objc_missing_superclass);
       if (From->getSuperClass())
         Importer.FromDiag(From->getSuperClassLoc(),
                           diag::note_odr_objc_superclass)
-        << From->getSuperClass()->getDeclName();
+            << From->getSuperClass()->getDeclName();
       else
         Importer.FromDiag(From->getLocation(),
                           diag::note_odr_objc_missing_superclass);
@@ -5529,9 +5489,8 @@ Error ASTNodeImporter::ImportDefinition(
       From->protocol_loc_begin();
 
   for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(),
-                                         FromProtoEnd = From->protocol_end();
-       FromProto != FromProtoEnd;
-       ++FromProto, ++FromProtoLoc) {
+                                            FromProtoEnd = From->protocol_end();
+       FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) {
     if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
       Protocols.push_back(*ToProtoOrErr);
     else
@@ -5541,12 +5500,11 @@ Error ASTNodeImporter::ImportDefinition(
       ProtocolLocs.push_back(*ToProtoLocOrErr);
     else
       return ToProtoLocOrErr.takeError();
-
   }
 
   // FIXME: If we're merging, make sure that the protocol list is the same.
-  To->setProtocolList(Protocols.data(), Protocols.size(),
-                      ProtocolLocs.data(), Importer.getToContext());
+  To->setProtocolList(Protocols.data(), Protocols.size(), ProtocolLocs.data(),
+                      Importer.getToContext());
 
   // Import categories. When the categories themselves are imported, they'll
   // hook themselves into this interface.
@@ -5559,7 +5517,7 @@ Error ASTNodeImporter::ImportDefinition(
   // If we have an @implementation, import it as well.
   if (From->getImplementation()) {
     if (Expected<ObjCImplementationDecl *> ToImplOrErr =
-        import(From->getImplementation()))
+            import(From->getImplementation()))
       To->setImplementation(*ToImplOrErr);
     else
       return ToImplOrErr.takeError();
@@ -5593,10 +5551,8 @@ ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) {
   if (!RAngleLocOrErr)
     return RAngleLocOrErr.takeError();
 
-  return ObjCTypeParamList::create(Importer.getToContext(),
-                                   *LAngleLocOrErr,
-                                   toTypeParams,
-                                   *RAngleLocOrErr);
+  return ObjCTypeParamList::create(Importer.getToContext(), *LAngleLocOrErr,
+                                   toTypeParams, *RAngleLocOrErr);
 }
 
 ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
@@ -5639,11 +5595,11 @@ ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
     if (!AtBeginLocOrErr)
       return AtBeginLocOrErr.takeError();
 
-    if (GetImportedOrCreateDecl(
-            ToIface, D, Importer.getToContext(), DC,
-            *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
-            /*TypeParamList=*/nullptr,
-            /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
+    if (GetImportedOrCreateDecl(ToIface, D, Importer.getToContext(), DC,
+                                *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
+                                /*TypeParamList=*/nullptr,
+                                /*PrevDecl=*/nullptr, Loc,
+                                D->isImplicitInterfaceDecl()))
       return ToIface;
     ToIface->setLexicalDeclContext(LexicalDC);
     LexicalDC->addDeclInternal(ToIface);
@@ -5652,7 +5608,7 @@ ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
   // Import the type parameter list after MapImported, to avoid
   // loops when bringing in their DeclContext.
   if (auto ToPListOrErr =
-      ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
+          ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
     ToIface->setTypeParamList(*ToPListOrErr);
   else
     return ToPListOrErr.takeError();
@@ -5683,10 +5639,10 @@ ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
     if (Err)
       return std::move(Err);
 
-    if (GetImportedOrCreateDecl(
-            ToImpl, D, Importer.getToContext(), DC,
-            Importer.Import(D->getIdentifier()), Category->getClassInterface(),
-            ToLocation, ToAtStartLoc, ToCategoryNameLoc))
+    if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
+                                Importer.Import(D->getIdentifier()),
+                                Category->getClassInterface(), ToLocation,
+                                ToAtStartLoc, ToCategoryNameLoc))
       return ToImpl;
 
     ToImpl->setLexicalDeclContext(LexicalDC);
@@ -5730,13 +5686,9 @@ ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
     if (Err)
       return std::move(Err);
 
-    if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
-                                DC, Iface, Super,
-                                ToLocation,
-                                ToAtStartLoc,
-                                ToSuperClassLoc,
-                                ToIvarLBraceLoc,
-                                ToIvarRBraceLoc))
+    if (GetImportedOrCreateDecl(
+            Impl, D, Importer.getToContext(), DC, Iface, Super, ToLocation,
+            ToAtStartLoc, ToSuperClassLoc, ToIvarLBraceLoc, ToIvarRBraceLoc))
       return Impl;
 
     Impl->setLexicalDeclContext(LexicalDC);
@@ -5755,20 +5707,18 @@ ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
                              Impl->getSuperClass()))) {
       Importer.ToDiag(Impl->getLocation(),
                       diag::warn_odr_objc_superclass_inconsistent)
-        << Iface->getDeclName();
+          << Iface->getDeclName();
       // FIXME: It would be nice to have the location of the superclass
       // below.
       if (Impl->getSuperClass())
-        Importer.ToDiag(Impl->getLocation(),
-                        diag::note_odr_objc_superclass)
-        << Impl->getSuperClass()->getDeclName();
+        Importer.ToDiag(Impl->getLocation(), diag::note_odr_objc_superclass)
+            << Impl->getSuperClass()->getDeclName();
       else
         Importer.ToDiag(Impl->getLocation(),
                         diag::note_odr_objc_missing_superclass);
       if (D->getSuperClass())
-        Importer.FromDiag(D->getLocation(),
-                          diag::note_odr_objc_superclass)
-        << D->getSuperClass()->getDeclName();
+        Importer.FromDiag(D->getLocation(), diag::note_odr_objc_superclass)
+            << D->getSuperClass()->getDeclName();
       else
         Importer.FromDiag(D->getLocation(),
                           diag::note_odr_objc_missing_superclass);
@@ -5808,9 +5758,9 @@ ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
       if (!Importer.IsStructurallyEquivalent(D->getType(),
                                              FoundProp->getType())) {
         Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
-          << Name << D->getType() << FoundProp->getType();
+            << Name << D->getType() << FoundProp->getType();
         Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
-          << FoundProp->getType();
+            << FoundProp->getType();
 
         return make_error<ASTImportError>(ASTImportError::NameConflict);
       }
@@ -5833,11 +5783,10 @@ ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
 
   // Create the new property.
   ObjCPropertyDecl *ToProperty;
-  if (GetImportedOrCreateDecl(
-          ToProperty, D, Importer.getToContext(), DC, Loc,
-          Name.getAsIdentifierInfo(), ToAtLoc,
-          ToLParenLoc, ToType,
-          ToTypeSourceInfo, D->getPropertyImplementation()))
+  if (GetImportedOrCreateDecl(ToProperty, D, Importer.getToContext(), DC, Loc,
+                              Name.getAsIdentifierInfo(), ToAtLoc, ToLParenLoc,
+                              ToType, ToTypeSourceInfo,
+                              D->getPropertyImplementation()))
     return ToProperty;
 
   auto ToGetterName = importChecked(Err, D->getGetterName());
@@ -5855,7 +5804,7 @@ ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
 
   ToProperty->setPropertyAttributes(D->getPropertyAttributes());
   ToProperty->setPropertyAttributesAsWritten(
-                                      D->getPropertyAttributesAsWritten());
+      D->getPropertyAttributesAsWritten());
   ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
   ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
   ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
@@ -5881,9 +5830,8 @@ ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
   if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
     return std::move(Err);
 
-  ObjCPropertyImplDecl *ToImpl
-    = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
-                                   Property->getQueryKind());
+  ObjCPropertyImplDecl *ToImpl = InImpl->FindPropertyImplDecl(
+      Property->getIdentifier(), Property->getQueryKind());
   if (!ToImpl) {
 
     Error Err = Error::success();
@@ -5895,8 +5843,7 @@ ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
       return std::move(Err);
 
     if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
-                                ToBeginLoc,
-                                ToLocation, Property,
+                                ToBeginLoc, ToLocation, Property,
                                 D->getPropertyImplementation(), Ivar,
                                 ToPropertyIvarDeclLoc))
       return ToImpl;
@@ -5909,13 +5856,13 @@ ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
     if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
       Importer.ToDiag(ToImpl->getLocation(),
                       diag::warn_odr_objc_property_impl_kind_inconsistent)
-        << Property->getDeclName()
-        << (ToImpl->getPropertyImplementation()
-                                              == ObjCPropertyImplDecl::Dynamic);
+          << Property->getDeclName()
+          << (ToImpl->getPropertyImplementation() ==
+              ObjCPropertyImplDecl::Dynamic);
       Importer.FromDiag(D->getLocation(),
                         diag::note_odr_objc_property_impl_kind)
-        << D->getPropertyDecl()->getDeclName()
-        << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
+          << D->getPropertyDecl()->getDeclName()
+          << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
 
       return make_error<ASTImportError>(ASTImportError::NameConflict);
     }
@@ -5925,12 +5872,12 @@ ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
         Ivar != ToImpl->getPropertyIvarDecl()) {
       Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
                       diag::warn_odr_objc_synthesize_ivar_inconsistent)
-        << Property->getDeclName()
-        << ToImpl->getPropertyIvarDecl()->getDeclName()
-        << Ivar->getDeclName();
+          << Property->getDeclName()
+          << ToImpl->getPropertyIvarDecl()->getDeclName()
+          << Ivar->getDeclName();
       Importer.FromDiag(D->getPropertyIvarDeclLoc(),
                         diag::note_odr_objc_synthesize_ivar_here)
-        << D->getPropertyIvarDecl()->getDeclName();
+          << D->getPropertyIvarDecl()->getDeclName();
 
       return make_error<ASTImportError>(ASTImportError::NameConflict);
     }
@@ -5958,12 +5905,11 @@ ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 
   TemplateTypeParmDecl *ToD = nullptr;
   if (GetImportedOrCreateDecl(
-      ToD, D, Importer.getToContext(),
-      Importer.getToContext().getTranslationUnitDecl(),
-      *BeginLocOrErr, *LocationOrErr,
-      D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
-      D->wasDeclaredWithTypename(), D->isParameterPack(),
-      D->hasTypeConstraint()))
+          ToD, D, Importer.getToContext(),
+          Importer.getToContext().getTranslationUnitDecl(), *BeginLocOrErr,
+          *LocationOrErr, D->getDepth(), D->getIndex(),
+          Importer.Import(D->getIdentifier()), D->wasDeclaredWithTypename(),
+          D->isParameterPack(), D->hasTypeConstraint()))
     return ToD;
 
   // Import the type-constraint
@@ -6205,7 +6151,7 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 }
 
 ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
-                                          ClassTemplateSpecializationDecl *D) {
+    ClassTemplateSpecializationDecl *D) {
   ClassTemplateDecl *ClassTemplate;
   if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
     return std::move(Err);
@@ -6225,7 +6171,7 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
   void *InsertPos = nullptr;
   ClassTemplateSpecializationDecl *PrevDecl = nullptr;
   ClassTemplatePartialSpecializationDecl *PartialSpec =
-            dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
+      dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
 
   // Import template parameters.
   TemplateParameterList *ToTPList = nullptr;
@@ -6235,9 +6181,8 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
     if (!ToTPListOrErr)
       return ToTPListOrErr.takeError();
     ToTPList = *ToTPListOrErr;
-    PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
-                                                        *ToTPListOrErr,
-                                                        InsertPos);
+    PrevDecl = ClassTemplate->findPartialSpecialization(
+        TemplateArgs, *ToTPListOrErr, InsertPos);
   } else
     PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
 
@@ -6294,8 +6239,8 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
   ClassTemplateSpecializationDecl *D2 = nullptr;
   if (PartialSpec) {
     QualType CanonInjType;
-    if (Error Err = importInto(
-        CanonInjType, PartialSpec->getInjectedSpecializationType()))
+    if (Error Err = importInto(CanonInjType,
+                               PartialSpec->getInjectedSpecializationType()))
       return std::move(Err);
     CanonInjType = CanonInjType.getCanonicalType();
 
@@ -6808,7 +6753,6 @@ ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) {
   return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
 }
 
-
 ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) {
   if (Importer.returnWithErrorInTest())
     return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
@@ -6833,7 +6777,6 @@ ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) {
       Clobbers.push_back(*ClobberOrErr);
     else
       return ClobberOrErr.takeError();
-
   }
 
   SmallVector<Expr *, 4> Constraints;
@@ -6875,20 +6818,10 @@ ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) {
     return RParenLocOrErr.takeError();
 
   return new (Importer.getToContext()) GCCAsmStmt(
-      Importer.getToContext(),
-      *AsmLocOrErr,
-      S->isSimple(),
-      S->isVolatile(),
-      S->getNumOutputs(),
-      S->getNumInputs(),
-      Names.data(),
-      Constraints.data(),
-      Exprs.data(),
-      *AsmStrOrErr,
-      S->getNumClobbers(),
-      Clobbers.data(),
-      S->getNumLabels(),
-      *RParenLocOrErr);
+      Importer.getToContext(), *AsmLocOrErr, S->isSimple(), S->isVolatile(),
+      S->getNumOutputs(), S->getNumInputs(), Names.data(), Constraints.data(),
+      Exprs.data(), *AsmStrOrErr, S->getNumClobbers(), Clobbers.data(),
+      S->getNumLabels(), *RParenLocOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) {
@@ -6906,8 +6839,8 @@ ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) {
   ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
   if (!ToSemiLocOrErr)
     return ToSemiLocOrErr.takeError();
-  return new (Importer.getToContext()) NullStmt(
-      *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
+  return new (Importer.getToContext())
+      NullStmt(*ToSemiLocOrErr, S->hasLeadingEmptyMacro());
 }
 
 ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) {
@@ -6958,8 +6891,8 @@ ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) DefaultStmt(
-    ToDefaultLoc, ToColonLoc, ToSubStmt);
+  return new (Importer.getToContext())
+      DefaultStmt(ToDefaultLoc, ToColonLoc, ToSubStmt);
 }
 
 ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) {
@@ -6971,15 +6904,15 @@ ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) LabelStmt(
-      ToIdentLoc, ToLabelDecl, ToSubStmt);
+  return new (Importer.getToContext())
+      LabelStmt(ToIdentLoc, ToLabelDecl, ToSubStmt);
 }
 
 ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) {
   ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
   if (!ToAttrLocOrErr)
     return ToAttrLocOrErr.takeError();
-  ArrayRef<const Attr*> FromAttrs(S->getAttrs());
+  ArrayRef<const Attr *> FromAttrs(S->getAttrs());
   SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
   if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
     return std::move(Err);
@@ -6987,8 +6920,8 @@ ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) {
   if (!ToSubStmtOrErr)
     return ToSubStmtOrErr.takeError();
 
-  return AttributedStmt::Create(
-      Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
+  return AttributedStmt::Create(Importer.getToContext(), *ToAttrLocOrErr,
+                                ToAttrs, *ToSubStmtOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) {
@@ -7074,8 +7007,8 @@ ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) DoStmt(
-      ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
+  return new (Importer.getToContext())
+      DoStmt(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) {
@@ -7092,10 +7025,9 @@ ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ForStmt(
-      Importer.getToContext(),
-      ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
-      ToRParenLoc);
+  return new (Importer.getToContext())
+      ForStmt(Importer.getToContext(), ToInit, ToCond, ToConditionVariable,
+              ToInc, ToBody, ToForLoc, ToLParenLoc, ToRParenLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) {
@@ -7107,8 +7039,7 @@ ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) GotoStmt(
-      ToLabel, ToGotoLoc, ToLabelLoc);
+  return new (Importer.getToContext()) GotoStmt(ToLabel, ToGotoLoc, ToLabelLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
@@ -7120,8 +7051,8 @@ ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) IndirectGotoStmt(
-      ToGotoLoc, ToStarLoc, ToTarget);
+  return new (Importer.getToContext())
+      IndirectGotoStmt(ToGotoLoc, ToStarLoc, ToTarget);
 }
 
 ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) {
@@ -7160,8 +7091,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) CXXCatchStmt (
-      ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
+  return new (Importer.getToContext())
+      CXXCatchStmt(ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) {
@@ -7220,11 +7151,8 @@ ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
-                                                             ToCollection,
-                                                             ToBody,
-                                                             ToForLoc,
-                                                             ToRParenLoc);
+  return new (Importer.getToContext()) ObjCForCollectionStmt(
+      ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
@@ -7237,8 +7165,8 @@ ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ObjCAtCatchStmt (
-      ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
+  return new (Importer.getToContext())
+      ObjCAtCatchStmt(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
 }
 
 ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
@@ -7248,8 +7176,8 @@ ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
   ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
   if (!ToAtFinallyStmtOrErr)
     return ToAtFinallyStmtOrErr.takeError();
-  return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
-                                                         *ToAtFinallyStmtOrErr);
+  return new (Importer.getToContext())
+      ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, *ToAtFinallyStmtOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
@@ -7270,8 +7198,7 @@ ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
       return ToCatchStmtOrErr.takeError();
   }
 
-  return ObjCAtTryStmt::Create(Importer.getToContext(),
-                               ToAtTryLoc, ToTryBody,
+  return ObjCAtTryStmt::Create(Importer.getToContext(), ToAtTryLoc, ToTryBody,
                                ToCatchStmts.begin(), ToCatchStmts.size(),
                                ToFinallyStmt);
 }
@@ -7286,8 +7213,8 @@ ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
-    ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
+  return new (Importer.getToContext())
+      ObjCAtSynchronizedStmt(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
 }
 
 ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
@@ -7297,20 +7224,20 @@ ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
   ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
   if (!ToThrowExprOrErr)
     return ToThrowExprOrErr.takeError();
-  return new (Importer.getToContext()) ObjCAtThrowStmt(
-      *ToThrowLocOrErr, *ToThrowExprOrErr);
+  return new (Importer.getToContext())
+      ObjCAtThrowStmt(*ToThrowLocOrErr, *ToThrowExprOrErr);
 }
 
-ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt(
-    ObjCAutoreleasePoolStmt *S) {
+ExpectedStmt
+ASTNodeImporter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
   ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
   if (!ToAtLocOrErr)
     return ToAtLocOrErr.takeError();
   ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
   if (!ToSubStmtOrErr)
     return ToSubStmtOrErr.takeError();
-  return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
-                                                               *ToSubStmtOrErr);
+  return new (Importer.getToContext())
+      ObjCAutoreleasePoolStmt(*ToAtLocOrErr, *ToSubStmtOrErr);
 }
 
 //----------------------------------------------------------------------------
@@ -7349,9 +7276,9 @@ ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) VAArgExpr(
-      ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
-      E->isMicrosoftABI());
+  return new (Importer.getToContext())
+      VAArgExpr(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
+                E->isMicrosoftABI());
 }
 
 ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) {
@@ -7530,7 +7457,8 @@ ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) {
   return ToE;
 }
 
-ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
+ExpectedStmt
+ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
   ExpectedType TypeOrErr = import(E->getType());
   if (!TypeOrErr)
     return TypeOrErr.takeError();
@@ -7560,10 +7488,9 @@ ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
   if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
     return std::move(Err);
 
-  return DesignatedInitExpr::Create(
-        Importer.getToContext(), ToDesignators,
-        ToIndexExprs, *ToEqualOrColonLocOrErr,
-        E->usesGNUSyntax(), *ToInitOrErr);
+  return DesignatedInitExpr::Create(Importer.getToContext(), ToDesignators,
+                                    ToIndexExprs, *ToEqualOrColonLocOrErr,
+                                    E->usesGNUSyntax(), *ToInitOrErr);
 }
 
 ExpectedStmt
@@ -7576,8 +7503,8 @@ ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
   if (!ToLocationOrErr)
     return ToLocationOrErr.takeError();
 
-  return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
-      *ToTypeOrErr, *ToLocationOrErr);
+  return new (Importer.getToContext())
+      CXXNullPtrLiteralExpr(*ToTypeOrErr, *ToLocationOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) {
@@ -7589,11 +7516,10 @@ ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) {
   if (!ToLocationOrErr)
     return ToLocationOrErr.takeError();
 
-  return IntegerLiteral::Create(
-      Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
+  return IntegerLiteral::Create(Importer.getToContext(), E->getValue(),
+                                *ToTypeOrErr, *ToLocationOrErr);
 }
 
-
 ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
@@ -7603,9 +7529,8 @@ ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) {
   if (!ToLocationOrErr)
     return ToLocationOrErr.takeError();
 
-  return FloatingLiteral::Create(
-      Importer.getToContext(), E->getValue(), E->isExact(),
-      *ToTypeOrErr, *ToLocationOrErr);
+  return FloatingLiteral::Create(Importer.getToContext(), E->getValue(),
+                                 E->isExact(), *ToTypeOrErr, *ToLocationOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
@@ -7617,8 +7542,8 @@ ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) {
   if (!ToSubExprOrErr)
     return ToSubExprOrErr.takeError();
 
-  return new (Importer.getToContext()) ImaginaryLiteral(
-      *ToSubExprOrErr, *ToTypeOrErr);
+  return new (Importer.getToContext())
+      ImaginaryLiteral(*ToSubExprOrErr, *ToTypeOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
@@ -7654,13 +7579,13 @@ ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) {
     return ToTypeOrErr.takeError();
 
   SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated());
-  if (Error Err = ImportArrayChecked(
-      E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
+  if (Error Err = ImportArrayChecked(E->tokloc_begin(), E->tokloc_end(),
+                                     ToLocations.begin()))
     return std::move(Err);
 
-  return StringLiteral::Create(
-      Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
-      *ToTypeOrErr, ToLocations.data(), ToLocations.size());
+  return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
+                               E->getKind(), E->isPascal(), *ToTypeOrErr,
+                               ToLocations.data(), ToLocations.size());
 }
 
 ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
@@ -7673,9 +7598,9 @@ ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) CompoundLiteralExpr(
-        ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
-        ToInitializer, E->isFileScope());
+  return new (Importer.getToContext())
+      CompoundLiteralExpr(ToLParenLoc, ToTypeSourceInfo, ToType,
+                          E->getValueKind(), ToInitializer, E->isFileScope());
 }
 
 ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) {
@@ -7688,9 +7613,9 @@ ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) {
     return std::move(Err);
 
   SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
-  if (Error Err = ImportArrayChecked(
-      E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
-      ToExprs.begin()))
+  if (Error Err = ImportArrayChecked(E->getSubExprs(),
+                                     E->getSubExprs() + E->getNumSubExprs(),
+                                     ToExprs.begin()))
     return std::move(Err);
 
   return new (Importer.getToContext()) AtomicExpr(
@@ -7707,8 +7632,8 @@ ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) AddrLabelExpr(
-      ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
+  return new (Importer.getToContext())
+      AddrLabelExpr(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
 }
 ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) {
   Error Err = Error::success();
@@ -7727,8 +7652,7 @@ ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext())
-      ParenExpr(ToLParen, ToRParen, ToSubExpr);
+  return new (Importer.getToContext()) ParenExpr(ToLParen, ToRParen, ToSubExpr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) {
@@ -7757,9 +7681,8 @@ ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext())
-      StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
-               E->getTemplateDepth());
+  return new (Importer.getToContext()) StmtExpr(
+      ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, E->getTemplateDepth());
 }
 
 ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {
@@ -7799,9 +7722,9 @@ ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
     if (!ToArgumentTypeInfoOrErr)
       return ToArgumentTypeInfoOrErr.takeError();
 
-    return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
-        E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
-        ToRParenLoc);
+    return new (Importer.getToContext())
+        UnaryExprOrTypeTraitExpr(E->getKind(), *ToArgumentTypeInfoOrErr, ToType,
+                                 ToOperatorLoc, ToRParenLoc);
   }
 
   ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
@@ -7823,8 +7746,7 @@ ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) {
 
   return BinaryOperator::Create(
       Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
-      E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
-      E->getFPFeatures());
+      E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->getFPFeatures());
 }
 
 ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) {
@@ -7838,9 +7760,9 @@ ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ConditionalOperator(
-      ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
-      E->getValueKind(), E->getObjectKind());
+  return new (Importer.getToContext())
+      ConditionalOperator(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS,
+                          ToType, E->getValueKind(), E->getObjectKind());
 }
 
 ExpectedStmt
@@ -7858,9 +7780,8 @@ ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
     return std::move(Err);
 
   return new (Importer.getToContext()) BinaryConditionalOperator(
-      ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
-      ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
-      E->getObjectKind());
+      ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc,
+      ToColonLoc, ToType, E->getValueKind(), E->getObjectKind());
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXRewrittenBinaryOperator(
@@ -7899,9 +7820,9 @@ ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ExpressionTraitExpr(
-      ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
-      ToEndLoc, ToType);
+  return new (Importer.getToContext())
+      ExpressionTraitExpr(ToBeginLoc, E->getTrait(), ToQueriedExpression,
+                          E->getValue(), ToEndLoc, ToType);
 }
 
 ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
@@ -7925,9 +7846,9 @@ ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ArraySubscriptExpr(
-      ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
-      ToRBracketLoc);
+  return new (Importer.getToContext())
+      ArraySubscriptExpr(ToLHS, ToRHS, ToType, E->getValueKind(),
+                         E->getObjectKind(), ToRBracketLoc);
 }
 
 ExpectedStmt
@@ -7945,13 +7866,11 @@ ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
 
   return CompoundAssignOperator::Create(
       Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
-      E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
-      E->getFPFeatures(),
+      E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->getFPFeatures(),
       ToComputationLHSType, ToComputationResultType);
 }
 
-Expected<CXXCastPath>
-ASTNodeImporter::ImportCastPath(CastExpr *CE) {
+Expected<CXXCastPath> ASTNodeImporter::ImportCastPath(CastExpr *CE) {
   CXXCastPath Path;
   for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
     if (auto SpecOrErr = import(*I))
@@ -8110,9 +8029,8 @@ ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return OffsetOfExpr::Create(
-      Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
-      ToExprs, ToRParenLoc);
+  return OffsetOfExpr::Create(Importer.getToContext(), ToType, ToOperatorLoc,
+                              ToTypeSourceInfo, ToNodes, ToExprs, ToRParenLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
@@ -8130,8 +8048,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
   else
     ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
 
-  return new (Importer.getToContext()) CXXNoexceptExpr(
-      ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
+  return new (Importer.getToContext())
+      CXXNoexceptExpr(ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) {
@@ -8142,8 +8060,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) CXXThrowExpr(
-      ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
+  return new (Importer.getToContext())
+      CXXThrowExpr(ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
@@ -8195,8 +8113,8 @@ ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) CXXScalarValueInitExpr(
-      ToType, ToTypeSourceInfo, ToRParenLoc);
+  return new (Importer.getToContext())
+      CXXScalarValueInitExpr(ToType, ToTypeSourceInfo, ToRParenLoc);
 }
 
 ExpectedStmt
@@ -8311,12 +8229,11 @@ ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
       return std::move(Err);
   }
 
-  return SizeOfPackExpr::Create(
-      Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
-      Length, ToPartialArguments);
+  return SizeOfPackExpr::Create(Importer.getToContext(), ToOperatorLoc, ToPack,
+                                ToPackLoc, ToRParenLoc, Length,
+                                ToPartialArguments);
 }
 
-
 ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) {
   Error Err = Error::success();
   auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
@@ -8334,7 +8251,7 @@ ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) {
 
   SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
   if (Error Err =
-      ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
+          ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
     return std::move(Err);
 
   return CXXNewExpr::Create(
@@ -8392,9 +8309,8 @@ ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) {
   if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
     return std::move(Err);
 
-  return ExprWithCleanups::Create(
-      Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
-      ToObjects);
+  return ExprWithCleanups::Create(Importer.getToContext(), *ToSubExprOrErr,
+                                  E->cleanupsHaveSideEffects(), ToObjects);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
@@ -8572,14 +8488,14 @@ ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
   TemplateArgumentListInfo *ResInfo = nullptr;
   if (E->hasExplicitTemplateArgs()) {
     if (Error Err =
-        ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
+            ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
       return std::move(Err);
     ResInfo = &ToTAInfo;
   }
 
-  return DependentScopeDeclRefExpr::Create(
-      Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
-      ToNameInfo, ResInfo);
+  return DependentScopeDeclRefExpr::Create(Importer.getToContext(),
+                                           ToQualifierLoc, ToTemplateKeywordLoc,
+                                           ToNameInfo, ResInfo);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr(
@@ -8594,7 +8510,7 @@ ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr(
 
   SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
   if (Error Err =
-      ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
+          ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
     return std::move(Err);
 
   return CXXUnresolvedConstructExpr::Create(
@@ -8632,9 +8548,9 @@ ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
 
   if (E->hasExplicitTemplateArgs()) {
     TemplateArgumentListInfo ToTAInfo;
-    if (Error Err = ImportTemplateArgumentListInfo(
-        E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
-        ToTAInfo))
+    if (Error Err =
+            ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
+                                           E->template_arguments(), ToTAInfo))
       return std::move(Err);
 
     ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
@@ -8717,7 +8633,7 @@ ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) {
   unsigned NumArgs = E->getNumArgs();
   llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
   if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
-     return std::move(Err);
+    return std::move(Err);
 
   if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
     return CXXOperatorCallExpr::Create(
@@ -8760,7 +8676,6 @@ ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) {
                             ToEndLoc, E->containsUnexpandedParameterPack());
 }
 
-
 ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) {
   Error Err = Error::success();
   auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
@@ -8774,8 +8689,8 @@ ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) {
     return std::move(Err);
 
   ASTContext &ToCtx = Importer.getToContext();
-  InitListExpr *To = new (ToCtx) InitListExpr(
-      ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
+  InitListExpr *To =
+      new (ToCtx) InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
   To->setType(ToType);
 
   if (E->hasArrayFiller()) {
@@ -8806,8 +8721,8 @@ ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) {
   return To;
 }
 
-ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr(
-    CXXStdInitializerListExpr *E) {
+ExpectedStmt
+ASTNodeImporter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
     return ToTypeOrErr.takeError();
@@ -8816,12 +8731,12 @@ ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr(
   if (!ToSubExprOrErr)
     return ToSubExprOrErr.takeError();
 
-  return new (Importer.getToContext()) CXXStdInitializerListExpr(
-      *ToTypeOrErr, *ToSubExprOrErr);
+  return new (Importer.getToContext())
+      CXXStdInitializerListExpr(*ToTypeOrErr, *ToSubExprOrErr);
 }
 
-ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
-    CXXInheritedCtorInitExpr *E) {
+ExpectedStmt
+ASTNodeImporter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
   Error Err = Error::success();
   auto ToLocation = importChecked(Err, E->getLocation());
   auto ToType = importChecked(Err, E->getType());
@@ -8829,9 +8744,9 @@ ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr(
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
-      ToLocation, ToType, ToConstructor, E->constructsVBase(),
-      E->inheritedFromVBase());
+  return new (Importer.getToContext())
+      CXXInheritedCtorInitExpr(ToLocation, ToType, ToConstructor,
+                               E->constructsVBase(), E->inheritedFromVBase());
 }
 
 ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
@@ -8842,8 +8757,8 @@ ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
   if (Err)
     return std::move(Err);
 
-  return new (Importer.getToContext()) ArrayInitLoopExpr(
-      ToType, ToCommonExpr, ToSubExpr);
+  return new (Importer.getToContext())
+      ArrayInitLoopExpr(ToType, ToCommonExpr, ToSubExpr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
@@ -8984,8 +8899,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
 
   if (E->isTypeOperand()) {
     if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
-      return new (Importer.getToContext()) CXXTypeidExpr(
-          *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
+      return new (Importer.getToContext())
+          CXXTypeidExpr(*ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
     else
       return ToTSIOrErr.takeError();
   }
@@ -8994,8 +8909,8 @@ ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
   if (!ToExprOperandOrErr)
     return ToExprOperandOrErr.takeError();
 
-  return new (Importer.getToContext()) CXXTypeidExpr(
-      *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
+  return new (Importer.getToContext())
+      CXXTypeidExpr(*ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) {
@@ -9022,8 +8937,8 @@ Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
   Error ImportErrors = Error::success();
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
     if (auto ImportedOrErr = import(FromOverriddenMethod))
-      ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
-          (*ImportedOrErr)->getCanonicalDecl()));
+      ToMethod->getCanonicalDecl()->addOverriddenMethod(
+          cast<CXXMethodDecl>((*ImportedOrErr)->getCanonicalDecl()));
     else
       ImportErrors =
           joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
@@ -9052,7 +8967,7 @@ ASTImporter::~ASTImporter() = default;
 
 UnsignedOrNone ASTImporter::getFieldIndex(Decl *F) {
   assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
-      "Try to get field index for non-field.");
+         "Try to get field index for non-field.");
 
   auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
   if (!Owner)
@@ -9072,8 +8987,8 @@ UnsignedOrNone ASTImporter::getFieldIndex(Decl *F) {
   return std::nullopt;
 }
 
-ASTImporter::FoundDeclsTy
-ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
+ASTImporter::FoundDeclsTy ASTImporter::findDeclsInToCtx(DeclContext *DC,
+                                                        DeclarationName Name) {
   // We search in the redecl context because of transparent contexts.
   // E.g. a simple C language enum is a transparent context:
   //   enum E { A, B };
@@ -9560,13 +9475,13 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
           break;
         PrevFromDi = FromDi;
         setImportDeclError(FromDi, ErrOut);
-        //FIXME Should we remove these Decls from ImportedDecls?
-        // Set the error for the mapped to Decl, which is in the "to" context.
+        // FIXME Should we remove these Decls from ImportedDecls?
+        //  Set the error for the mapped to Decl, which is in the "to" context.
         auto Ii = ImportedDecls.find(FromDi);
         if (Ii != ImportedDecls.end())
           SharedState->setImportDeclError(Ii->second, ErrOut);
-          // FIXME Should we remove these Decls from the LookupTable,
-          // and from ImportedFromDecls?
+        // FIXME Should we remove these Decls from the LookupTable,
+        // and from ImportedFromDecls?
       }
     }
     SavedImportPaths.erase(FromD);
@@ -9646,7 +9561,7 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
 
     if (FromRecord->isCompleteDefinition())
       if (Error Err = ASTNodeImporter(*this).ImportDefinition(
-          FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
+              FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
         return std::move(Err);
   } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
     auto *FromEnum = cast<EnumDecl>(FromDC);
@@ -9654,7 +9569,7 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
       // Do nothing.
     } else if (FromEnum->isCompleteDefinition()) {
       if (Error Err = ASTNodeImporter(*this).ImportDefinition(
-          FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
+              FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
         return std::move(Err);
     } else {
       CompleteDecl(ToEnum);
@@ -9665,7 +9580,7 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
       // Do nothing.
     } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
       if (Error Err = ASTNodeImporter(*this).ImportDefinition(
-          FromDef, ToClass, ASTNodeImporter::IDK_Basic))
+              FromDef, ToClass, ASTNodeImporter::IDK_Basic))
         return std::move(Err);
     } else {
       CompleteDecl(ToClass);
@@ -9676,7 +9591,7 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
       // Do nothing.
     } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
       if (Error Err = ASTNodeImporter(*this).ImportDefinition(
-          FromDef, ToProto, ASTNodeImporter::IDK_Basic))
+              FromDef, ToProto, ASTNodeImporter::IDK_Basic))
         return std::move(Err);
     } else {
       CompleteDecl(ToProto);
@@ -9775,7 +9690,7 @@ ASTImporter::Import(NestedNameSpecifier *FromNNS) {
 Expected<NestedNameSpecifierLoc>
 ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
   // Copied from NestedNameSpecifier mostly.
-  SmallVector<NestedNameSpecifierLoc , 8> NestedNames;
+  SmallVector<NestedNameSpecifierLoc, 8> NestedNames;
   NestedNameSpecifierLoc NNS = FromNNS;
 
   // Push each of the nested-name-specifiers's onto a stack for
@@ -9844,7 +9759,7 @@ ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
                         ToSourceRangeOrErr->getBegin(),
                         ToSourceRangeOrErr->getEnd());
     }
-  }
+    }
   }
 
   return Builder.getWithLocInContext(getToContext());
@@ -9854,7 +9769,8 @@ Expected<TemplateName> ASTImporter::Import(TemplateName From) {
   switch (From.getKind()) {
   case TemplateName::Template:
     if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-      return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
+      return TemplateName(
+          cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
     else
       return ToTemplateOrErr.takeError();
 
@@ -10160,32 +10076,29 @@ Error ASTImporter::ImportDefinition(Decl *From) {
 
   if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
     if (!ToRecord->getDefinition()) {
-      return Importer.ImportDefinition(
-          cast<RecordDecl>(FromDC), ToRecord,
-          ASTNodeImporter::IDK_Everything);
+      return Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
+                                       ASTNodeImporter::IDK_Everything);
     }
   }
 
   if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
     if (!ToEnum->getDefinition()) {
-      return Importer.ImportDefinition(
-          cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
+      return Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum,
+                                       ASTNodeImporter::IDK_Everything);
     }
   }
 
   if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
     if (!ToIFace->getDefinition()) {
-      return Importer.ImportDefinition(
-          cast<ObjCInterfaceDecl>(FromDC), ToIFace,
-          ASTNodeImporter::IDK_Everything);
+      return Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace,
+                                       ASTNodeImporter::IDK_Everything);
     }
   }
 
   if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
     if (!ToProto->getDefinition()) {
-      return Importer.ImportDefinition(
-          cast<ObjCProtocolDecl>(FromDC), ToProto,
-          ASTNodeImporter::IDK_Everything);
+      return Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto,
+                                       ASTNodeImporter::IDK_Everything);
     }
   }
 
@@ -10242,7 +10155,7 @@ Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) {
 
   case DeclarationName::CXXOperatorName:
     return ToContext.DeclarationNames.getCXXOperatorName(
-                                          FromName.getCXXOverloadedOperator());
+        FromName.getCXXOverloadedOperator());
 
   case DeclarationName::CXXLiteralOperatorName:
     return ToContext.DeclarationNames.getCXXLiteralOperatorName(
@@ -10463,7 +10376,7 @@ Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name,
 DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
   if (LastDiagFromFrom)
     ToContext.getDiagnostics().notePriorDiagnosticFrom(
-      FromContext.getDiagnostics());
+        FromContext.getDiagnostics());
   LastDiagFromFrom = false;
   return ToContext.getDiagnostics().Report(Loc, DiagID);
 }
@@ -10471,27 +10384,24 @@ DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) {
 DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) {
   if (!LastDiagFromFrom)
     FromContext.getDiagnostics().notePriorDiagnosticFrom(
-      ToContext.getDiagnostics());
+        ToContext.getDiagnostics());
   LastDiagFromFrom = true;
   return FromContext.getDiagnostics().Report(Loc, DiagID);
 }
 
-void ASTImporter::CompleteDecl (Decl *D) {
+void ASTImporter::CompleteDecl(Decl *D) {
   if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
     if (!ID->getDefinition())
       ID->startDefinition();
-  }
-  else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
+  } else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
     if (!PD->getDefinition())
       PD->startDefinition();
-  }
-  else if (auto *TD = dyn_cast<TagDecl>(D)) {
+  } else if (auto *TD = dyn_cast<TagDecl>(D)) {
     if (!TD->getDefinition() && !TD->isBeingDefined()) {
       TD->startDefinition();
       TD->setCompleteDefinition(true);
     }
-  }
-  else {
+  } else {
     assert(0 && "CompleteDecl called on a Decl that can't be completed");
   }
 }
diff --git a/clang/lib/ASTImporter/ASTImporterLookupTable.cpp b/clang/lib/ASTImporter/ASTImporterLookupTable.cpp
index 7dda8c3a0..1364b23ee 100644
--- a/clang/lib/ASTImporter/ASTImporterLookupTable.cpp
+++ b/clang/lib/ASTImporter/ASTImporterLookupTable.cpp
@@ -187,7 +187,7 @@ void ASTImporterLookupTable::dump(DeclContext *DC) const {
     DeclarationName Name = Entry.first;
     llvm::errs() << "==== Name: ";
     Name.dump();
-    const DeclList& List = Entry.second;
+    const DeclList &List = Entry.second;
     for (NamedDecl *ND : List) {
       ND->dump();
     }
diff --git a/clang/lib/ASTImporter/ExternalASTMerger.cpp b/clang/lib/ASTImporter/ExternalASTMerger.cpp
index f2fe1987d..c9189c8bd 100644
--- a/clang/lib/ASTImporter/ExternalASTMerger.cpp
+++ b/clang/lib/ASTImporter/ExternalASTMerger.cpp
@@ -11,12 +11,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "clang/ASTImporter/ExternalASTMerger.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
-#include "clang/ASTImporter/ExternalASTMerger.h"
 
 using namespace clang;
 
@@ -109,6 +109,7 @@ private:
   /// @see ExternalASTMerger::ImporterSource::Merger
   ExternalASTMerger *SourceMerger;
   llvm::raw_ostream &logs() { return Parent.logs(); }
+
 public:
   LazyASTImporter(ExternalASTMerger &_Parent, ASTContext &ToContext,
                   FileManager &ToFileManager,
@@ -186,9 +187,7 @@ public:
 
   /// Implements the ASTImporter interface for tracking back a declaration
   /// to its original declaration it came from.
-  Decl *GetOriginalDecl(Decl *To) override {
-    return ToOrigin.lookup(To);
-  }
+  Decl *GetOriginalDecl(Decl *To) override { return ToOrigin.lookup(To); }
 
   /// Whenever a DeclContext is imported, ensure that ExternalASTSource's origin
   /// map is kept up to date.  Also set the appropriate flags.
@@ -198,12 +197,12 @@ public:
     if (auto *ToDC = dyn_cast<DeclContext>(To)) {
       const bool LoggingEnabled = Parent.LoggingEnabled();
       if (LoggingEnabled)
-        logs() << "(ExternalASTMerger*)" << (void*)&Parent
-               << " imported (DeclContext*)" << (void*)ToDC
-               << ", (ASTContext*)" << (void*)&getToContext()
-               << " from (DeclContext*)" << (void*)llvm::cast<DeclContext>(From)
-               << ", (ASTContext*)" << (void*)&getFromContext()
-               << "\n";
+        logs() << "(ExternalASTMerger*)" << (void *)&Parent
+               << " imported (DeclContext*)" << (void *)ToDC
+               << ", (ASTContext*)" << (void *)&getToContext()
+               << " from (DeclContext*)"
+               << (void *)llvm::cast<DeclContext>(From) << ", (ASTContext*)"
+               << (void *)&getFromContext() << "\n";
       Source<DeclContext *> FromDC(
           cast<DeclContext>(From)->getPrimaryContext());
       if (auto It = FromOrigins.find(FromDC);
@@ -216,10 +215,9 @@ public:
         Parent.ForceRecordOrigin(ToDC, It->second);
       } else {
         if (LoggingEnabled)
-          logs() << "(ExternalASTMerger*)" << (void*)&Parent
-                 << " maybe recording origin (DeclContext*)" << (void*)FromDC
-                 << ", (ASTContext*)" << (void*)&getFromContext()
-                 << "\n";
+          logs() << "(ExternalASTMerger*)" << (void *)&Parent
+                 << " maybe recording origin (DeclContext*)" << (void *)FromDC
+                 << ", (ASTContext*)" << (void *)&getFromContext() << "\n";
         Parent.MaybeRecordOrigin(ToDC, {FromDC, &getFromContext()});
       }
     }
@@ -258,11 +256,11 @@ ASTImporter &ExternalASTMerger::ImporterForOrigin(ASTContext &OriginContext) {
 
 namespace {
 LazyASTImporter &LazyImporterForOrigin(ExternalASTMerger &Merger,
-                                   ASTContext &OriginContext) {
+                                       ASTContext &OriginContext) {
   return static_cast<LazyASTImporter &>(
       Merger.ImporterForOrigin(OriginContext));
 }
-}
+} // namespace
 
 bool ExternalASTMerger::HasImporterForOrigin(ASTContext &OriginContext) {
   for (const std::unique_ptr<ASTImporter> &I : Importers)
@@ -292,36 +290,39 @@ void ExternalASTMerger::ForEachMatchingDC(const DeclContext *DC,
       }
     }
     if (!DidCallback && LoggingEnabled())
-      logs() << "(ExternalASTMerger*)" << (void*)this
-             << " asserting for (DeclContext*)" << (const void*)DC
-             << ", (ASTContext*)" << (void*)&Target.AST
-             << "\n";
+      logs() << "(ExternalASTMerger*)" << (void *)this
+             << " asserting for (DeclContext*)" << (const void *)DC
+             << ", (ASTContext*)" << (void *)&Target.AST << "\n";
     assert(DidCallback && "Couldn't find a source context matching our DC");
   }
 }
 
 void ExternalASTMerger::CompleteType(TagDecl *Tag) {
   assert(Tag->hasExternalLexicalStorage());
-  ForEachMatchingDC(Tag, [&](ASTImporter &Forward, ASTImporter &Reverse,
-                             Source<const DeclContext *> SourceDC) -> bool {
-    auto *SourceTag = const_cast<TagDecl *>(cast<TagDecl>(SourceDC.get()));
-    if (SourceTag->hasExternalLexicalStorage())
-      SourceTag->getASTContext().getExternalSource()->CompleteType(SourceTag);
-    if (!SourceTag->getDefinition())
-      return false;
-    Forward.MapImported(SourceTag, Tag);
-    if (llvm::Error Err = Forward.ImportDefinition(SourceTag))
-      llvm::consumeError(std::move(Err));
-    Tag->setCompleteDefinition(SourceTag->isCompleteDefinition());
-    return true;
-  });
+  ForEachMatchingDC(
+      Tag,
+      [&](ASTImporter &Forward, ASTImporter &Reverse,
+          Source<const DeclContext *> SourceDC) -> bool {
+        auto *SourceTag = const_cast<TagDecl *>(cast<TagDecl>(SourceDC.get()));
+        if (SourceTag->hasExternalLexicalStorage())
+          SourceTag->getASTContext().getExternalSource()->CompleteType(
+              SourceTag);
+        if (!SourceTag->getDefinition())
+          return false;
+        Forward.MapImported(SourceTag, Tag);
+        if (llvm::Error Err = Forward.ImportDefinition(SourceTag))
+          llvm::consumeError(std::move(Err));
+        Tag->setCompleteDefinition(SourceTag->isCompleteDefinition());
+        return true;
+      });
 }
 
 void ExternalASTMerger::CompleteType(ObjCInterfaceDecl *Interface) {
   assert(Interface->hasExternalLexicalStorage());
   ForEachMatchingDC(
-      Interface, [&](ASTImporter &Forward, ASTImporter &Reverse,
-                     Source<const DeclContext *> SourceDC) -> bool {
+      Interface,
+      [&](ASTImporter &Forward, ASTImporter &Reverse,
+          Source<const DeclContext *> SourceDC) -> bool {
         auto *SourceInterface = const_cast<ObjCInterfaceDecl *>(
             cast<ObjCInterfaceDecl>(SourceDC.get()));
         if (SourceInterface->hasExternalLexicalStorage())
@@ -359,7 +360,7 @@ bool IsSameDC(const DeclContext *D1, const DeclContext *D2) {
         return true;
   return D1 == D2 || D1 == CanonicalizeDC(D2);
 }
-}
+} // namespace
 
 void ExternalASTMerger::MaybeRecordOrigin(const DeclContext *ToDC,
                                           DCOrigin Origin) {
@@ -371,11 +372,10 @@ void ExternalASTMerger::MaybeRecordOrigin(const DeclContext *ToDC,
   if (DoRecord)
     RecordOriginImpl(ToDC, Origin, Importer);
   if (LoggingEnabled())
-    logs() << "(ExternalASTMerger*)" << (void*)this
-             << (DoRecord ? " decided " : " decided NOT")
-             << " to record origin (DeclContext*)" << (void*)Origin.DC
-             << ", (ASTContext*)" << (void*)&Origin.AST
-             << "\n";
+    logs() << "(ExternalASTMerger*)" << (void *)this
+           << (DoRecord ? " decided " : " decided NOT")
+           << " to record origin (DeclContext*)" << (void *)Origin.DC
+           << ", (ASTContext*)" << (void *)&Origin.AST << "\n";
 }
 
 void ExternalASTMerger::ForceRecordOrigin(const DeclContext *ToDC,
@@ -383,14 +383,17 @@ void ExternalASTMerger::ForceRecordOrigin(const DeclContext *ToDC,
   RecordOriginImpl(ToDC, Origin, ImporterForOrigin(*Origin.AST));
 }
 
-void ExternalASTMerger::RecordOriginImpl(const DeclContext *ToDC, DCOrigin Origin,
+void ExternalASTMerger::RecordOriginImpl(const DeclContext *ToDC,
+                                         DCOrigin Origin,
                                          ASTImporter &Importer) {
   Origins[ToDC] = Origin;
-  Importer.ASTImporter::MapImported(cast<Decl>(Origin.DC), const_cast<Decl*>(cast<Decl>(ToDC)));
+  Importer.ASTImporter::MapImported(cast<Decl>(Origin.DC),
+                                    const_cast<Decl *>(cast<Decl>(ToDC)));
 }
 
 ExternalASTMerger::ExternalASTMerger(const ImporterTarget &Target,
-                                     llvm::ArrayRef<ImporterSource> Sources) : LogStream(&llvm::nulls()), Target(Target) {
+                                     llvm::ArrayRef<ImporterSource> Sources)
+    : LogStream(&llvm::nulls()), Target(Target) {
   SharedState = std::make_shared<ASTImporterSharedState>(
       *Target.AST.getTranslationUnitDecl());
   AddSources(Sources);
@@ -428,7 +431,8 @@ void ExternalASTMerger::RemoveSources(llvm::ArrayRef<ImporterSource> Sources) {
                    }
                    return false;
                  });
-  for (OriginMap::iterator OI = Origins.begin(), OE = Origins.end(); OI != OE; ) {
+  for (OriginMap::iterator OI = Origins.begin(), OE = Origins.end();
+       OI != OE;) {
     std::pair<const DeclContext *, DCOrigin> Origin = *OI;
     bool Erase = false;
     for (const ImporterSource &S : Sources) {
@@ -476,8 +480,8 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(
   llvm::SmallVector<Candidate, 4> Candidates;
 
   auto FilterFoundDecl = [&Candidates](const Candidate &C) {
-   if (!HasDeclOfSameType(Candidates, C))
-     Candidates.push_back(C);
+    if (!HasDeclOfSameType(Candidates, C))
+      Candidates.push_back(C);
   };
 
   ForEachMatchingDC(DC,
@@ -522,18 +526,20 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(
 void ExternalASTMerger::FindExternalLexicalDecls(
     const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
     SmallVectorImpl<Decl *> &Result) {
-  ForEachMatchingDC(DC, [&](ASTImporter &Forward, ASTImporter &Reverse,
-                            Source<const DeclContext *> SourceDC) -> bool {
-    for (const Decl *SourceDecl : SourceDC.get()->decls()) {
-      if (IsKindWeWant(SourceDecl->getKind())) {
-        auto ImportedDeclOrErr = Forward.Import(SourceDecl);
-        if (ImportedDeclOrErr)
-          assert(!(*ImportedDeclOrErr) ||
-                 IsSameDC((*ImportedDeclOrErr)->getDeclContext(), DC));
-        else
-          llvm::consumeError(ImportedDeclOrErr.takeError());
-      }
-    }
-    return false;
-  });
+  ForEachMatchingDC(
+      DC,
+      [&](ASTImporter &Forward, ASTImporter &Reverse,
+          Source<const DeclContext *> SourceDC) -> bool {
+        for (const Decl *SourceDecl : SourceDC.get()->decls()) {
+          if (IsKindWeWant(SourceDecl->getKind())) {
+            auto ImportedDeclOrErr = Forward.Import(SourceDecl);
+            if (ImportedDeclOrErr)
+              assert(!(*ImportedDeclOrErr) ||
+                     IsSameDC((*ImportedDeclOrErr)->getDeclContext(), DC));
+            else
+              llvm::consumeError(ImportedDeclOrErr.takeError());
+          }
+        }
+        return false;
+      });
 }
diff --git a/clang/lib/Frontend/ASTMerge.cpp b/clang/lib/Frontend/ASTMerge.cpp
index a30357976..564c2473d 100644
--- a/clang/lib/Frontend/ASTMerge.cpp
+++ b/clang/lib/Frontend/ASTMerge.cpp
@@ -5,12 +5,12 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/ASTImporter/ASTImporter.h"
 #include "clang/ASTImporter/ASTImporterSharedState.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/140913


More information about the cfe-commits mailing list