Skip to content

Cherry-Pick -enable-swifttail-musttail-check flag #3016

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
23 changes: 20 additions & 3 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3430,7 +3430,26 @@ static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) {
return Copy;
}

static cl::opt<bool>
EnableSwiftTailCCMustTailCheck("enable-swifttailcc-musttail-check",
cl::init(false), cl::desc("Check that tail calls from swifttailcc functions to"
" swifttailcc functions are marked musttail."));

void Verifier::verifyMustTailCall(CallInst &CI) {
if (!CI.isMustTailCall()) {
#ifndef NDEBUG
if (EnableSwiftTailCCMustTailCheck &&
CI.getCallingConv() == CallingConv::SwiftTail &&
CI.getCaller()->getCallingConv() == CallingConv::SwiftTail &&
isa_and_nonnull<ReturnInst>(CI.getNextNode())) {
Assert(
false, "tail call from swifttail->swiftail should be marked musttail",
&CI);
}
#endif
return;
}

Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI);

Function *F = CI.getParent()->getParent();
Expand Down Expand Up @@ -3515,9 +3534,7 @@ void Verifier::verifyMustTailCall(CallInst &CI) {

void Verifier::visitCallInst(CallInst &CI) {
visitCallBase(CI);

if (CI.isMustTailCall())
verifyMustTailCall(CI);
verifyMustTailCall(CI);
}

void Verifier::visitInvokeInst(InvokeInst &II) {
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/IPO/MergeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,11 @@ void MergeFunctions::writeThunk(Function *F, Function *G) {

CallInst *CI = Builder.CreateCall(F, Args);
ReturnInst *RI = nullptr;
CI->setTailCall();
bool isSwiftTailCall =
F->getCallingConv() == CallingConv::SwiftTail &&
G->getCallingConv() == CallingConv::SwiftTail;
CI->setTailCallKind(
isSwiftTailCall ? llvm::CallInst::TCK_MustTail : llvm::CallInst::TCK_Tail);
CI->setCallingConv(F->getCallingConv());
CI->setAttributes(F->getAttributes());
if (H->getReturnType()->isVoidTy()) {
Expand Down