From 1e36c9373295b39f14e7fe90ff3b49dd3fccc9d2 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 24 Apr 2025 12:26:12 -0700 Subject: [PATCH 1/2] [lldb] Diagnose a fallback warning for type aliases --- .../Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp | 5 +++++ .../Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp index 24fbb01a1b97e..b3694968ccad2 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp @@ -3309,6 +3309,11 @@ SwiftLanguageRuntime::GetSwiftRuntimeTypeInfo( // Resolve all type aliases. type = type.GetCanonicalType(); + if (!type) + // FIXME: We could print a better error message if + // GetCanonicalType() returned an Expected. + return llvm::createStringError( + "could not get canonical type (possibly due to unresolved typealias)"); // Resolve all generic type parameters in the type for the current // frame. Generic parameter binding has to happen in the scratch diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index 8649156be370e..385fbc2e774ef 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -3383,7 +3383,11 @@ TypeSystemSwiftTypeRef::GetCanonicalType(opaque_compiler_type_t type) { // then we don't have debug info to resolve it from. CompilerType ast_type = ReconstructType({weak_from_this(), type}, nullptr).GetCanonicalType(); - return GetTypeFromMangledTypename(ast_type.GetMangledTypeName()); + CompilerType result = + GetTypeFromMangledTypename(ast_type.GetMangledTypeName()); + if (result && !llvm::isa(this)) + DiagnoseSwiftASTContextFallback(__FUNCTION__, type); + return result; } auto flavor = SwiftLanguageRuntime::GetManglingFlavor(AsMangledName(type)); auto mangling = mangleNode(canonical, flavor); From 708b410c4c596974e3ee99eb636ebd5b66ebacfa Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 24 Apr 2025 16:40:07 -0700 Subject: [PATCH 2/2] Update lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp Co-authored-by: Jonas Devlieghere --- .../Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp index b3694968ccad2..c2abd19cb8e9e 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp @@ -3309,11 +3309,12 @@ SwiftLanguageRuntime::GetSwiftRuntimeTypeInfo( // Resolve all type aliases. type = type.GetCanonicalType(); - if (!type) + if (!type) { // FIXME: We could print a better error message if // GetCanonicalType() returned an Expected. return llvm::createStringError( "could not get canonical type (possibly due to unresolved typealias)"); +} // Resolve all generic type parameters in the type for the current // frame. Generic parameter binding has to happen in the scratch