llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Ding Fei (danix800) <details> <summary>Changes</summary> This fixes infinite recursion crash on return with UnaryTransformType, whose underlying type is a SubstTemplateTypeParmType which is associated with current imported function. --- Full diff: https://github.com/llvm/llvm-project/pull/101517.diff 2 Files Affected: - (modified) clang/lib/AST/ASTImporter.cpp (+4) - (modified) clang/unittests/AST/ASTImporterTest.cpp (+19) ``````````diff diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 103235547f482..157fa40163122 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3636,6 +3636,10 @@ class IsTypeDeclaredInsideVisitor return {}; } + std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) { + return CheckType(T->getBaseType()); + } + std::optional<bool> VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { // The "associated declaration" can be the same as ParentDC. diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 57242ff49fe3b..fd9be92d3792a 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -7581,6 +7581,25 @@ TEST_P(ImportAutoFunctions, ReturnWithSubstNonTypeTemplateParmExpr) { EXPECT_TRUE(ToBar); } +TEST_P(ImportAutoFunctions, ReturnWithUnaryTransformType) { + const char *Code = + R"( + enum E { E1 }; + + template<typename T> + auto foo(T v) { return static_cast<__underlying_type(T)>(v); } + + bool bar() { return foo(E1); } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX17); + + auto *FromBar = FirstDeclMatcher<FunctionDecl>().match( + FromTU, functionDecl(hasName("bar"))); + + auto *ToBar = Import(FromBar, Lang_CXX17); + EXPECT_TRUE(ToBar); +} + struct ImportSourceLocations : ASTImporterOptionSpecificTestBase {}; TEST_P(ImportSourceLocations, PreserveFileIDTreeStructure) { `````````` </details> https://github.com/llvm/llvm-project/pull/101517 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits