Skip to content

Commit 5ac3e7c

Browse files
authored
Merge pull request #33315 from eeckstein/fix-string-optimization
2 parents a577a87 + b8485d6 commit 5ac3e7c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/SILOptimizer/Transforms/StringOptimization.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,16 @@ static bool containsProblematicNode(Demangle::Node *node, bool qualified) {
257257
if (qualified)
258258
return true;
259259
break;
260-
case Demangle::Node::Kind::Class:
260+
case Demangle::Node::Kind::Class: {
261261
// ObjC class names are not derived from the mangling but from the
262262
// ObjC runtime. We cannot constant fold this.
263-
if (node->getChild(0)->getText() == "__C")
263+
Demangle::Node *context = node->getChild(0);
264+
if (context->getKind() == Demangle::Node::Kind::Module &&
265+
context->getText() == "__C") {
264266
return true;
267+
}
265268
break;
269+
}
266270
default:
267271
break;
268272
}

test/SILOptimizer/string_optimization.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Foundation
1313
struct Outer {
1414
struct Inner { }
1515

16+
class InnerClass { }
17+
1618
static let staticString = "static"
1719
}
1820

@@ -94,13 +96,23 @@ public func testQualifiedLocalType() -> String {
9496
return _typeName(LocalStruct.self, qualified: true)
9597
}
9698

99+
// CHECK-LABEL: sil [noinline] @$s4test0A10InnerClassSSyF
100+
// CHECK-NOT: apply
101+
// CHECK-NOT: bb1
102+
// CHECK: } // end sil function '$s4test0A10InnerClassSSyF'
103+
@inline(never)
104+
public func testInnerClass() -> String {
105+
return _typeName(Outer.InnerClass.self, qualified: true)
106+
}
107+
97108
#if _runtime(_ObjC)
98109
@inline(never)
99110
public func testObjcClassName(qualified: Bool) -> String {
100111
return _typeName(NSObject.self, qualified: qualified)
101112
}
102113
#endif
103114

115+
104116
@inline(never)
105117
func printEmbeeded(_ s: String) {
106118
print("<\(s)>")
@@ -130,6 +142,9 @@ printEmbeeded(testUnqualifiedLocalType())
130142
// CHECK-OUTPUT: <test.(unknown context at {{.*}}).LocalStruct>
131143
printEmbeeded(testQualifiedLocalType())
132144

145+
// CHECK-OUTPUT: <test.Outer.InnerClass>
146+
printEmbeeded(testInnerClass())
147+
133148
#if _runtime(_ObjC)
134149

135150
// Can't use check-output here, because for non ObjC runtimes it would not match.

0 commit comments

Comments
 (0)