[llvm] AArch64: Use reportFatalUsageError for unsupported calling conv (PR #144840)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 19 22:28:00 PDT 2025


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/144840

>From a79c84bf292b473b073a5b762858c7cbdef2cb8f Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 19 Jun 2025 13:46:08 +0900
Subject: [PATCH 1/2] AArch64: Use reportFatalUsageError for unsupported
 calling conv

This probably should emit a DiagnosticInfoUnsupported and use the
default calling convention instead, but then we would need to pass
in the context.

Also move where CCAssignFnForCall is called. It was unnecessarily
called for each argument, so the error wouldn't trigger for functions
with 0 arguments.

This only ensures the error occurs for functions defined with the
calling convention. The error is still missed for outgoing calls
with no arguments. The lowering logic here is convoluted, calling
CCAssignFnForCall for each argument and it does not mirror
LowerFormalArguments so I'm not sure what's going on here.
---
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp  | 14 +++++++++-----
 llvm/test/CodeGen/AArch64/unsupported-cc-call.ll |  8 ++++++++
 llvm/test/CodeGen/AArch64/unsupported-cc-func.ll |  6 ++++++
 3 files changed, 23 insertions(+), 5 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
 create mode 100644 llvm/test/CodeGen/AArch64/unsupported-cc-func.ll

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 581f152776026..69f8c6c21a556 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -7632,7 +7632,7 @@ CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC,
                                                      bool IsVarArg) const {
   switch (CC) {
   default:
-    report_fatal_error("Unsupported calling convention.");
+    reportFatalUsageError("unsupported calling convention");
   case CallingConv::GHC:
     return CC_AArch64_GHC;
   case CallingConv::PreserveNone:
@@ -7741,6 +7741,12 @@ SDValue AArch64TargetLowering::LowerFormalArguments(
   unsigned NumArgs = Ins.size();
   Function::const_arg_iterator CurOrigArg = F.arg_begin();
   unsigned CurArgIdx = 0;
+  bool UseVarArgCC = false;
+  if (IsWin64)
+    UseVarArgCC = isVarArg;
+
+  CCAssignFn *AssignFn = CCAssignFnForCall(CallConv, UseVarArgCC);
+
   for (unsigned i = 0; i != NumArgs; ++i) {
     MVT ValVT = Ins[i].VT;
     if (Ins[i].isOrigArg()) {
@@ -7757,10 +7763,6 @@ SDValue AArch64TargetLowering::LowerFormalArguments(
       else if (ActualMVT == MVT::i16)
         ValVT = MVT::i16;
     }
-    bool UseVarArgCC = false;
-    if (IsWin64)
-      UseVarArgCC = isVarArg;
-    CCAssignFn *AssignFn = CCAssignFnForCall(CallConv, UseVarArgCC);
     bool Res =
         AssignFn(i, ValVT, ValVT, CCValAssign::Full, Ins[i].Flags, CCInfo);
     assert(!Res && "Call operand has unhandled type");
@@ -8429,6 +8431,8 @@ 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);
     bool Res = AssignFn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, CCInfo);
     assert(!Res && "Call operand has unhandled type");
diff --git a/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll b/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
new file mode 100644
index 0000000000000..3e03ac81baf5a
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/unsupported-cc-call.ll
@@ -0,0 +1,8 @@
+; FIXME: This should error:
+; RUN: llc -mtriple=aarch64-- -filetype=null %s
+declare amdgpu_gfx void @amdgpu_gfx_func()
+
+define void @call_amdgpu_gfx_func() {
+  call amdgpu_gfx void @amdgpu_gfx_func()
+  ret void
+}
diff --git a/llvm/test/CodeGen/AArch64/unsupported-cc-func.ll b/llvm/test/CodeGen/AArch64/unsupported-cc-func.ll
new file mode 100644
index 0000000000000..2d0fb12af0d4a
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/unsupported-cc-func.ll
@@ -0,0 +1,6 @@
+; RUN: not llc -mtriple=aarch64-- -filetype=null %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: unsupported calling convention
+define amdgpu_gfx void @amdgpu_gfx_func_definition() {
+  ret void
+}

>From 3385d2bd04c3b5c8ad8209a08c4133efa2946931 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 20 Jun 2025 14:27:10 +0900
Subject: [PATCH 2/2] Fix an MC test using an arm calling convention

---
 llvm/test/MC/AArch64/coff-function-type-info.ll | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/MC/AArch64/coff-function-type-info.ll b/llvm/test/MC/AArch64/coff-function-type-info.ll
index 21446c50ab275..63cac59adef1b 100644
--- a/llvm/test/MC/AArch64/coff-function-type-info.ll
+++ b/llvm/test/MC/AArch64/coff-function-type-info.ll
@@ -1,10 +1,10 @@
-; RUN: llc -mtriple arm64-windows -filetype asm -o - %s \
+    ; RUN: llc -mtriple arm64-windows -filetype asm -o - %s \
 ; RUN:    | FileCheck %s -check-prefix CHECK-ASM
 
 ; RUN: llc -mtriple arm64-windows -filetype obj -o - %s \
 ; RUN:    | llvm-readobj --symbols - | FileCheck %s -check-prefix CHECK-OBJECT
 
-define arm_aapcs_vfpcc void @external() {
+define aarch64_vector_pcs void @external() {
 entry:
   ret void
 }
@@ -15,7 +15,7 @@ entry:
 ; CHECK-ASM: .endef
 ; CHECK-ASM: .globl external
 
-define internal arm_aapcs_vfpcc void @internal() {
+define internal aarch64_vector_pcs void @internal() {
 entry:
   ret void
 }



More information about the llvm-commits mailing list