Skip to content

Commit

Permalink
Merge pull request #2766 from varungandhi-apple/vg-apple/stable
Browse files Browse the repository at this point in the history
Add optional verification to check that tail calls from swifttail->swiftail are marked musttail.
  • Loading branch information
varungandhi-apple authored Mar 31, 2021
2 parents b8fc4ea + f652e1b commit 80c7803
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 18 additions & 3 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3316,7 +3316,24 @@ 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()) {
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);
}
return;
}

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

Function *F = CI.getParent()->getParent();
Expand Down Expand Up @@ -3401,9 +3418,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 @@ -713,7 +713,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

0 comments on commit 80c7803

Please sign in to comment.