Skip to content

Avoid infinite recursion in GetBitSize/GetBitAlign #3089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

adrian-prantl
Copy link

rdar://79874370

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
@adrian-prantl
Copy link
Author

@swift-ci test

struct SwiftType : public Type {
/// Avoid a potential infinite recursion because
/// Type::GetByteSize() may call into this function again.
llvm::Optional<uint64_t> GetStaticByteSize() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding this function directly to Type?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it in this odd way is to minimize the diff between swift-lldb and llvm.org lldb.

@@ -3179,9 +3193,10 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
// alignment information out of DWARF. Because it is stored in the
// Type object we need to look that up by name again.
if (TypeSP type_sp = LookupTypeInModule(type))
return type_sp->GetLayoutCompilerType().GetTypeBitAlign(exe_scope);
if (type_sp->GetLayoutCompilerType().GetOpaqueQualType() != type)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: a comment saying when/why this inequality happens.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's again to avoid an infinite recursion. I'll add a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants