Skip to content

Commit 2c98933

Browse files
committed
Avoid infinite recursion in GetBitSize/GetBitAlign.
If the lldb::Type does not have static size info attached to it, Type::GetByteSize() calls back into TypeSystemSwiftTypeRef(), creating an infinite recursion. This patch avoids this by adding an accessor that only returns the static or precomputed byte size without the recursion. rdar://79874370
1 parent 9e9c7b2 commit 2c98933

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,18 +2170,32 @@ TypeSystemSwiftTypeRef::GetBitSize(opaque_compiler_type_t type,
21702170
// info for it, so defer to SwiftASTContext.
21712171
if (llvm::isa<SwiftASTContextForExpressions>(m_swift_ast_context))
21722172
return ReconstructType({this, type}).GetBitSize(exe_scope);
2173+
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2174+
"Couldn't compute size of type %s using SwiftLanguageRuntime.",
2175+
AsMangledName(type));
2176+
return {};
21732177
}
21742178

21752179
// If there is no process, we can still try to get the static size
21762180
// information out of DWARF. Because it is stored in the Type
21772181
// object we need to look that up by name again.
21782182
if (TypeSP type_sp = LookupTypeInModule(type)) {
2179-
if (auto byte_size = type_sp->GetByteSize(exe_scope))
2183+
struct SwiftType : public Type {
2184+
/// Avoid a potential infinite recursion because
2185+
/// Type::GetByteSize() may call into this function again.
2186+
llvm::Optional<uint64_t> GetStaticByteSize() {
2187+
if (m_byte_size_has_value)
2188+
return m_byte_size;
2189+
return {};
2190+
}
2191+
};
2192+
if (auto byte_size =
2193+
reinterpret_cast<SwiftType *>(type_sp.get())->GetStaticByteSize())
21802194
return *byte_size * 8;
21812195
else return {};
21822196
}
21832197
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2184-
"Couldn't compute size of type %s without a process.",
2198+
"Couldn't compute size of type %s using static debug info.",
21852199
AsMangledName(type));
21862200
return {};
21872201
};
@@ -3179,9 +3193,10 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
31793193
// alignment information out of DWARF. Because it is stored in the
31803194
// Type object we need to look that up by name again.
31813195
if (TypeSP type_sp = LookupTypeInModule(type))
3182-
return type_sp->GetLayoutCompilerType().GetTypeBitAlign(exe_scope);
3196+
if (type_sp->GetLayoutCompilerType().GetOpaqueQualType() != type)
3197+
return type_sp->GetLayoutCompilerType().GetTypeBitAlign(exe_scope);
31833198
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
3184-
"Couldn't compute alignment of type %s without a process.",
3199+
"Couldn't compute alignment of type %s using static debug info.",
31853200
AsMangledName(type));
31863201
return {};
31873202
}

0 commit comments

Comments
 (0)