Skip to content

Commit 8620bc6

Browse files
authored
Merge pull request #18578 from jckarter/dont-verify-roundtripping-private-types
Runtime: Don't attempt to round-trip mangled names for private types.
2 parents 2f015ce + fb05ede commit 8620bc6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

stdlib/public/runtime/Demangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ swift::_buildDemanglingForContext(const ContextDescriptor *context,
226226
// no richer runtime information available about it (such as an anonymous
227227
// context). Use an unstable mangling to represent the context by its
228228
// pointer identity.
229-
char addressBuf[sizeof(void*) * 2 + 2 + 1];
230-
snprintf(addressBuf, sizeof(addressBuf), "0x%" PRIxPTR, (uintptr_t)component);
229+
char addressBuf[sizeof(void*) * 2 + 1 + 1];
230+
snprintf(addressBuf, sizeof(addressBuf), "$%" PRIxPTR, (uintptr_t)component);
231231

232232
auto anonNode = Dem.createNode(Node::Kind::AnonymousContext);
233233
CharVector addressStr;

stdlib/public/runtime/Metadata.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4196,6 +4196,16 @@ bool Metadata::satisfiesClassConstraint() const {
41964196
}
41974197

41984198
#if !NDEBUG
4199+
static bool referencesAnonymousContext(Demangle::Node *node) {
4200+
if (node->getKind() == Demangle::Node::Kind::AnonymousContext)
4201+
return true;
4202+
for (unsigned i = 0, e = node->getNumChildren(); i < e; ++i)
4203+
if (referencesAnonymousContext(node->getChild(i)))
4204+
return true;
4205+
4206+
return false;
4207+
}
4208+
41994209
void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
42004210
// Enable verification when a special environment variable is set.
42014211
// Some metatypes crash when going through the mangler or demangler. A
@@ -4211,12 +4221,17 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
42114221

42124222
Demangle::Demangler Dem;
42134223
auto node = _swift_buildDemanglingForMetadata(metadata, Dem);
4224+
// If the mangled node involves types in an AnonymousContext, then by design,
4225+
// it cannot be looked up by name.
4226+
if (referencesAnonymousContext(node))
4227+
return;
4228+
42144229
auto mangledName = Demangle::mangleNode(node);
42154230
auto result = _getTypeByMangledName(mangledName,
42164231
[](unsigned, unsigned){ return nullptr; });
42174232
if (metadata != result)
42184233
swift::warning(RuntimeErrorFlagNone,
4219-
"Metadata mangled name failed to roundtrip: %p -> %s -> %p",
4234+
"Metadata mangled name failed to roundtrip: %p -> %s -> %p\n",
42204235
metadata, mangledName.c_str(), (const Metadata *)result);
42214236
}
42224237
#endif

0 commit comments

Comments
 (0)