Skip to content

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