[llvm] [AMDGPU] Enhance error handling for mismatched calling conventions (PR #137825)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 29 08:27:48 PDT 2025


================
@@ -1453,13 +1453,22 @@ bool AMDGPUCallLowering::lowerChainCall(MachineIRBuilder &MIRBuilder,
 
 bool AMDGPUCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
                                    CallLoweringInfo &Info) const {
-  if (Function *F = Info.CB->getCalledFunction())
+  if (Function *F = Info.CB->getCalledFunction()) {
     if (F->isIntrinsic()) {
       assert(F->getIntrinsicID() == Intrinsic::amdgcn_cs_chain &&
              "Unexpected intrinsic");
       return lowerChainCall(MIRBuilder, Info);
     }
 
+    // Detect UB caused due to calling convention mismatches early to avoid
+    // debugging if errors occur later.
+    if (F->getCallingConv() != Info.CallConv) {
+      LLVM_DEBUG(dbgs() << "Failed to lower call: calling convention mismatch "
+                           "(undefined behavior)\n");
+      return false;
----------------
arsenm wrote:

This is deferring handling to the DAG fallback, should directly handle the case 

https://github.com/llvm/llvm-project/pull/137825


More information about the llvm-commits mailing list