Skip to content

Commit 81e923a

Browse files
Merge pull request #3093 from adrian-prantl/79874370-next
Avoid infinite recursion in GetBitSize/GetBitAlign.
2 parents ac9454a + 64e13c8 commit 81e923a

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
@@ -2169,18 +2169,32 @@ TypeSystemSwiftTypeRef::GetBitSize(opaque_compiler_type_t type,
21692169
// info for it, so defer to SwiftASTContext.
21702170
if (llvm::isa<SwiftASTContextForExpressions>(m_swift_ast_context))
21712171
return ReconstructType({this, type}).GetBitSize(exe_scope);
2172+
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2173+
"Couldn't compute size of type %s using SwiftLanguageRuntime.",
2174+
AsMangledName(type));
2175+
return {};
21722176
}
21732177

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

0 commit comments

Comments
 (0)