Skip to content

Commit fbdb140

Browse files
Merge pull request #37592 from varungandhi-apple/vg-musttail-dynamic-replacement
Fix missing musttail for dynamic replacement calls.
2 parents da4eb3a + a044644 commit fbdb140

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,10 @@ void IRGenModule::emitDynamicReplacementOriginalFunctionThunk(SILFunction *f) {
29552955
FunctionPointer(fnType, typeFnPtr, authInfo, signature)
29562956
.getAsFunction(IGF),
29572957
forwardedArgs);
2958+
Res->setTailCall();
2959+
if (f->isAsync()) {
2960+
Res->setTailCallKind(IGF.IGM.AsyncTailCallKind);
2961+
}
29582962

29592963
if (implFn->getReturnType()->isVoidTy())
29602964
IGF.Builder.CreateRetVoid();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -disable-objc-interop | %FileCheck %s
2+
3+
// REQUIRES: concurrency
4+
5+
public dynamic func number() async -> Int {
6+
return 100
7+
}
8+
9+
@_dynamicReplacement(for: number())
10+
internal func _replacement_number() async -> Int {
11+
return 200
12+
}
13+
14+
// rdar://78284346 - Dynamic replacement should use musttail
15+
// for tail calls from swifttailcc to swifttailcc
16+
// CHECK-LABEL: define {{.*}} swifttailcc void @"$s25async_dynamic_replacement01_C7_numberSiyYaFTI"
17+
// CHECK: musttail call swifttailcc void
18+
// CHECK-NEXT: ret void
19+
20+
public func calls_number() async -> Int {
21+
await number()
22+
}

0 commit comments

Comments
 (0)