@@ -256,17 +256,25 @@ testSuite.test("NotPresent") {
256
256
// Swift.Int is not a class type.
257
257
expectNil ( NSClassFromString ( " Si " ) )
258
258
259
- // Mangled names with byte sequences that look like symbolic references
260
- // should not be demangled.
261
- expectNil ( NSClassFromString ( " \u{1} badnews " ) ) ;
262
- expectNil ( NSClassFromString ( " $s \u{1} badnews " ) ) ;
263
- expectNil ( NSClassFromString ( " _T \u{1} badnews " ) ) ;
264
-
265
- // Correct mangled names with additional text afterwards should not resolve.
266
- expectNil ( NSClassFromString ( " _TtC4main20MangledSwiftSubclass_ " ) )
267
- expectNil ( NSClassFromString ( " _TtC4main22MangledSwiftSuperclassXYZ " ) )
268
- expectNil ( NSClassFromString ( " _TtC4main19MangledObjCSubclass123 " ) )
269
- expectNil ( NSClassFromString ( " _TtC4main21MangledObjCSuperclasswhee " ) )
259
+ if #available( StdlibDeploymentTarget 5 . 3 , * ) {
260
+ // Mangled names with byte sequences that look like symbolic references
261
+ // should not be demangled. Use indirect references to test. Direct
262
+ // references often resolve to readable memory, and then the data there
263
+ // often looks like a descriptor with an unknown kind and the lookup code
264
+ // then fails gracefully. With an indirect reference, the indirected pointer
265
+ // is typically garbage and dereferencing it will crash.
266
+ expectNil ( NSClassFromString ( " \u{2} badnews " ) ) ;
267
+ expectNil ( NSClassFromString ( " $s \u{2} badnews " ) ) ;
268
+ expectNil ( NSClassFromString ( " _T \u{2} badnews " ) ) ;
269
+ }
270
+
271
+ if #available( StdlibDeploymentTarget 5 . 3 , * ) {
272
+ // Correct mangled names with additional text afterwards should not resolve.
273
+ expectNil ( NSClassFromString ( " _TtC4main20MangledSwiftSubclass_ " ) )
274
+ expectNil ( NSClassFromString ( " _TtC4main22MangledSwiftSuperclassXYZ " ) )
275
+ expectNil ( NSClassFromString ( " _TtC4main19MangledObjCSubclass123 " ) )
276
+ expectNil ( NSClassFromString ( " _TtC4main21MangledObjCSuperclasswhee " ) )
277
+ }
270
278
}
271
279
272
280
runAllTests ( )
0 commit comments