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)
|
if (qualified)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case Demangle::Node::Kind::Class:
|
case Demangle::Node::Kind::Class: {
|
||||||
// ObjC class names are not derived from the mangling but from the
|
// ObjC class names are not derived from the mangling but from the
|
||||||
// ObjC runtime. We cannot constant fold this.
|
// 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;
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import Foundation
|
|||||||
struct Outer {
|
struct Outer {
|
||||||
struct Inner { }
|
struct Inner { }
|
||||||
|
|
||||||
|
class InnerClass { }
|
||||||
|
|
||||||
static let staticString = "static"
|
static let staticString = "static"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +96,15 @@ public func testQualifiedLocalType() -> String {
|
|||||||
return _typeName(LocalStruct.self, qualified: true)
|
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)
|
#if _runtime(_ObjC)
|
||||||
@inline(never)
|
@inline(never)
|
||||||
public func testObjcClassName(qualified: Bool) -> String {
|
public func testObjcClassName(qualified: Bool) -> String {
|
||||||
@@ -101,6 +112,7 @@ public func testObjcClassName(qualified: Bool) -> String {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@inline(never)
|
@inline(never)
|
||||||
func printEmbeeded(_ s: String) {
|
func printEmbeeded(_ s: String) {
|
||||||
print("<\(s)>")
|
print("<\(s)>")
|
||||||
@@ -130,6 +142,9 @@ printEmbeeded(testUnqualifiedLocalType())
|
|||||||
// CHECK-OUTPUT: <test.(unknown context at {{.*}}).LocalStruct>
|
// CHECK-OUTPUT: <test.(unknown context at {{.*}}).LocalStruct>
|
||||||
printEmbeeded(testQualifiedLocalType())
|
printEmbeeded(testQualifiedLocalType())
|
||||||
|
|
||||||
|
// CHECK-OUTPUT: <test.Outer.InnerClass>
|
||||||
|
printEmbeeded(testInnerClass())
|
||||||
|
|
||||||
#if _runtime(_ObjC)
|
#if _runtime(_ObjC)
|
||||||
|
|
||||||
// Can't use check-output here, because for non ObjC runtimes it would not match.
|
// Can't use check-output here, because for non ObjC runtimes it would not match.
|
||||||
|
|||||||
Reference in New Issue
Block a user