[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)
Qizhi Hu via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 8 23:14:30 PST 2023
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/74919
Skip checking `TemplateTypeParmDecl ` in `VisitTypeAliasTemplateDecl`. [Fix this crash](https://github.com/llvm/llvm-project/issues/74765)
>From b3c28d66efb98dff8b8f879bda92341bf62f45d3 Mon Sep 17 00:00:00 2001
From: huqizhi <huqizhi at feysh.com>
Date: Sat, 9 Dec 2023 12:00:02 +0800
Subject: [PATCH] [clang][ASTImporter] skip TemplateTypeParmDecl in
VisitTypeAliasTemplateDecl
---
clang/lib/AST/ASTImporter.cpp | 3 ++-
clang/unittests/AST/ASTImporterTest.cpp | 23 +++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a4..bfe9af648e603b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2769,7 +2769,8 @@ ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
unsigned IDNS = Decl::IDNS_Ordinary;
auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
for (auto *FoundDecl : FoundDecls) {
- if (!FoundDecl->isInIdentifierNamespace(IDNS))
+ if (!FoundDecl->isInIdentifierNamespace(IDNS) ||
+ isa_and_nonnull<TemplateTypeParmDecl>(FoundDecl))
continue;
if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl))
return Importer.MapImported(D, FoundAlias);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf8..6f9aba2c867eea 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9284,6 +9284,29 @@ TEST_P(ASTImporterOptionSpecificTestBase,
// EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1);
}
+TEST_P(ASTImporterOptionSpecificTestBase, XXX) {
+ 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);
+}
+
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
DefaultTestValuesForRunOptions);
More information about the cfe-commits
mailing list