Skip to content

Commit

Permalink
runtime: correct signature for swift_swiftValueConformsTo
Browse files Browse the repository at this point in the history
The swift side signature for `swift_swiftValueConformsTo` is:
`func swift_swiftValueConformsTo<T>(_: T.self) -> Bool`

This translates to:
`bool swift_swiftValueConformsTo(const Metadata *, const Metadata *)`

The elided parameter would be passed invalid values..  Running this on
Windows with optimizations triggered an optimization where the parameter
happened to be null as `rdx` is the second parameter rather than the 4th
parameter.
  • Loading branch information
compnerd committed Feb 17, 2019
1 parent 0fe7e14 commit 3ec6e12
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions stdlib/public/runtime/Casting.cpp
Expand Up @@ -677,7 +677,7 @@ static bool _dynamicCastFromAnyHashable(OpaqueValue *destination,

#if !SWIFT_OBJC_INTEROP // __SwiftValue is a native class
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
bool swift_swiftValueConformsTo(const Metadata *destinationType);
bool swift_swiftValueConformsTo(const Metadata *, const Metadata *);

#define _bridgeAnythingToObjectiveC \
MANGLE_SYM(s27_bridgeAnythingToObjectiveCyyXlxlF)
Expand Down Expand Up @@ -780,14 +780,16 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
return true;
}
#else // !SWIFT_OBJC_INTEROP -- __SwiftValue is a native class
bool isMetatype = kind == MetadataKind::ExistentialMetatype || kind == MetadataKind::Metatype;
if (!isMetatype && (isTargetTypeAnyObject || swift_swiftValueConformsTo(targetType))) {
auto object = _bridgeAnythingToObjectiveC(src, srcType);
swift_retain(object);
destExistential->Value = object;
maybeDeallocateSource(true);
return true;
}
bool isMetatype = kind == MetadataKind::ExistentialMetatype ||
kind == MetadataKind::Metatype;
if (!isMetatype && (isTargetTypeAnyObject ||
swift_swiftValueConformsTo(targetType, targetType))) {
auto object = _bridgeAnythingToObjectiveC(src, srcType);
swift_retain(object);
destExistential->Value = object;
maybeDeallocateSource(true);
return true;
}
#endif

return _fail(src, srcType, targetType, flags);
Expand Down

0 comments on commit 3ec6e12

Please sign in to comment.