@@ -3037,11 +3037,26 @@ static inline ClassROData *getROData(ClassMetadata *theClass) {
3037
3037
return (ClassROData*)(theClass->Data & ~uintptr_t (SWIFT_CLASS_IS_SWIFT_MASK));
3038
3038
}
3039
3039
3040
+ // This gets called if we fail during copyGenericClassObjcName(). Its job is
3041
+ // to generate a unique name, even though the name won't be very helpful if
3042
+ // we end up looking at it in a debugger.
3043
+ #define EMERGENCY_PREFIX " $SwiftEmergencyPlaceholderClassName"
3044
+ static char *copyEmergencyName (ClassMetadata *theClass) {
3045
+ char *nameBuf = nullptr ;
3046
+ asprintf (&nameBuf,
3047
+ EMERGENCY_PREFIX " %016" PRIxPTR,
3048
+ (uintptr_t )theClass);
3049
+ return nameBuf;
3050
+ }
3051
+
3040
3052
static char *copyGenericClassObjCName (ClassMetadata *theClass) {
3041
3053
// Use the remangler to generate a mangled name from the type metadata.
3042
3054
Demangle::StackAllocatedDemangler<4096 > Dem;
3043
3055
3044
3056
auto demangling = _swift_buildDemanglingForMetadata (theClass, Dem);
3057
+ if (!demangling) {
3058
+ return copyEmergencyName (theClass);
3059
+ }
3045
3060
3046
3061
// Remangle that into a new type mangling string.
3047
3062
auto typeNode = Dem.createNode (Demangle::Node::Kind::TypeMangling);
@@ -3051,7 +3066,7 @@ static char *copyGenericClassObjCName(ClassMetadata *theClass) {
3051
3066
3052
3067
auto mangling = Demangle::mangleNodeOld (globalNode, Dem);
3053
3068
if (!mangling.isSuccess ()) {
3054
- return nullptr ;
3069
+ return copyEmergencyName (theClass) ;
3055
3070
}
3056
3071
llvm::StringRef string = mangling.result ();
3057
3072
@@ -3064,7 +3079,7 @@ static char *copyGenericClassObjCName(ClassMetadata *theClass) {
3064
3079
size_t allocationSize = string.size () + 1 ;
3065
3080
if (addSuffix)
3066
3081
allocationSize += 1 ;
3067
-
3082
+
3068
3083
auto fullNameBuf = (char *)swift_slowAlloc (allocationSize, 0 );
3069
3084
memcpy (fullNameBuf, string.data (), string.size ());
3070
3085
0 commit comments