SILCombine: fix convert_function -> apply peephole for generic function types

Currently we cannot deal with generic arguments/returns. Bail in this case.

Fixes a compiler crash
rdar://158809851
This commit is contained in:
Erik Eckstein
2025-08-26 10:16:12 +02:00
parent 55f82ea3a0
commit 36d2549bf4
2 changed files with 30 additions and 0 deletions

View File

@@ -172,6 +172,18 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
auto oldOpParamTypes = substConventions.getParameterSILTypes(context);
auto newOpParamTypes = convertConventions.getParameterSILTypes(context);
// Currently we cannot deal with generic arguments/returns. Bail in this case.
for (auto newRetTy : newOpRetTypes) {
if (newRetTy.hasTypeParameter())
return nullptr;
}
for (auto newParamTy : newOpParamTypes) {
if (newParamTy.hasTypeParameter())
return nullptr;
}
if (newIndirectErrorResultType && newIndirectErrorResultType.hasTypeParameter())
return nullptr;
llvm::SmallVector<SILValue, 8> Args;
llvm::SmallVector<BeginBorrowInst *, 8> Borrows;
auto convertOp = [&](SILValue Op, SILType OldOpType, SILType NewOpType,

View File

@@ -583,6 +583,24 @@ bb0:
return %return : $()
}
class GenC<T> {
}
sil @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
// CHECK-LABEL: sil [ossa] @convert_function_with_generic_arg :
// CHECK: [[C:%.*]] = convert_function
// CHECK: apply [[C]]
// CHECK: } // end sil function 'convert_function_with_generic_arg'
sil [ossa] @convert_function_with_generic_arg : $@convention(thin) (@owned AnyObject) -> () {
bb0(%0 : @owned $AnyObject):
%2 = function_ref @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
%9 = convert_function %2 to $@convention(thin) (@owned AnyObject) -> ()
%30 = apply %9(%0) : $@convention(thin) (@owned AnyObject) -> ()
%r = tuple ()
return %r
}
sil shared [transparent] [thunk] @genericClosure : $@convention(thin) <T> (@in T) -> @out T {
bb0(%0 : $*T, %1 : $*T):
%12 = tuple ()