Author: pcc Date: Tue Dec 19 17:47:08 2017 New Revision: 321139 URL: http://llvm.org/viewvc/llvm-project?rev=321139&view=rev Log: Revert r320942, "[ASTImporter] Support importing FunctionTemplateDecl and CXXDependentScopeMemberExpr"
Caused a test failure on Windows: [ RUN ] ImportExpr.ImportCXXDependentScopeMemberExpr C:\b\rr\tmppzcp4w\w\src\third_party\llvm\tools\clang\unittests\AST\ASTImporterTest.cpp(526): error: Value of: testImport("template <typename T> class C { T t; };" "template <typename T> void declToImport() {" " C<T> d;" " d.t;" "}", Lang_CXX, "", Lang_CXX, Verifier, functionTemplateDecl(has(functionDecl(has(compoundStmt( has(cxxDependentScopeMemberExpr()))))))) Actual: false (Could not find match) Expected: true C:\b\rr\tmppzcp4w\w\src\third_party\llvm\tools\clang\unittests\AST\ASTImporterTest.cpp(534): error: Value of: testImport("template <typename T> class C { T t; };" "template <typename T> void declToImport() {" " C<T> d;" " (&d)->t;" "}", Lang_CXX, "", Lang_CXX, Verifier, functionTemplateDecl(has(functionDecl(has(compoundStmt( has(cxxDependentScopeMemberExpr()))))))) Actual: false (Could not find match) Expected: true [ FAILED ] ImportExpr.ImportCXXDependentScopeMemberExpr (37 ms) Modified: cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/lib/AST/ASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=321139&r1=321138&r2=321139&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp (original) +++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Dec 19 17:47:08 2017 @@ -134,17 +134,12 @@ namespace clang { bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl<TemplateArgument> &ToArgs); - template <typename InContainerTy> - bool ImportTemplateArgumentListInfo(const InContainerTy &Container, - TemplateArgumentListInfo &ToTAInfo); bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, bool Complain = true); bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, bool Complain = true); bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); - bool IsStructuralMatch(FunctionTemplateDecl *From, - FunctionTemplateDecl *To); bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); Decl *VisitDecl(Decl *D); @@ -200,7 +195,6 @@ namespace clang { ClassTemplateSpecializationDecl *D); Decl *VisitVarTemplateDecl(VarTemplateDecl *D); Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); - Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); // Importing statements DeclGroupRef ImportDeclGroup(DeclGroupRef DG); @@ -286,7 +280,6 @@ namespace clang { Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); Expr *VisitCXXConstructExpr(CXXConstructExpr *E); Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); - Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); Expr *VisitCXXThisExpr(CXXThisExpr *E); Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); @@ -1254,18 +1247,6 @@ bool ASTNodeImporter::ImportTemplateArgu return false; } -template <typename InContainerTy> -bool ASTNodeImporter::ImportTemplateArgumentListInfo( - const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { - for (const auto &FromLoc : Container) { - if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) - ToTAInfo.addArgument(*ToLoc); - else - return true; - } - return false; -} - bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, bool Complain) { // Eliminate a potential failure point where we attempt to re-import @@ -1299,14 +1280,6 @@ bool ASTNodeImporter::IsStructuralMatch( return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); } -bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, - FunctionTemplateDecl *To) { - StructuralEquivalenceContext Ctx( - Importer.getFromContext(), Importer.getToContext(), - Importer.getNonEquivalentDecls(), false, false); - return Ctx.IsStructurallyEquivalent(From, To); -} - bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC) { @@ -4224,64 +4197,6 @@ Decl *ASTNodeImporter::VisitVarTemplateS return D2; } -Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { - DeclContext *DC, *LexicalDC; - DeclarationName Name; - SourceLocation Loc; - NamedDecl *ToD; - - if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) - return nullptr; - - if (ToD) - return ToD; - - // Try to find a function in our own ("to") context with the same name, same - // type, and in the same context as the function we're importing. - if (!LexicalDC->isFunctionOrMethod()) { - unsigned IDNS = Decl::IDNS_Ordinary; - SmallVector<NamedDecl *, 2> FoundDecls; - DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); - for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) - continue; - - if (FunctionTemplateDecl *FoundFunction = - dyn_cast<FunctionTemplateDecl>(FoundDecls[I])) { - if (FoundFunction->hasExternalFormalLinkage() && - D->hasExternalFormalLinkage()) { - if (IsStructuralMatch(D, FoundFunction)) { - Importer.Imported(D, FoundFunction); - // FIXME: Actually try to merge the body and other attributes. - return FoundFunction; - } - } - } - } - } - - TemplateParameterList *Params = - ImportTemplateParameterList(D->getTemplateParameters()); - if (!Params) - return nullptr; - - FunctionDecl *TemplatedFD = - cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); - if (!TemplatedFD) - return nullptr; - - FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( - Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); - - TemplatedFD->setDescribedFunctionTemplate(ToFunc); - ToFunc->setAccess(D->getAccess()); - ToFunc->setLexicalDeclContext(LexicalDC); - Importer.Imported(D, ToFunc); - - LexicalDC->addDeclInternal(ToFunc); - return ToFunc; -} - //---------------------------------------------------------------------------- // Import Statements //---------------------------------------------------------------------------- @@ -5844,47 +5759,6 @@ Expr *ASTNodeImporter::VisitCXXPseudoDes Importer.Import(E->getTildeLoc()), Storage); } -Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( - CXXDependentScopeMemberExpr *E) { - Expr *Base = nullptr; - if (!E->isImplicitAccess()) { - Base = Importer.Import(E->getBase()); - if (!Base) - return nullptr; - } - - QualType BaseType = Importer.Import(E->getBaseType()); - if (BaseType.isNull()) - return nullptr; - - TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), - Importer.Import(E->getRAngleLoc())); - TemplateArgumentListInfo *ResInfo = nullptr; - if (E->hasExplicitTemplateArgs()) { - if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) - return nullptr; - ResInfo = &ToTAInfo; - } - - DeclarationName Name = Importer.Import(E->getMember()); - if (!E->getMember().isEmpty() && Name.isEmpty()) - return nullptr; - - DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); - // Import additional name location/type info. - ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); - auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); - if (!ToFQ && E->getFirstQualifierFoundInScope()) - return nullptr; - - return CXXDependentScopeMemberExpr::Create( - Importer.getToContext(), Base, BaseType, E->isArrow(), - Importer.Import(E->getOperatorLoc()), - Importer.Import(E->getQualifierLoc()), - Importer.Import(E->getTemplateKeywordLoc()), - cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); -} - Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { QualType T = Importer.Import(E->getType()); if (T.isNull()) Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=321139&r1=321138&r2=321139&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Tue Dec 19 17:47:08 2017 @@ -504,35 +504,6 @@ TEST(ImportType, ImportTypeAliasTemplate declRefExpr())))))))))); } -TEST(ImportDecl, ImportFunctionTemplateDecl) { - MatchVerifier<Decl> Verifier; - EXPECT_TRUE(testImport("template <typename T> void declToImport() { };", - Lang_CXX, "", Lang_CXX, Verifier, - functionTemplateDecl())); -} - -const internal::VariadicDynCastAllOfMatcher<Expr, CXXDependentScopeMemberExpr> - cxxDependentScopeMemberExpr; - -TEST(ImportExpr, ImportCXXDependentScopeMemberExpr) { - MatchVerifier<Decl> Verifier; - EXPECT_TRUE(testImport("template <typename T> class C { T t; };" - "template <typename T> void declToImport() {" - " C<T> d;" - " d.t;" - "}", - Lang_CXX, "", Lang_CXX, Verifier, - functionTemplateDecl(has(functionDecl(has(compoundStmt( - has(cxxDependentScopeMemberExpr())))))))); - EXPECT_TRUE(testImport("template <typename T> class C { T t; };" - "template <typename T> void declToImport() {" - " C<T> d;" - " (&d)->t;" - "}", - Lang_CXX, "", Lang_CXX, Verifier, - functionTemplateDecl(has(functionDecl(has(compoundStmt( - has(cxxDependentScopeMemberExpr())))))))); -} TEST(ImportType, ImportPackExpansion) { MatchVerifier<Decl> Verifier; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits