mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
StringOptimization: fix a crash when constant folding the type name of an inner class
rdar://problem/66540633
This commit is contained in:
@@ -257,12 +257,16 @@ static bool containsProblematicNode(Demangle::Node *node, bool qualified) {
|
||||
if (qualified)
|
||||
return true;
|
||||
break;
|
||||
case Demangle::Node::Kind::Class:
|
||||
case Demangle::Node::Kind::Class: {
|
||||
// ObjC class names are not derived from the mangling but from the
|
||||
// ObjC runtime. We cannot constant fold this.
|
||||
if (node->getChild(0)->getText() == "__C")
|
||||
Demangle::Node *context = node->getChild(0);
|
||||
if (context->getKind() == Demangle::Node::Kind::Module &&
|
||||
context->getText() == "__C") {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import Foundation
|
||||
struct Outer {
|
||||
struct Inner { }
|
||||
|
||||
class InnerClass { }
|
||||
|
||||
static let staticString = "static"
|
||||
}
|
||||
|
||||
@@ -94,6 +96,15 @@ public func testQualifiedLocalType() -> String {
|
||||
return _typeName(LocalStruct.self, qualified: true)
|
||||
}
|
||||
|
||||
// CHECK-LABEL: sil [noinline] @$s4test0A10InnerClassSSyF
|
||||
// CHECK-NOT: apply
|
||||
// CHECK-NOT: bb1
|
||||
// CHECK: } // end sil function '$s4test0A10InnerClassSSyF'
|
||||
@inline(never)
|
||||
public func testInnerClass() -> String {
|
||||
return _typeName(Outer.InnerClass.self, qualified: true)
|
||||
}
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
@inline(never)
|
||||
public func testObjcClassName(qualified: Bool) -> String {
|
||||
@@ -101,6 +112,7 @@ public func testObjcClassName(qualified: Bool) -> String {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@inline(never)
|
||||
func printEmbeeded(_ s: String) {
|
||||
print("<\(s)>")
|
||||
@@ -130,6 +142,9 @@ printEmbeeded(testUnqualifiedLocalType())
|
||||
// CHECK-OUTPUT: <test.(unknown context at {{.*}}).LocalStruct>
|
||||
printEmbeeded(testQualifiedLocalType())
|
||||
|
||||
// CHECK-OUTPUT: <test.Outer.InnerClass>
|
||||
printEmbeeded(testInnerClass())
|
||||
|
||||
#if _runtime(_ObjC)
|
||||
|
||||
// Can't use check-output here, because for non ObjC runtimes it would not match.
|
||||
|
||||
Reference in New Issue
Block a user