diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp index 754c6a13b9e7a..7321f7662746a 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp @@ -550,6 +550,8 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp, auto *stack_frame = stack_frame_sp.get(); imported_self_type = swift_runtime->BindGenericTypeParameters( *stack_frame, imported_self_type); + if (!imported_self_type) + return; { auto *swift_type_system = llvm::dyn_cast_or_null( @@ -561,6 +563,8 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp, // extend the referent: imported_self_type = swift_type_system->GetReferentType( imported_self_type.GetOpaqueQualType()); + if (!imported_self_type) + return; } { @@ -573,6 +577,8 @@ static void AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp, // and we have to grab the instance type: imported_self_type = swift_type_system->GetInstanceType( imported_self_type.GetOpaqueQualType()); + if (!imported_self_type) + return; } Flags imported_self_type_flags(imported_self_type.GetTypeInfo()); diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index e102828da5b68..1032d2aec772a 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -2176,12 +2176,12 @@ CompilerType TypeSystemSwiftTypeRef::GetFieldAtIndex( static swift::Demangle::NodePointer GetClangTypeTypeNode(TypeSystemSwiftTypeRef &ts, swift::Demangle::Demangler &dem, CompilerType clang_type, - SwiftASTContext *swift_ast_context) { + SwiftASTContext *module_holder) { assert(llvm::isa(clang_type.GetTypeSystem()) && "expected a clang type"); using namespace swift::Demangle; NodePointer type = dem.createNode(Node::Kind::Type); - type->addChild(GetClangTypeNode(clang_type, dem, swift_ast_context), dem); + type->addChild(GetClangTypeNode(clang_type, dem, module_holder), dem); return type; } @@ -2342,20 +2342,19 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex( llvm::StringRef suffix(ast_child_name); if (suffix.consume_front("__ObjC.")) ast_child_name = suffix.str(); + assert((llvm::StringRef(child_name).contains('.') || + Equivalent(child_name, ast_child_name))); + assert((Equivalent(llvm::Optional(child_byte_size), + llvm::Optional(ast_child_byte_size)) || + ast_language_flags)); + assert(Equivalent(llvm::Optional(child_byte_offset), + llvm::Optional(ast_child_byte_offset))); assert( - (llvm::StringRef(child_name).contains('.') || - Equivalent(child_name, ast_child_name)) && - (Equivalent(llvm::Optional(child_byte_size), - llvm::Optional(ast_child_byte_size)) || - ast_language_flags) && - Equivalent(llvm::Optional(child_byte_offset), - llvm::Optional(ast_child_byte_offset)) && - Equivalent(child_bitfield_bit_offset, ast_child_bitfield_bit_offset) && - Equivalent(child_bitfield_bit_size, ast_child_bitfield_bit_size) && - Equivalent(child_is_base_class, ast_child_is_base_class) && - Equivalent(child_is_deref_of_parent, ast_child_is_deref_of_parent) && - Equivalent(language_flags, ast_language_flags) && - "TypeSystemSwiftTypeRef diverges from SwiftASTContext"); + Equivalent(child_bitfield_bit_offset, ast_child_bitfield_bit_offset)); + assert(Equivalent(child_bitfield_bit_size, ast_child_bitfield_bit_size)); + assert(Equivalent(child_is_base_class, ast_child_is_base_class)); + assert(Equivalent(child_is_deref_of_parent, ast_child_is_deref_of_parent)); + assert(Equivalent(language_flags, ast_language_flags)); }); #endif VALIDATE_AND_RETURN( diff --git a/lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp b/lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp index a8c8028df6fec..c278a17546abe 100644 --- a/lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp +++ b/lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp @@ -1485,6 +1485,11 @@ bool SwiftLanguageRuntimeImpl::ForEachSuperClassType( auto *reflection_ctx = GetReflectionContext(); if (!reflection_ctx) return false; + CompilerType instance_type = instance.GetCompilerType(); + auto *ts = + llvm::dyn_cast_or_null(instance_type.GetTypeSystem()); + if (!ts) + return false; lldb::addr_t pointer = instance.GetPointerValue(); // Maybe this belongs into GetPointerValue, but on the other hand it @@ -1494,7 +1499,7 @@ bool SwiftLanguageRuntimeImpl::ForEachSuperClassType( // libReflection cannot tell up how many bits to strip from // multi-payload enum values. auto addr_deref = - FixupPointerValue(pointer, instance.GetCompilerType()); + FixupPointerValue(pointer, instance_type); pointer = addr_deref.first; if (addr_deref.second) { // This is a reference storage object. @@ -1504,11 +1509,6 @@ bool SwiftLanguageRuntimeImpl::ForEachSuperClassType( return false; } - auto *ts = llvm::dyn_cast_or_null( - instance.GetCompilerType().GetTypeSystem()); - if (!ts) - return false; - auto md_ptr = reflection_ctx->readMetadataFromInstance(pointer); if (!md_ptr) return false;