@@ -1033,6 +1033,30 @@ DWARFASTParser *TypeSystemSwiftTypeRef::GetDWARFParser() {
1033
1033
return m_swift_ast_context->GetDWARFParser ();
1034
1034
}
1035
1035
1036
+ TypeSP TypeSystemSwiftTypeRef::LookupTypeInModule (
1037
+ lldb::opaque_compiler_type_t opaque_type) {
1038
+ auto *M = GetModule ();
1039
+ if (!M)
1040
+ return {};
1041
+ swift::Demangle::Demangler dem;
1042
+ auto *node = GetDemangledType (dem, AsMangledName (opaque_type));
1043
+ auto module_type = GetNominal (dem, node);
1044
+ if (!module_type)
1045
+ return {};
1046
+ // DW_AT_linkage_name is not part of the accelerator table, so
1047
+ // we need to search by module+name.
1048
+ ConstString module (module_type->first );
1049
+ ConstString type (module_type->second );
1050
+ llvm::SmallVector<CompilerContext, 2 > decl_context;
1051
+ decl_context.push_back ({CompilerContextKind::Module, module });
1052
+ decl_context.push_back ({CompilerContextKind::AnyType, type});
1053
+ llvm::DenseSet<SymbolFile *> searched_symbol_files;
1054
+ TypeMap types;
1055
+ M->FindTypes (decl_context, TypeSystemSwift::GetSupportedLanguagesForTypes (),
1056
+ searched_symbol_files, types);
1057
+ return types.Empty () ? TypeSP () : types.GetTypeAtIndex (0 );
1058
+ }
1059
+
1036
1060
// Tests
1037
1061
1038
1062
#ifndef NDEBUG
@@ -1681,27 +1705,8 @@ TypeSystemSwiftTypeRef::GetBitSize(opaque_compiler_type_t type,
1681
1705
// If there is no process, we can still try to get the static size
1682
1706
// information out of DWARF. Because it is stored in the Type
1683
1707
// object we need to look that up by name again.
1684
- if (auto *M = GetModule ()) {
1685
- swift::Demangle::Demangler dem;
1686
- auto node = GetDemangledType (dem, AsMangledName (type));
1687
- if (auto module_type = GetNominal (dem, node)) {
1688
- // DW_AT_linkage_name is not part of the accelerator table, so
1689
- // we need to search by module+name.
1690
- ConstString module (module_type->first );
1691
- ConstString type (module_type->second );
1692
- llvm::SmallVector<CompilerContext, 2 > decl_context;
1693
- decl_context.push_back ({CompilerContextKind::Module, module });
1694
- decl_context.push_back ({CompilerContextKind::AnyType, type});
1695
- llvm::DenseSet<SymbolFile *> searched_symbol_files;
1696
- TypeMap types;
1697
- M->FindTypes (decl_context,
1698
- TypeSystemSwift::GetSupportedLanguagesForTypes (),
1699
- searched_symbol_files, types);
1700
- if (!types.Empty ())
1701
- if (auto type = types.GetTypeAtIndex (0 ))
1702
- return type->GetByteSize (nullptr );
1703
- }
1704
- }
1708
+ if (TypeSP type_sp = LookupTypeInModule (type))
1709
+ return type_sp->GetByteSize (exe_scope);
1705
1710
LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
1706
1711
" Couldn't compute size of type %s without a process." ,
1707
1712
AsMangledName (type));
@@ -1956,7 +1961,41 @@ bool TypeSystemSwiftTypeRef::IsPointerOrReferenceType(
1956
1961
llvm::Optional<size_t >
1957
1962
TypeSystemSwiftTypeRef::GetTypeBitAlign (opaque_compiler_type_t type,
1958
1963
ExecutionContextScope *exe_scope) {
1959
- return m_swift_ast_context->GetTypeBitAlign (ReconstructType (type), exe_scope);
1964
+ auto impl = [&]() -> llvm::Optional<size_t > {
1965
+ // Clang types can be resolved even without a process.
1966
+ if (CompilerType clang_type = GetAsClangTypeOrNull (type)) {
1967
+ // Swift doesn't know pointers: return the size alignment of the
1968
+ // object pointer instead of the underlying object.
1969
+ if (Flags (clang_type.GetTypeInfo ()).AllSet (eTypeIsObjC | eTypeIsClass))
1970
+ return GetPointerByteSize () * 8 ;
1971
+ return clang_type.GetTypeBitAlign (exe_scope);
1972
+ }
1973
+ if (!exe_scope) {
1974
+ LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
1975
+ " Couldn't compute alignment of type %s without an execution "
1976
+ " context." ,
1977
+ AsMangledName (type));
1978
+ return {};
1979
+ }
1980
+ if (auto *runtime =
1981
+ SwiftLanguageRuntime::Get (exe_scope->CalculateProcess ()))
1982
+ return runtime->GetBitAlignment ({this , type}, exe_scope);
1983
+
1984
+ // If there is no process, we can still try to get the static
1985
+ // alignment information out of DWARF. Because it is stored in the
1986
+ // Type object we need to look that up by name again.
1987
+ if (TypeSP type_sp = LookupTypeInModule (type))
1988
+ return type_sp->GetLayoutCompilerType ().GetTypeBitAlign (exe_scope);
1989
+ LLDB_LOGF (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES),
1990
+ " Couldn't compute alignment of type %s without a process." ,
1991
+ AsMangledName (type));
1992
+ return {};
1993
+ };
1994
+ if (exe_scope && exe_scope->CalculateProcess ())
1995
+ VALIDATE_AND_RETURN (impl, GetTypeBitAlign, type,
1996
+ (ReconstructType (type), exe_scope));
1997
+ else
1998
+ return impl ();
1960
1999
}
1961
2000
bool TypeSystemSwiftTypeRef::IsTypedefType (opaque_compiler_type_t type) {
1962
2001
return m_swift_ast_context->IsTypedefType (ReconstructType (type));
0 commit comments