https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74919
>From e4e981ed4f545f3dd4cc709bab30468a8ceb3962 Mon Sep 17 00:00:00 2001 From: huqizhi <huqi...@feysh.com> Date: Sat, 9 Dec 2023 12:00:02 +0800 Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl --- clang/lib/AST/ASTImporter.cpp | 16 ++++--- clang/lib/AST/ASTStructuralEquivalence.cpp | 16 +++++++ clang/unittests/AST/ASTImporterTest.cpp | 50 ++++++++++++++++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..40e5ac6ecb13e4 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2771,9 +2771,12 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { for (auto *FoundDecl : FoundDecls) { if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; - if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) - return Importer.MapImported(D, FoundAlias); - ConflictingDecls.push_back(FoundDecl); + if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) { + // if (IsStructuralMatch(D,FoundAlias)) + return Importer.MapImported(D, FoundAlias); + + ConflictingDecls.push_back(FoundDecl); + } } if (!ConflictingDecls.empty()) { @@ -9073,7 +9076,6 @@ class AttrImporter { ToAttr = FromAttr->clone(Importer.getToContext()); ToAttr->setRange(ToRange); - ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName())); } // Get the result of the previous import attempt (can be used only once). @@ -9223,6 +9225,11 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { AI.castAttrAs<CountedByAttr>()->setCountedByFieldLoc(SR.get()); break; } + case attr::AlignValue:{ + auto *From = cast<AlignValueAttr>(FromAttr); + AI.importAttr(From,AI.importArg(From->getAlignment()).value()); + break; + } default: { // The default branch works for attributes that have no arguments to import. @@ -9391,7 +9398,6 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) { setImportDeclError(FromD, *Error); return make_error<ASTImportError>(*Error); } - // Make sure that ImportImpl registered the imported decl. assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); if (auto Error = ImportAttrs(ToD, FromD)) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 6bb4bf14b873d7..5d6c3f35e50832 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -1977,6 +1977,22 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, D2->getTemplatedDecl()->getType()); } +// static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, +// TypeAliasTemplateDecl *D1, +// TypeAliasTemplateDecl *D2) { +// if (!IsStructurallyEquivalent(Context, D1->getDeclName(), D2->getDeclName())) +// return false; + +// // Check the templated declaration. +// if (!IsStructurallyEquivalent(Context, D1->getTemplatedDecl(), +// D2->getTemplatedDecl())) +// return false; + +// // Check template parameters. +// return IsStructurallyEquivalent(Context, D1->getTemplateParameters(), +// D2->getTemplateParameters()); +// } + static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, ConceptDecl *D1, ConceptDecl *D2) { diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..454a4d42d77520 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,56 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +// TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl) { +// const char *Code = +// R"( +// struct S; +// template <typename> +// using Callable = S; +// template <typename Callable> +// int bindingFunctionVTable; +// )"; +// Decl *FromTU = getTuDecl(Code, Lang_CXX17); + +// auto *FromCallable1 = FirstDeclMatcher<TypeAliasTemplateDecl>().match( +// FromTU, typeAliasTemplateDecl(hasName("Callable"))); + +// auto *FromCallable2 = FirstDeclMatcher<TemplateTypeParmDecl>().match( +// FromTU, templateTypeParmDecl(hasName("Callable"))); + +// auto *ToCallable2 = Import(FromCallable2, Lang_CXX17); +// auto *ToCallable1 = Import(FromCallable1, Lang_CXX17); +// EXPECT_TRUE(ToCallable1); +// EXPECT_TRUE(ToCallable2); +// } + +// TEST_P(ASTImporterOptionSpecificTestBase, X) { +// const char *CodeFrom1 = +// R"( +// template <typename> +// bool A = A<int>; +// )"; +// const char *CodeFrom2 = +// R"( +// template <typename> +// bool A = A<int>; +// )"; +// Decl *From1TU = getTuDecl(CodeFrom1, Lang_CXX17, "input1.cc"); +// Decl *ToTuDecl = getToTuDecl(CodeFrom2, Lang_CXX17); + +// auto *From1A = FirstDeclMatcher<VarTemplateSpecializationDecl>().match( +// From1TU, varTemplateSpecializationDecl(hasName("A"))); + +// // auto *From2A = FirstDeclMatcher<VarTemplateSpecializationDecl>().match( +// // From2TU, varTemplateSpecializationDecl(hasName("A"))); + +// auto *ToA = Import(From1A, Lang_CXX17); +// // auto *ToCallable1 = Import(FromCallable1, Lang_CXX17); +// EXPECT_TRUE(ToA); +// // ToA = Import(From2A, Lang_CXX17); +// // EXPECT_TRUE(ToA); +// } + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits