Skip to content

Commit b916be3

Browse files
authored
Merge pull request #84459 from eeckstein/fix-specialization-mangler
GenericSpecializationMangler: don't assume a SIL function name can always be demangled
2 parents c47b60a + a31a121 commit b916be3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SIL/Utils/GenericSpecializationMangler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ std::string SpecializationMangler::finalize() {
6363
StringRef FuncName = Function ? Function->getName() : StringRef(FunctionName);
6464
NodePointer FuncTopLevel = nullptr;
6565
if (FuncName.starts_with(MANGLING_PREFIX_STR)) {
66+
// Demangling can fail, i.e. FuncTopLevel == nullptr, if the user provides
67+
// a custom not-demangable `@_silgen_name` (but still containing the "$s"
68+
// mangling prefix).
6669
FuncTopLevel = D.demangleSymbol(FuncName);
67-
assert(FuncTopLevel);
6870
}
6971
else if (FuncName.starts_with(MANGLING_PREFIX_EMBEDDED_STR)) {
7072
FuncTopLevel = D.demangleSymbol(FuncName);

test/SILOptimizer/specialize_ossa.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,3 +1665,22 @@ bb0(%0 : $Int):
16651665
dealloc_stack %1
16661666
return %11
16671667
}
1668+
1669+
1670+
sil hidden [ossa] @$s_custom_not_demangable_name : $@convention(thin) <T> (@thick T.Type) -> () {
1671+
bb0(%0 : $@thick T.Type):
1672+
%8 = tuple ()
1673+
return %8 : $()
1674+
}
1675+
1676+
// CHECK-LABEL: sil [ossa] @call_custom_name :
1677+
// CHECK: function_ref @$s29$s_custom_not_demangable_nameSi_Ttg5 : $@convention(thin) () -> ()
1678+
// CHECK: } // end sil function 'call_custom_name'
1679+
sil [ossa] @call_custom_name : $@convention(thin) () -> () {
1680+
bb0:
1681+
%2 = function_ref @$s_custom_not_demangable_name : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> ()
1682+
%3 = metatype $@thick Int.Type
1683+
%4 = apply %2<Int>(%3) : $@convention(thin) <τ_0_0> (@thick τ_0_0.Type) -> ()
1684+
%5 = tuple ()
1685+
return %5 : $()
1686+
}

0 commit comments

Comments
 (0)