Skip to content

Commit 788e3c0

Browse files
authored
Merge pull request #83948 from mikeash/objc-getclass-test-availability
[Test] Gate newer objc_getClass tests on OS version.
2 parents 9fe4383 + e1fff81 commit 788e3c0

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

test/Interpreter/SDK/objc_getClass.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,25 @@ testSuite.test("NotPresent") {
256256
// Swift.Int is not a class type.
257257
expectNil(NSClassFromString("Si"))
258258

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+
}
270278
}
271279

272280
runAllTests()

0 commit comments

Comments
 (0)