Author: Balázs Kéri Date: 2021-03-22T14:38:49+01:00 New Revision: ce9bade1f2c6249cf4179842aeb5e7e3bb34ceec
URL: https://github.com/llvm/llvm-project/commit/ce9bade1f2c6249cf4179842aeb5e7e3bb34ceec DIFF: https://github.com/llvm/llvm-project/commit/ce9bade1f2c6249cf4179842aeb5e7e3bb34ceec.diff LOG: [clang][ASTImporter] Add import API for 'const Type *' (NFC). 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`.) Reviewed By: shafik, teemperor, martong Differential Revision: https://reviews.llvm.org/D98951 Added: Modified: clang/include/clang/AST/ASTImporter.h clang/lib/AST/ASTImporter.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h index 630d220deff7..17e673a8471a 100644 --- a/clang/include/clang/AST/ASTImporter.h +++ b/clang/include/clang/AST/ASTImporter.h @@ -344,6 +344,12 @@ class TypeSourceInfo; 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. diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index bf3cb4c42873..182a57c16aba 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -8168,28 +8168,37 @@ ASTImporter::Import(ExprWithCleanups::CleanupObject From) { 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits