Skip to content

Commit 2f2d448

Browse files
committed
Runtime: add an explicit cast; NFC
This adds an explicit cast of the atomic type to the contained type prior to comparing it to nullptr. This is generally unnecessary, however, the Windows C++ library (msvcprt) from Visual Studio 2014 (WinSDK 10.0.10586.0) has extensions which makes the conversion ambiguous. Simply cast the value on all targets. In order to reduce the duplication of the type, create a local typedef for the constant runtime-uniqued metadata pointer type.
1 parent c404785 commit 2f2d448

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,8 @@ struct TargetForeignTypeMetadata : public TargetMetadata<Runtime> {
18161816
using StoredSize = typename Runtime::StoredSize;
18171817
using InitializationFunction_t =
18181818
void (*)(TargetForeignTypeMetadata<Runtime> *selectedMetadata);
1819+
using RuntimeMetadataPointer =
1820+
ConstTargetMetadataPointer<Runtime, swift::TargetForeignTypeMetadata>;
18191821

18201822
/// Foreign type metadata may have extra header fields depending on
18211823
/// the flags.
@@ -1830,14 +1832,12 @@ struct TargetForeignTypeMetadata : public TargetMetadata<Runtime> {
18301832
/// The Swift-mangled name of the type. This is the uniquing key for the
18311833
/// type.
18321834
TargetPointer<Runtime, const char> Name;
1833-
1835+
18341836
/// A pointer to the actual, runtime-uniqued metadata for this
18351837
/// type. This is essentially an invasive cache for the lookup
18361838
/// structure.
1837-
mutable std::atomic<
1838-
ConstTargetMetadataPointer<Runtime, swift::TargetForeignTypeMetadata>
1839-
> Unique;
1840-
1839+
mutable std::atomic<RuntimeMetadataPointer> Unique;
1840+
18411841
/// Various flags.
18421842
enum : StoredSize {
18431843
/// This metadata has an initialization callback function. If
@@ -1856,9 +1856,8 @@ struct TargetForeignTypeMetadata : public TargetMetadata<Runtime> {
18561856
return reinterpret_cast<TargetPointer<Runtime, const char>>(
18571857
asFullMetadata(this)->Name);
18581858
}
1859-
1860-
ConstTargetMetadataPointer<Runtime, swift::TargetForeignTypeMetadata>
1861-
getCachedUniqueMetadata() const {
1859+
1860+
RuntimeMetadataPointer getCachedUniqueMetadata() const {
18621861
#if __alpha__
18631862
// TODO: This can be a relaxed-order load if there is no initialization
18641863
// function. On platforms we care about, consume is no more expensive than
@@ -1869,15 +1868,13 @@ struct TargetForeignTypeMetadata : public TargetMetadata<Runtime> {
18691868
#endif
18701869
return asFullMetadata(this)->Unique.load(SWIFT_MEMORY_ORDER_CONSUME);
18711870
}
1872-
1873-
void
1874-
setCachedUniqueMetadata(
1875-
ConstTargetMetadataPointer<Runtime, swift::TargetForeignTypeMetadata> unique)
1876-
const {
1877-
assert((asFullMetadata(this)->Unique == nullptr
1878-
|| asFullMetadata(this)->Unique == unique)
1879-
&& "already set unique metadata");
1880-
1871+
1872+
void setCachedUniqueMetadata(RuntimeMetadataPointer unique) const {
1873+
assert((static_cast<RuntimeMetadataPointer>(asFullMetadata(this)->Unique) ==
1874+
nullptr ||
1875+
asFullMetadata(this)->Unique == unique) &&
1876+
"already set unique metadata");
1877+
18811878
// If there is no initialization function, this can be a relaxed store.
18821879
if (!hasInitializationFunction())
18831880
asFullMetadata(this)->Unique.store(unique, std::memory_order_relaxed);

0 commit comments

Comments
 (0)