[llvm] [LLVM][Verifier] Actually verify call mismatches (PR #136052)

Bruno Cardoso Lopes via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 16:07:29 PDT 2025


https://github.com/bcardosolopes created https://github.com/llvm/llvm-project/pull/136052

None

>From 546489f449906a3f369f850e6162943d0f922e6f Mon Sep 17 00:00:00 2001
From: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
Date: Wed, 16 Apr 2025 16:06:46 -0700
Subject: [PATCH] [LLVM][Verifier] Actually verify call mismatches

---
 llvm/lib/IR/Verifier.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e3f6c1ad5a65b..92e798f18c483 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3570,6 +3570,16 @@ void Verifier::visitCallBase(CallBase &Call) {
         "Called function must be a pointer!", Call);
   FunctionType *FTy = Call.getFunctionType();
 
+  // `FTy` encodes the call site function type in case this is an indirect call
+  // or if the called function does not match the function type signature of the
+  // caller. Therefore retrieve the actual type of the called function in order
+  // to verify against the actual signature. Note `Call.getCalledFunction` shall
+  // not be used here because it returns null not only if this is an indirect
+  // call but also if the function signature mismatches, which is what we want
+  // to verify.
+  if (auto *CalledFn = dyn_cast_or_null<Function>(Call.getCalledOperand()))
+    FTy = CalledFn->getFunctionType();
+
   // Verify that the correct number of arguments are being passed
   if (FTy->isVarArg())
     Check(Call.arg_size() >= FTy->getNumParams(),



More information about the llvm-commits mailing list