https://github.com/danix800 created https://github.com/llvm/llvm-project/pull/101517
This fixes infinite recursion crash on return with UnaryTransformType, whose underlying type is a SubstTemplateTypeParmType which is associated with current imported function. >From 3b787c88dafc287b9a5a7aea2afba6c3fc6dead1 Mon Sep 17 00:00:00 2001 From: dingfei <fd...@feysh.com> Date: Fri, 2 Aug 2024 00:46:57 +0800 Subject: [PATCH] [clang][ASTImporter] support import return with UnaryTransformType This fixes infinite recursion crash on return with UnaryTransformType, whose underlying type is a SubstTemplateTypeParmType which is associated with current imported function. --- clang/lib/AST/ASTImporter.cpp | 4 ++++ clang/unittests/AST/ASTImporterTest.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits