Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee591a9

Browse files
authored
Merge pull request swiftlang#7023 from augusto2112/stop-reconstruct-typeref-disabled
[lldb] Fix infinite recursion in ReconstructType
2 parents 5b9984c + b1aecf3 commit ee591a9

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

+32-26
Original file line numberDiff line numberDiff line change
@@ -3970,33 +3970,39 @@ swift::TypeBase *SwiftASTContext::ReconstructType(ConstString mangled_typename,
39703970
.getPointer();
39713971
assert(!found_type || &found_type->getASTContext() == ast_ctx);
39723972

3973-
// Objective-C classes sometimes have private subclasses that are invisible to
3974-
// the Swift compiler because they are declared and defined in a .m file. If
3975-
// we can't reconstruct an ObjC type, walk up the type hierarchy until we find
3976-
// something we can import, or until we run out of types
3977-
while (!found_type) {
3978-
CompilerType clang_type = GetAsClangType(mangled_typename);
3979-
if (!clang_type)
3980-
break;
3973+
// If the typeref type system is disabled GetAsClangType will eventually call
3974+
// ReconstructType again, eventually leading to a stack overflow.
3975+
if (ModuleList::GetGlobalModuleListProperties()
3976+
.GetUseSwiftTypeRefTypeSystem()) {
3977+
// Objective-C classes sometimes have private subclasses that are invisible
3978+
// to the Swift compiler because they are declared and defined in a .m file.
3979+
// If we can't reconstruct an ObjC type, walk up the type hierarchy until we
3980+
// find something we can import, or until we run out of types
3981+
while (!found_type) {
3982+
CompilerType clang_type = GetAsClangType(mangled_typename);
3983+
if (!clang_type)
3984+
break;
39813985

3982-
auto clang_ctx =
3983-
clang_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
3984-
if (!clang_ctx)
3985-
break;
3986-
auto *interface_decl = TypeSystemClang::GetAsObjCInterfaceDecl(clang_type);
3987-
if (!interface_decl)
3988-
break;
3989-
auto *super_interface_decl = interface_decl->getSuperClass();
3990-
if (!super_interface_decl)
3991-
break;
3992-
CompilerType super_type = clang_ctx->GetTypeForDecl(super_interface_decl);
3993-
if (!super_type)
3994-
break;
3995-
auto super_mangled_typename = super_type.GetMangledTypeName();
3996-
found_type = swift::Demangle::getTypeForMangling(
3997-
*ast_ctx, super_mangled_typename.GetStringRef())
3998-
.getPointer();
3999-
assert(!found_type || &found_type->getASTContext() == ast_ctx);
3986+
auto clang_ctx =
3987+
clang_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
3988+
if (!clang_ctx)
3989+
break;
3990+
auto *interface_decl =
3991+
TypeSystemClang::GetAsObjCInterfaceDecl(clang_type);
3992+
if (!interface_decl)
3993+
break;
3994+
auto *super_interface_decl = interface_decl->getSuperClass();
3995+
if (!super_interface_decl)
3996+
break;
3997+
CompilerType super_type = clang_ctx->GetTypeForDecl(super_interface_decl);
3998+
if (!super_type)
3999+
break;
4000+
auto super_mangled_typename = super_type.GetMangledTypeName();
4001+
found_type = swift::Demangle::getTypeForMangling(
4002+
*ast_ctx, super_mangled_typename.GetStringRef())
4003+
.getPointer();
4004+
assert(!found_type || &found_type->getASTContext() == ast_ctx);
4005+
}
40004006
}
40014007

40024008
if (found_type) {

0 commit comments

Comments
 (0)