balazske created this revision. Herald added subscribers: martong, teemperor, gamesh411, Szelethus, dkrupp. Herald added a reviewer: a.sidorin. Herald added a reviewer: shafik. balazske requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
There was only an `Import` function for `QualType` but not for `Type`. For correct import of some AST nodes where not `QualType` is used an import of `Type *` is needed. (It is the case with `FieldDecl::getCapturedVLAType`.) Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D98951 Files: clang/include/clang/AST/ASTImporter.h clang/lib/AST/ASTImporter.cpp Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -8151,28 +8151,37 @@ return make_error<ImportError>(ImportError::UnsupportedConstruct); } -Expected<QualType> ASTImporter::Import(QualType FromT) { - if (FromT.isNull()) - return QualType{}; - - const Type *FromTy = FromT.getTypePtr(); +Expected<const Type *> ASTImporter::Import(const Type *FromT) { + if (!FromT) + return FromT; // Check whether we've already imported this type. - llvm::DenseMap<const Type *, const Type *>::iterator Pos - = ImportedTypes.find(FromTy); + llvm::DenseMap<const Type *, const Type *>::iterator Pos = + ImportedTypes.find(FromT); if (Pos != ImportedTypes.end()) - return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); + return Pos->second; // Import the type ASTNodeImporter Importer(*this); - ExpectedType ToTOrErr = Importer.Visit(FromTy); + ExpectedType ToTOrErr = Importer.Visit(FromT); if (!ToTOrErr) return ToTOrErr.takeError(); // Record the imported type. - ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); + ImportedTypes[FromT] = ToTOrErr->getTypePtr(); + + return ToTOrErr->getTypePtr(); +} + +Expected<QualType> ASTImporter::Import(QualType FromT) { + if (FromT.isNull()) + return QualType{}; + + Expected<const Type *> ToTyOrErr = Import(FromT.getTypePtr()); + if (!ToTyOrErr) + return ToTyOrErr.takeError(); - return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); + return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers()); } Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { Index: clang/include/clang/AST/ASTImporter.h =================================================================== --- clang/include/clang/AST/ASTImporter.h +++ clang/include/clang/AST/ASTImporter.h @@ -344,6 +344,12 @@ 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.
Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -8151,28 +8151,37 @@ return make_error<ImportError>(ImportError::UnsupportedConstruct); } -Expected<QualType> ASTImporter::Import(QualType FromT) { - if (FromT.isNull()) - return QualType{}; - - const Type *FromTy = FromT.getTypePtr(); +Expected<const Type *> ASTImporter::Import(const Type *FromT) { + if (!FromT) + return FromT; // Check whether we've already imported this type. - llvm::DenseMap<const Type *, const Type *>::iterator Pos - = ImportedTypes.find(FromTy); + llvm::DenseMap<const Type *, const Type *>::iterator Pos = + ImportedTypes.find(FromT); if (Pos != ImportedTypes.end()) - return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); + return Pos->second; // Import the type ASTNodeImporter Importer(*this); - ExpectedType ToTOrErr = Importer.Visit(FromTy); + ExpectedType ToTOrErr = Importer.Visit(FromT); if (!ToTOrErr) return ToTOrErr.takeError(); // Record the imported type. - ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); + ImportedTypes[FromT] = ToTOrErr->getTypePtr(); + + return ToTOrErr->getTypePtr(); +} + +Expected<QualType> ASTImporter::Import(QualType FromT) { + if (FromT.isNull()) + return QualType{}; + + Expected<const Type *> ToTyOrErr = Import(FromT.getTypePtr()); + if (!ToTyOrErr) + return ToTyOrErr.takeError(); - return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); + return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers()); } Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { Index: clang/include/clang/AST/ASTImporter.h =================================================================== --- clang/include/clang/AST/ASTImporter.h +++ clang/include/clang/AST/ASTImporter.h @@ -344,6 +344,12 @@ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits