Skip to content

Commit 0c8877e

Browse files
committed
CrossModuleOptimization: fix a crash with dynamic functions
Use the correct `FunctionRefBaseInst` API to get the callee. Fixes a compiler crash when using `dynamic` functions in embedded swift. rdar://162309631
1 parent 46623cb commit 0c8877e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ void CrossModuleOptimization::serializeInstruction(SILInstruction *inst,
921921
const FunctionFlags &canSerializeFlags) {
922922
// Put callees onto the worklist if they should be serialized as well.
923923
if (auto *FRI = dyn_cast<FunctionRefBaseInst>(inst)) {
924-
SILFunction *callee = FRI->getReferencedFunctionOrNull();
924+
SILFunction *callee = FRI->getInitiallyReferencedFunction();
925925
assert(callee);
926926
if (!callee->isDefinition() || callee->isAvailableExternally())
927927
return;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend %s -g -enable-experimental-feature Embedded -emit-ir | %FileCheck %s
2+
// REQUIRES: swift_feature_Embedded
3+
4+
5+
// CHECK-LABEL: define {{.*}} @"$e4main3fooyS2iF"
6+
// CHECK: call ptr @swift_getFunctionReplacement
7+
// CHECK: ret
8+
dynamic func foo(_ i: Int) -> Int {
9+
return i
10+
}
11+
12+
public func test(_ i: Int) -> Int {
13+
return foo(i)
14+
}

0 commit comments

Comments
 (0)