Skip to content

Commit b8f1876

Browse files
authored
RemoteInspection: Handle ObjC typerefs in computeUnalignedFieldStartOffset (#76678)
This change is part of a fix for a regression that wasn't noticed because lldb has a fallback to using ASTContexts when type metadata resolution fails. For any Swift class that directly or indirectly inherits from an ObjC class (such as `NSObject`, `NSView`, etc), the function `computeUnalignedFieldStartOffset` will fail to compute the start offset. To compute the start offset, it traverses the parent classes and uses their sizes. Once the traversal reaches an ObjC class, the RemoteInspection does not know the size. The fix here is to get the size from the `TypeInfo` returned by the external `TypeInfoProvider` (which in LLDB is `LLDBTypeInforProvider`). Depended on by swiftlang/llvm-project#9320
1 parent 79b0a7c commit b8f1876

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,12 @@ class ReflectionContext
12871287
// after the isa and retain fields.
12881288
return isaAndRetainCountSize;
12891289

1290+
// `ObjCClassTypeRef` instances represent classes in the ObjC module ("__C").
1291+
// These will never have Swift type metadata.
1292+
if (auto *objcSuper = dyn_cast<ObjCClassTypeRef>(superclass))
1293+
if (auto *superTI = ExternalTypeInfo->getTypeInfo(objcSuper->getName()))
1294+
return superTI->getSize();
1295+
12901296
auto superclassStart =
12911297
computeUnalignedFieldStartOffset(superclass, ExternalTypeInfo);
12921298
if (!superclassStart)

0 commit comments

Comments
 (0)