Skip to content

Commit e3df402

Browse files
committed
Runtime: Don't crash when overriding a weak-imported method that's not available
1 parent b6893e6 commit e3df402

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/swift/ABI/Metadata.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,13 +845,15 @@ struct TargetVTableDescriptorHeader {
845845
template <typename Runtime>
846846
struct TargetMethodOverrideDescriptor {
847847
/// The class containing the base method.
848-
TargetRelativeIndirectablePointer<Runtime, TargetClassDescriptor<Runtime>> Class;
848+
TargetRelativeIndirectablePointer<Runtime, TargetClassDescriptor<Runtime>,
849+
/*nullable*/ true> Class;
849850

850851
/// The base method.
851-
TargetRelativeIndirectablePointer<Runtime, TargetMethodDescriptor<Runtime>> Method;
852+
TargetRelativeIndirectablePointer<Runtime, TargetMethodDescriptor<Runtime>,
853+
/*nullable*/ true> Method;
852854

853855
/// The implementation of the override.
854-
TargetRelativeDirectPointer<Runtime, void, /*Nullable=*/true> Impl;
856+
TargetRelativeDirectPointer<Runtime, void, /*nullable*/ true> Impl;
855857
};
856858

857859
/// Header for a class vtable override descriptor. This is a variable-sized

stdlib/public/runtime/Metadata.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,11 @@ static void initClassVTable(ClassMetadata *self) {
23192319
auto *baseClass = descriptor.Class.get();
23202320
auto *baseMethod = descriptor.Method.get();
23212321

2322+
// If the base method is null, it's an unavailable weak-linked
2323+
// symbol.
2324+
if (baseClass == nullptr || baseMethod == nullptr)
2325+
continue;
2326+
23222327
// Calculate the base method's vtable offset from the
23232328
// base method descriptor. The offset will be relative
23242329
// to the base class's vtable start offset.

0 commit comments

Comments
 (0)