Skip to content

Commit 802f0bd

Browse files
authored
Merge pull request #22674 from compnerd/UB-is-your-friend
runtime: correct signature for `swift_swiftValueConformsTo`
2 parents 4ef2538 + 3ec6e12 commit 802f0bd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static bool _dynamicCastFromAnyHashable(OpaqueValue *destination,
677677

678678
#if !SWIFT_OBJC_INTEROP // __SwiftValue is a native class
679679
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
680-
bool swift_swiftValueConformsTo(const Metadata *destinationType);
680+
bool swift_swiftValueConformsTo(const Metadata *, const Metadata *);
681681

682682
#define _bridgeAnythingToObjectiveC \
683683
MANGLE_SYM(s27_bridgeAnythingToObjectiveCyyXlxlF)
@@ -780,14 +780,16 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
780780
return true;
781781
}
782782
#else // !SWIFT_OBJC_INTEROP -- __SwiftValue is a native class
783-
bool isMetatype = kind == MetadataKind::ExistentialMetatype || kind == MetadataKind::Metatype;
784-
if (!isMetatype && (isTargetTypeAnyObject || swift_swiftValueConformsTo(targetType))) {
785-
auto object = _bridgeAnythingToObjectiveC(src, srcType);
786-
swift_retain(object);
787-
destExistential->Value = object;
788-
maybeDeallocateSource(true);
789-
return true;
790-
}
783+
bool isMetatype = kind == MetadataKind::ExistentialMetatype ||
784+
kind == MetadataKind::Metatype;
785+
if (!isMetatype && (isTargetTypeAnyObject ||
786+
swift_swiftValueConformsTo(targetType, targetType))) {
787+
auto object = _bridgeAnythingToObjectiveC(src, srcType);
788+
swift_retain(object);
789+
destExistential->Value = object;
790+
maybeDeallocateSource(true);
791+
return true;
792+
}
791793
#endif
792794

793795
return _fail(src, srcType, targetType, flags);

0 commit comments

Comments
 (0)