Skip to content

Commit 52459b1

Browse files
Merge pull request #37654 from varungandhi-apple/vg-5.5-musttail-dynamic-replacement
[5.5] [IRGen] Fix missing musttail for dynamic replacement calls.
2 parents 8410011 + dc59efc commit 52459b1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -disable-objc-interop | %FileCheck %s
2+
3+
// Windows does not do swiftailcc
4+
// XFAIL: OS=windows-msvc
5+
6+
// REQUIRES: concurrency
7+
8+
public dynamic func number() async -> Int {
9+
return 100
10+
}
11+
12+
@_dynamicReplacement(for: number())
13+
internal func _replacement_number() async -> Int {
14+
return 200
15+
}
16+
17+
// rdar://78284346 - Dynamic replacement should use musttail
18+
// for tail calls from swifttailcc to swifttailcc
19+
// CHECK-LABEL: define {{.*}} swifttailcc void @"$s25async_dynamic_replacement01_C7_numberSiyYaFTI"
20+
// CHECK: musttail call swifttailcc void
21+
// CHECK-NEXT: ret void
22+
23+
public func calls_number() async -> Int {
24+
await number()
25+
}

0 commit comments

Comments
 (0)