Skip to content

Commit a58f20b

Browse files
authored
[clang][ASTImporter] support import return with UnaryTransformType (#101517)
This fixes infinite recursion crash on return with UnaryTransformType, whose underlying type is a SubstTemplateTypeParmType which is associated with current imported function.
1 parent 5518b46 commit a58f20b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,10 @@ class IsTypeDeclaredInsideVisitor
36403640
return {};
36413641
}
36423642

3643+
std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3644+
return CheckType(T->getBaseType());
3645+
}
3646+
36433647
std::optional<bool>
36443648
VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
36453649
// The "associated declaration" can be the same as ParentDC.

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7598,6 +7598,25 @@ TEST_P(ImportAutoFunctions, ReturnWithSubstNonTypeTemplateParmExpr) {
75987598
EXPECT_TRUE(ToBar);
75997599
}
76007600

7601+
TEST_P(ImportAutoFunctions, ReturnWithUnaryTransformType) {
7602+
const char *Code =
7603+
R"(
7604+
enum E { E1 };
7605+
7606+
template<typename T>
7607+
auto foo(T v) { return static_cast<__underlying_type(T)>(v); }
7608+
7609+
bool bar() { return foo(E1); }
7610+
)";
7611+
Decl *FromTU = getTuDecl(Code, Lang_CXX17);
7612+
7613+
auto *FromBar = FirstDeclMatcher<FunctionDecl>().match(
7614+
FromTU, functionDecl(hasName("bar")));
7615+
7616+
auto *ToBar = Import(FromBar, Lang_CXX17);
7617+
EXPECT_TRUE(ToBar);
7618+
}
7619+
76017620
struct ImportSourceLocations : ASTImporterOptionSpecificTestBase {};
76027621

76037622
TEST_P(ImportSourceLocations, PreserveFileIDTreeStructure) {

0 commit comments

Comments
 (0)