Skip to content

[5.5] [IRGen] Fix missing musttail for dynamic replacement calls. #37654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,10 @@ void IRGenModule::emitDynamicReplacementOriginalFunctionThunk(SILFunction *f) {
FunctionPointer(fnType, typeFnPtr, authInfo, signature)
.getAsFunction(IGF),
forwardedArgs);
Res->setTailCall();
if (f->isAsync()) {
Res->setTailCallKind(IGF.IGM.AsyncTailCallKind);
}

if (implFn->getReturnType()->isVoidTy())
IGF.Builder.CreateRetVoid();
Expand Down
25 changes: 25 additions & 0 deletions test/IRGen/async_dynamic_replacement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-swift-frontend %s -emit-ir -disable-objc-interop | %FileCheck %s

// Windows does not do swiftailcc
// XFAIL: OS=windows-msvc

// REQUIRES: concurrency

public dynamic func number() async -> Int {
return 100
}

@_dynamicReplacement(for: number())
internal func _replacement_number() async -> Int {
return 200
}

// rdar://78284346 - Dynamic replacement should use musttail
// for tail calls from swifttailcc to swifttailcc
// CHECK-LABEL: define {{.*}} swifttailcc void @"$s25async_dynamic_replacement01_C7_numberSiyYaFTI"
// CHECK: musttail call swifttailcc void
// CHECK-NEXT: ret void

public func calls_number() async -> Int {
await number()
}