diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3419,7 +3419,26 @@ return Copy; } +static cl::opt +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(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); // - The caller and callee prototypes must match. Pointer types of @@ -3485,9 +3504,7 @@ void Verifier::visitCallInst(CallInst &CI) { visitCallBase(CI); - - if (CI.isMustTailCall()) - verifyMustTailCall(CI); + verifyMustTailCall(CI); } void Verifier::visitInvokeInst(InvokeInst &II) {