[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
This revision was automatically updated to reflect the committed changes. Closed by commit rC337260: [ASTImporter] Import described template (if any) of function. (authored by balazske, committed by ). Changed prior to commit: https://reviews.llvm.org/D49235?vs=155630=155832#toc Repository: rC Clang https://reviews.llvm.org/D49235 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2539,6 +2539,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2565,6 +2566,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2740,6 +2749,11 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) +if (!Importer.Import(FromFT)) + return nullptr; + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1185,7 +1185,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2539,6 +2539,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2565,6 +2566,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2740,6 +2749,11 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) +if (!Importer.Import(FromFT)) + return nullptr; + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1185,7 +1185,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
a_sidorin accepted this revision. a_sidorin added a comment. This revision is now accepted and ready to land. LGTM. Repository: rC Clang https://reviews.llvm.org/D49235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
balazske updated this revision to Diff 155630. balazske added a comment. - Removed setDescribedFunctionTemplate call. Repository: rC Clang https://reviews.llvm.org/D49235 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1125,7 +1125,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2499,6 +2499,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2525,6 +2526,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2700,6 +2709,11 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) +if (!Importer.Import(FromFT)) + return nullptr; + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1125,7 +1125,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2499,6 +2499,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2525,6 +2526,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2700,6 +2709,11 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) +if (!Importer.Import(FromFT)) + return nullptr; + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
balazske added inline comments. Comment at: lib/AST/ASTImporter.cpp:2715 +if (auto *ToFT = dyn_cast(Importer.Import(FromFT))) + ToFunction->setDescribedFunctionTemplate(ToFT); +else a_sidorin wrote: > The function template should be already set after > `getDescribedFunctionTemplate()` is imported in > `VisitFunctionTemplateDecl()`. Are there still cases not covered by this? Yes this call can be omitted. But check of return value of Import is needed (the current code is not good: nullptr is not accepted by dyn_cast). Repository: rC Clang https://reviews.llvm.org/D49235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
a_sidorin added a comment. Hello Balasz, This looks mostly good but I have a question inline. Comment at: lib/AST/ASTImporter.cpp:2715 +if (auto *ToFT = dyn_cast(Importer.Import(FromFT))) + ToFunction->setDescribedFunctionTemplate(ToFT); +else The function template should be already set after `getDescribedFunctionTemplate()` is imported in `VisitFunctionTemplateDecl()`. Are there still cases not covered by this? Repository: rC Clang https://reviews.llvm.org/D49235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49235: [ASTImporter] Import described template (if any) of function.
balazske created this revision. Herald added subscribers: cfe-commits, martong. Herald added a reviewer: a.sidorin. When a function is imported, check if it has a described template. The name lookup is corrected to find the templated entity in this case. The described template of the function is imported too. Repository: rC Clang https://reviews.llvm.org/D49235 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1125,7 +1125,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2499,6 +2499,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2525,6 +2526,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2700,6 +2709,14 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) { +if (auto *ToFT = dyn_cast(Importer.Import(FromFT))) + ToFunction->setDescribedFunctionTemplate(ToFT); +else + return nullptr; + } + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1125,7 +1125,7 @@ } TEST_P(ASTImporterTestBase, - DISABLED_ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { + ImportOfTemplatedDeclShouldImportTheFunctionTemplateDecl) { Decl *FromTU = getTuDecl("template void f(){}", Lang_CXX); auto FromFT = FirstDeclMatcher().match( FromTU, functionTemplateDecl()); Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2499,6 +2499,7 @@ return ToD; const FunctionDecl *FoundByLookup = nullptr; + FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); // If this is a function template specialization, then try to find the same // existing specialization in the "to" context. The localUncachedLookup @@ -2525,6 +2526,14 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; + // If template was found, look at the templated function. + if (FromFT) { +if (auto *Template = dyn_cast(FoundDecl)) + FoundDecl = Template->getTemplatedDecl(); +else + continue; + } + if (auto *FoundFunction = dyn_cast(FoundDecl)) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -2700,6 +2709,14 @@ ToFunction->setType(T); } + // Import the describing template function, if any. + if (FromFT) { +if (auto *ToFT = dyn_cast(Importer.Import(FromFT))) + ToFunction->setDescribedFunctionTemplate(ToFT); +else + return nullptr; + } + if (D->doesThisDeclarationHaveABody()) { if (Stmt *FromBody = D->getBody()) { if (Stmt *ToBody = Importer.Import(FromBody)) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits