Skip to content

Commit 87bf924

Browse files
committed
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
1 parent 3a8399d commit 87bf924

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
172172
auto oldOpParamTypes = substConventions.getParameterSILTypes(context);
173173
auto newOpParamTypes = convertConventions.getParameterSILTypes(context);
174174

175+
// Currently we cannot deal with generic arguments/returns. Bail in this case.
176+
for (auto newRetTy : newOpRetTypes) {
177+
if (newRetTy.hasTypeParameter())
178+
return nullptr;
179+
}
180+
for (auto newParamTy : newOpParamTypes) {
181+
if (newParamTy.hasTypeParameter())
182+
return nullptr;
183+
}
184+
if (newIndirectErrorResultType && newIndirectErrorResultType.hasTypeParameter())
185+
return nullptr;
186+
175187
llvm::SmallVector<SILValue, 8> Args;
176188
llvm::SmallVector<BeginBorrowInst *, 8> Borrows;
177189
auto convertOp = [&](SILValue Op, SILType OldOpType, SILType NewOpType,

test/SILOptimizer/sil_combine_apply.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,24 @@ bb0:
570570
return %return : $()
571571
}
572572

573+
class GenC<T> {
574+
}
575+
576+
sil @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
577+
578+
// CHECK-LABEL: sil [ossa] @convert_function_with_generic_arg :
579+
// CHECK: [[C:%.*]] = convert_function
580+
// CHECK: apply [[C]]
581+
// CHECK: } // end sil function 'convert_function_with_generic_arg'
582+
sil [ossa] @convert_function_with_generic_arg : $@convention(thin) (@owned AnyObject) -> () {
583+
bb0(%0 : @owned $AnyObject):
584+
%2 = function_ref @takeGenC : $@convention(thin) <τ_0_0> (@owned GenC<τ_0_0>) -> ()
585+
%9 = convert_function %2 to $@convention(thin) (@owned AnyObject) -> ()
586+
%30 = apply %9(%0) : $@convention(thin) (@owned AnyObject) -> ()
587+
%r = tuple ()
588+
return %r
589+
}
590+
573591
sil shared [transparent] [thunk] @genericClosure : $@convention(thin) <T> (@in T) -> @out T {
574592
bb0(%0 : $*T, %1 : $*T):
575593
%12 = tuple ()

0 commit comments

Comments
 (0)