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