From 6d9870bc222934afc2b58bab2d2d7d17bf48b494 Mon Sep 17 00:00:00 2001 From: usuyus Date: Fri, 8 Aug 2025 17:57:00 +0100 Subject: [PATCH 1/4] Skip tailcall argument check for OCaml functions --- llvm/lib/IR/Verifier.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 2d62d31cf6b47..ec6f5d0f2f898 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3604,8 +3604,10 @@ void Verifier::verifyMustTailCall(CallInst &CI) { // - The caller and callee prototypes must match. Pointer types of // parameters or return types may differ in pointee type, but not - // address space. - if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { + // address space. Note that this is not applicable for OCaml functions, + // since their arguments will not be passed from the stack. + if ((!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) && + CI.getCallingConv() != CallingConv::OCaml) { Check(CallerTy->getNumParams() == CalleeTy->getNumParams(), "cannot guarantee tail call due to mismatched parameter counts", &CI); for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { From 300f47025d4cd0702bbb4d0a46aff66a7cd6d61f Mon Sep 17 00:00:00 2001 From: usuyus Date: Fri, 15 Aug 2025 10:30:14 +0100 Subject: [PATCH 2/4] Move the ocamlcc check to a more reasonable location --- llvm/lib/IR/Verifier.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index ec6f5d0f2f898..1481c7c3a6afd 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3580,7 +3580,8 @@ void Verifier::verifyMustTailCall(CallInst &CI) { AttributeList CallerAttrs = F->getAttributes(); AttributeList CalleeAttrs = CI.getAttributes(); if (CI.getCallingConv() == CallingConv::SwiftTail || - CI.getCallingConv() == CallingConv::Tail) { + CI.getCallingConv() == CallingConv::Tail || + CI.getCallingConv() == CallingConv::OCaml) { StringRef CCName = CI.getCallingConv() == CallingConv::Tail ? "tailcc" : "swifttailcc"; @@ -3602,12 +3603,7 @@ void Verifier::verifyMustTailCall(CallInst &CI) { return; } - // - The caller and callee prototypes must match. Pointer types of - // parameters or return types may differ in pointee type, but not - // address space. Note that this is not applicable for OCaml functions, - // since their arguments will not be passed from the stack. - if ((!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) && - CI.getCallingConv() != CallingConv::OCaml) { + if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { Check(CallerTy->getNumParams() == CalleeTy->getNumParams(), "cannot guarantee tail call due to mismatched parameter counts", &CI); for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { From 839b1340f19ae8a854c16bd5f9384f357ccee744 Mon Sep 17 00:00:00 2001 From: usuyus Date: Fri, 15 Aug 2025 10:42:00 +0100 Subject: [PATCH 3/4] Add comment back... --- llvm/lib/IR/Verifier.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 1481c7c3a6afd..c139a7d7a38ee 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3603,6 +3603,9 @@ void Verifier::verifyMustTailCall(CallInst &CI) { return; } + // - The caller and callee prototypes must match. Pointer types of + // parameters or return types may differ in pointee type, but not + // address space. if (!CI.getCalledFunction() || !CI.getCalledFunction()->isIntrinsic()) { Check(CallerTy->getNumParams() == CalleeTy->getNumParams(), "cannot guarantee tail call due to mismatched parameter counts", &CI); From 22ca8d47e3e8db266f2d3e1b95763531e0d355f5 Mon Sep 17 00:00:00 2001 From: usuyus Date: Fri, 15 Aug 2025 11:01:32 +0100 Subject: [PATCH 4/4] CCName --- llvm/lib/IR/Verifier.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index c139a7d7a38ee..086c5394322c7 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3583,7 +3583,8 @@ void Verifier::verifyMustTailCall(CallInst &CI) { CI.getCallingConv() == CallingConv::Tail || CI.getCallingConv() == CallingConv::OCaml) { StringRef CCName = - CI.getCallingConv() == CallingConv::Tail ? "tailcc" : "swifttailcc"; + CI.getCallingConv() == CallingConv::Tail ? "tailcc" : + CI.getCallingConv() == CallingConv::SwiftTail ? "swifttailcc" : "ocamlcc"; // - Only sret, byval, swiftself, and swiftasync ABI-impacting attributes // are allowed in swifttailcc call