diff options
author | Balazs Keri <1.int32@gmail.com> | 2018-07-16 12:16:39 +0000 |
---|---|---|
committer | Balazs Keri <1.int32@gmail.com> | 2018-07-16 12:16:39 +0000 |
commit | 1d20cc20f672ed7eb5f94584905ba6e902f669eb (patch) | |
tree | 14466e68ad4d6a6dfe5335af45864b9e38dfbd98 /clang/lib/AST/ASTImporter.cpp | |
parent | c3d8002c2e1b41a05095f6a0f2e720fa9bb63c00 (diff) | |
download | bcm5719-llvm-1d20cc20f672ed7eb5f94584905ba6e902f669eb.tar.gz bcm5719-llvm-1d20cc20f672ed7eb5f94584905ba6e902f669eb.zip |
[ASTImporter] Import implicit methods of existing class.
Summary:
When an already existing class is encountered during import,
check if it has implicit methods that are missing in the existing one,
and import these.
The to-be-imported code may use the same class in different way than the
existing (before the import) code. This may result in that there are
implicit methods that are not generated for the existing code.
Reviewers: a.sidorin, a_sidorin
Reviewed By: a_sidorin
Subscribers: a_sidorin, martong, cfe-commits
Differential Revision: https://reviews.llvm.org/D49245
llvm-svn: 337162
Diffstat (limited to 'clang/lib/AST/ASTImporter.cpp')
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 56ca9bbae46..366c2064d4e 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -228,6 +228,7 @@ namespace clang { void ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo& To); void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); + void ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); bool ImportCastPath(CastExpr *E, CXXCastPath &Path); @@ -1253,6 +1254,16 @@ void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { Importer.Import(From); } +void ASTNodeImporter::ImportImplicitMethods( + const CXXRecordDecl *From, CXXRecordDecl *To) { + assert(From->isCompleteDefinition() && To->getDefinition() == To && + "Import implicit methods to or from non-definition"); + + for (CXXMethodDecl *FromM : From->methods()) + if (FromM->isImplicit()) + Importer.Import(FromM); +} + static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer) { if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { @@ -2199,8 +2210,19 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { // The record types structurally match, or the "from" translation // unit only had a forward declaration anyway; call it the same // function. - // FIXME: For C++, we should also merge methods here. - return Importer.MapImported(D, FoundDef); + // FIXME: Structural equivalence check should check for same + // user-defined methods. + Importer.MapImported(D, FoundDef); + if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { + auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); + assert(FoundCXX && "Record type mismatch"); + + if (D->isCompleteDefinition() && !Importer.isMinimalImport()) + // FoundDef may not have every implicit method that D has + // because implicit methods are created only if they are used. + ImportImplicitMethods(DCXX, FoundCXX); + } + return FoundDef; } } else if (!D->isCompleteDefinition()) { // We have a forward declaration of this type, so adopt that forward |