Skip to content

Commit ed20908

Browse files
committed
AST: Don't use standard substitutions when mangling typealiases
Swift.UnicodeScalar is a typealias now, and for the TypeDecoder to work correctly we need to mangle it as a typealias and not as a struct. However, we still want to demangle old names that used the substitution, so don't remove it, instead just skip checking for a substitution when mangling a typealias. This does not change the ABI; typealiases are only mangled as part of debug info.
1 parent 72f0efe commit ed20908

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,11 +2174,13 @@ bool ASTMangler::tryAppendStandardSubstitution(const GenericTypeDecl *decl) {
21742174
if (!isStdlibType(decl))
21752175
return false;
21762176

2177-
if (char Subst = getStandardTypeSubst(decl->getName().str())) {
2178-
if (!SubstMerging.tryMergeSubst(*this, Subst, /*isStandardSubst*/ true)) {
2179-
appendOperator("S", StringRef(&Subst, 1));
2177+
if (isa<NominalTypeDecl>(decl)) {
2178+
if (char Subst = getStandardTypeSubst(decl->getName().str())) {
2179+
if (!SubstMerging.tryMergeSubst(*this, Subst, /*isStandardSubst*/ true)) {
2180+
appendOperator("S", StringRef(&Subst, 1));
2181+
}
2182+
return true;
21802183
}
2181-
return true;
21822184
}
21832185
return false;
21842186
}

test/DebugInfo/typealias.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func main () {
6363
// CHECK: [[GENERIC_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$s9typealias11NotSpecificaySiGD"
6464
let g: NotSpecific<Int> = .value
6565
markUsed(g)
66+
67+
// Make sure we're not using the abbreviation for this obsolete type that was replaced with a typealias in Swift 4
68+
//
69+
// CHECK-DAG: !DILocalVariable(name: "h", {{.*}} type: [[UNICODE_SCALAR_TYPE:![0-9]+]])
70+
// CHECK: [[UNICODE_SCALAR_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "$ss13UnicodeScalaraD"
71+
let h: UnicodeScalar = "a"
72+
markUsed(h)
6673
}
6774

6875
main()

0 commit comments

Comments
 (0)