[llvm] AArch64: Error on unsupported calls with no arguments (PR #229319)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 23:59:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

This was calling CCAssignFnForCall inside the loop over arguments instead of
once for the function, so it would skip the error if the function had no
arguments. Instead of checking IsFixed, change the logic to mirror what
LowerFormalArguments does.

Also required adding a calling convention definition for anyregcc to avoid
breaking patchpoint tests. These happened to work before because the assignment
function was never looked up for calls without arguments.

---
Full diff: https://github.com/llvm/llvm-project/pull/229319.diff


6 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64CallingConvention.cpp (+7) 
- (modified) llvm/lib/Target/AArch64/AArch64CallingConvention.h (+3) 
- (modified) llvm/lib/Target/AArch64/AArch64CallingConvention.td (+5) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+14-17) 
- (added) llvm/test/CodeGen/AArch64/anyregcc-call-error.ll (+10) 
- (modified) llvm/test/CodeGen/AArch64/unsupported-cc-call.ll (+4-2) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp b/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
index b094a058e50a7..6b9f6e12303f5 100644
--- a/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
+++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
@@ -221,6 +221,13 @@ static bool CC_AArch64_Custom_Block(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
   return finishStackBlock(PendingMembers, LocVT, ArgFlags, State, SlotAlign);
 }
 
+static bool CC_AArch64_AnyReg_Error(unsigned &, MVT &, MVT &,
+                                    CCValAssign::LocInfo &, ISD::ArgFlagsTy &,
+                                    CCState &) {
+  reportFatalUsageError("the anyregcc calling convention is only supported by "
+                        "the stackmap and patchpoint intrinsics");
+}
+
 // TableGen provides definitions of the calling convention analysis entry
 // points.
 #define GET_CALLING_CONV_IMPL
diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.h b/llvm/lib/Target/AArch64/AArch64CallingConvention.h
index 7105fa695334b..385995a6eeef2 100644
--- a/llvm/lib/Target/AArch64/AArch64CallingConvention.h
+++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.h
@@ -58,6 +58,9 @@ bool CC_AArch64_Arm64EC_CFGuard_Check(unsigned ValNo, MVT ValVT, MVT LocVT,
                                       CCValAssign::LocInfo LocInfo,
                                       ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
                                       CCState &State);
+bool CC_AArch64_AnyReg(unsigned ValNo, MVT ValVT, MVT LocVT,
+                       CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
+                       Type *OrigTy, CCState &State);
 bool CC_AArch64_GHC(unsigned ValNo, MVT ValVT, MVT LocVT,
                     CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
                     Type *OrigTy, CCState &State);
diff --git a/llvm/lib/Target/AArch64/AArch64CallingConvention.td b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
index 4683f166386e7..d71c6491eee1a 100644
--- a/llvm/lib/Target/AArch64/AArch64CallingConvention.td
+++ b/llvm/lib/Target/AArch64/AArch64CallingConvention.td
@@ -489,6 +489,11 @@ def CC_AArch64_DarwinPCS_ILP32_VarArg : CallingConv<[
            CCAssignToStack<16, 16>>
 ]>;
 
