balazske created this revision. Herald added subscribers: whisperity, 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.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D110395 Files: clang/include/clang/AST/ASTImporter.h clang/include/clang/ASTMatchers/ASTMatchers.h clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp =================================================================== --- clang/unittests/AST/ASTImporterTest.cpp +++ clang/unittests/AST/ASTImporterTest.cpp @@ -6775,6 +6775,31 @@ ToD->getTemplateSpecializationKind()); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportIsInheritingConstructorBit) { + Decl *FromTU = getTuDecl( + R"( + class a { + public: + a(int); + }; + struct b : a { + using a::a; // Ihnerited ctor. + }; + void c() { + (b(0)); + } + )", + Lang_CXX11); + auto *FromD = FirstDeclMatcher<CXXConstructorDecl>().match( + FromTU, cxxConstructorDecl(isInheritingConstructor())); + ASSERT_TRUE(FromD); + ASSERT_TRUE(FromD->isInheritingConstructor()); + + auto *ToD = Import(FromD, Lang_CXX11); + ASSERT_TRUE(ToD); + EXPECT_TRUE(ToD->isInheritingConstructor()); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); Index: clang/lib/AST/ASTImporter.cpp =================================================================== --- clang/lib/AST/ASTImporter.cpp +++ clang/lib/AST/ASTImporter.cpp @@ -477,6 +477,9 @@ Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam); + Expected<InheritedConstructor> + ImportInheritedConstructor(const InheritedConstructor &From); + template <typename T> bool hasSameVisibilityContextAndLinkage(T *Found, T *From); @@ -3477,13 +3480,19 @@ importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier()); if (Err) return std::move(Err); + auto ToInheritedConstructor = InheritedConstructor(); + if (FromConstructor->isInheritingConstructor()) { + Expected<InheritedConstructor> ImportedInheritedCtor = + import(FromConstructor->getInheritedConstructor()); + if (!ImportedInheritedCtor) + return ImportedInheritedCtor.takeError(); + ToInheritedConstructor = *ImportedInheritedCtor; + } if (GetImportedOrCreateDecl<CXXConstructorDecl>( ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(), D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), - InheritedConstructor(), // FIXME: Properly import inherited - // constructor info - TrailingRequiresClause)) + ToInheritedConstructor, TrailingRequiresClause)) return ToFunction; } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { @@ -4217,6 +4226,17 @@ return Error::success(); } +Expected<InheritedConstructor> +ASTNodeImporter::ImportInheritedConstructor(const InheritedConstructor &From) { + Error Err = Error::success(); + CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor()); + ConstructorUsingShadowDecl *ToShadow = + importChecked(Err, From.getShadowDecl()); + if (Err) + return std::move(Err); + return InheritedConstructor(ToShadow, ToBaseCtor); +} + ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { // Parameters are created in the translation unit's context, then moved // into the function declaration's context afterward. @@ -4756,9 +4776,23 @@ return ToTargetOrErr.takeError(); UsingShadowDecl *ToShadow; - if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, - Name, *ToIntroducerOrErr, *ToTargetOrErr)) - return ToShadow; + if (auto *FromConstructorUsingShadow = + dyn_cast<ConstructorUsingShadowDecl>(D)) { + if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>( + ToShadow, D, Importer.getToContext(), DC, Loc, + cast<UsingDecl>(*ToIntroducerOrErr), *ToTargetOrErr, + FromConstructorUsingShadow->constructsVirtualBase())) + return ToShadow; + // FIXME import the below members! + // FromConstructorUsingShadow->getNominatedBaseClassShadowDecl(); + // FromConstructorUsingShadow->getConstructedBaseClassShadowDecl(); + // FromConstructorUsingShadow->getNominatedBaseClass(); + // FromConstructorUsingShadow->getConstructedBaseClass(); + } else { + if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, + Name, *ToIntroducerOrErr, *ToTargetOrErr)) + return ToShadow; + } ToShadow->setLexicalDeclContext(LexicalDC); ToShadow->setAccess(D->getAccess()); @@ -8617,6 +8651,11 @@ return ToDOrErr; } +llvm::Expected<InheritedConstructor> +ASTImporter::Import(const InheritedConstructor &From) { + return ASTNodeImporter(*this).ImportInheritedConstructor(From); +} + Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { if (!FromDC) return FromDC; Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -5877,6 +5877,10 @@ return Node.isVirtualAsWritten(); } +AST_MATCHER(CXXConstructorDecl, isInheritingConstructor) { + return Node.isInheritingConstructor(); +} + /// Matches if the given method or class declaration is final. /// /// Given: Index: clang/include/clang/AST/ASTImporter.h =================================================================== --- clang/include/clang/AST/ASTImporter.h +++ clang/include/clang/AST/ASTImporter.h @@ -379,6 +379,9 @@ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits