8000 [lldb] Avoid mangling empty opaque types by kastiglione · Pull Request #10947 · swiftlang/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[lldb] Avoid mangling empty opaque types #10947

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

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from

Conversation

kastiglione
Copy link
@kastiglione kastiglione commented Jul 2, 2025

Update TypeSystemSwiftTypeRef::RemangleAsType to handle empty opaque types. Without this change, assertions will occur when running unit tests with an asserts-build of lldb.

An example of where this happens is Builtin.RawPointer ($sBpD). For values with that type, the typeref is:

(swift::reflection::OpaqueTypeRef *) typeref = 0x000060000309c000 {
  swift::reflection::TypeRef = {
    Kind = Opaque
  }
}

When demangling the above typeref, the resulting demangle tree is an empty OpaqueType:

(swift::Demangle::NodePointer) node = 0x0000000105240420 Type, 1 child {
  NodeKind = Type
  [0] = 0x0000000105240408 OpaqueType, 0 children {
    NodeKind = OpaqueType
  }
}

In Swift's Remangler::mangleOpaqueType, it's expected that the opaque type have 3 children:

DEMANGLER_ASSERT(node->getNumChildren() >= 3, node);

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as ready for review July 2, 2025 22:16
@kastiglione kastiglione requested a review from a team as a code owner July 2, 2025 22:16
@kastiglione kastiglione requested a review from adrian-prantl July 2, 2025 22:17
@kastiglione
Copy link
Author
kastiglione commented Jul 2, 2025

A possible alternative to this is to update Remangler::mangleOpaqueType to accept opaque nodes with no children, but I'm not sure whether that's a valid change to make, or not.

@kastiglione
Copy link
Author

@swift-ci test macOS

1 similar comment
@kastiglione
Copy link
Author

@swift-ci test macOS

@adrian-prantl
Copy link

This patch seems fine for avoiding the crash, but: Is there a bug in the remangler that makes it impossible to round-trip $sBpD? If yes, would it be better to fix that instead?

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
0