+let Entry = 1 in
+def CC_AArch64_AnyReg : CallingConv<[
+  CCCustom<"CC_AArch64_AnyReg_Error">
+]>;
+
 //===----------------------------------------------------------------------===//
 // ARM64 Calling Convention for GHC
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index ac8700d09491b..f6f069929a171 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -9291,6 +9291,8 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC,
   switch (CC) {
   default:
     reportFatalUsageError("unsupported calling convention");
+  case CallingConv::AnyReg:
+    return CC_AArch64_AnyReg;
   case CallingConv::GHC:
     return CC_AArch64_GHC;
   case CallingConv::PreserveNone:
@@ -10096,26 +10098,23 @@ static void analyzeCallOperands(const AArch64TargetLowering &TLI,
     NumArgs -= 2;
   }
 
+  // On Windows, the fixed arguments in a vararg call are passed in GPRs too, so
+  // use the vararg CC to force them to integer registers.
+  bool FixedUseVarArgCC = IsVarArg && IsCalleeWin64;
+  CCAssignFn *FixedAssignFn = TLI.CCAssignFnForCall(CalleeCC, FixedUseVarArgCC);
+  CCAssignFn *VarArgAssignFn =
+      IsVarArg ? TLI.CCAssignFnForCall(CalleeCC, /*IsVarArg=*/true) : nullptr;
+
   for (unsigned i = 0; i != NumArgs; ++i) {
     MVT ArgVT = Outs[i].VT;
     ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
-
-    bool UseVarArgCC = false;
-    if (IsVarArg) {
-      // On Windows, the fixed arguments in a vararg call are passed in GPRs
-      // too, so use the vararg CC to force them to integer registers.
-      if (IsCalleeWin64) {
-        UseVarArgCC = true;
-      } else {
-        UseVarArgCC = ArgFlags.isVarArg();
-      }
-    }
+    bool UseVarArgCC = FixedUseVarArgCC || (IsVarArg && ArgFlags.isVarArg());
 
     if (!UseVarArgCC) {
       // Get type of the original argument.
-      EVT ActualVT =
-          TLI.getValueType(DAG.getDataLayout(), CLI.Args[Outs[i].OrigArgIndex].Ty,
-                       /*AllowUnknown*/ true);
+      EVT ActualVT = TLI.getValueType(DAG.getDataLayout(),
+                                      CLI.Args[Outs[i].OrigArgIndex].Ty,
+                                      /*AllowUnknown*/ true);
       MVT ActualMVT = ActualVT.isSimple() ? ActualVT.getSimpleVT() : ArgVT;
       // If ActualMVT is i1/i8/i16, we should set LocVT to i8/i8/i16.
       if (ActualMVT == MVT::i1 || ActualMVT == MVT::i8)
@@ -10124,9 +10123,7 @@ static void analyzeCallOperands(const AArch64TargetLowering &TLI,
         ArgVT = MVT::i16;
     }
 
-    // FIXME: CCAssignFnForCall should be called once, for the call and not per
-    // argument. This logic should exactly mirror LowerFormalArguments.
-    CCAssignFn *AssignFn = TLI.CCAssignFnForCall(CalleeCC, UseVarArgCC);
+    CCAssignFn *AssignFn = UseVarArgCC ? VarArgAssignFn : FixedAssignFn;
     bool Res = AssignFn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags,
                         Outs[i].OrigTy, CCInfo);
     assert(!Res && "Call operand has unhandled type");
diff --git a/llvm/test/CodeGen/AArch64/anyregcc-call-error.ll b/llvm/test/CodeGen/AArch64/anyregcc-call-error.ll
new file mode 100644
index 0000000000000..bec9ac10d7142
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/anyregcc-call-error.ll
@@ -0,0 +1,10 @@
+; RUN: not llc -mtriple=aarch64-- -global-isel=0 -filetype=null %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=aarch64-- -global-isel=1 -filetype=null %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: the anyregcc calling convention is only supported by the stackmap and patchpoint intrinsics
+declare anyregcc void @anyregcc_func(i64)
+
+define void @call_anyregcc_func(i64 %x) {
+  call anyregcc void @anyregcc_func(i64 %x)
+  ret void
+}
diff --git a/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll b/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
index 3e03ac81baf5a..7bd9ae396a788 100644
--- a/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
+++ b/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
@@ -1,5 +1,7 @@
-; FIXME: This should error:
-; RUN: llc -mtriple=aarch64-- -filetype=null %s
+; RUN: not llc -mtriple=aarch64-- -global-isel=0 -filetype=null %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=aarch64-- -global-isel=1 -filetype=null %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: unsupported calling convention
 declare amdgpu_gfx void @amdgpu_gfx_func()
 
 define void @call_amdgpu_gfx_func() {

``````````

</details>


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


More information about the llvm-commits mailing list