[llvm] [win][arm64ec] Fix duplicate errors with the dontcall attribute (PR #152810)

Daniel Paoliello via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 9 14:51:35 PDT 2025


https://github.com/dpaoliello updated https://github.com/llvm/llvm-project/pull/152810

>From c9f311e36be8ea892c89333cf2d3bfde56ef0e92 Mon Sep 17 00:00:00 2001
From: Daniel Paoliello <danpao at microsoft.com>
Date: Fri, 8 Aug 2025 16:01:56 -0700
Subject: [PATCH] [win][arm64ec] Fix duplicate errors with the dontcall
 attribute

---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  | 12 ++++++----
 llvm/lib/CodeGen/SelectionDAG/FastISel.cpp    |  7 ++++--
 .../test/CodeGen/AArch64/arm64ec-dont-call.ll | 22 +++++++++++++++++++
 3 files changed, 35 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d30dfa72f0e9c..5dc8d275e04c2 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2786,11 +2786,15 @@ bool IRTranslator::translateCall(const User &U, MachineIRBuilder &MIRBuilder) {
   if (CI.isInlineAsm())
     return translateInlineAsm(CI, MIRBuilder);
 
-  diagnoseDontCall(CI);
-
   Intrinsic::ID ID = F ? F->getIntrinsicID() : Intrinsic::not_intrinsic;
-  if (!F || ID == Intrinsic::not_intrinsic)
-    return translateCallBase(CI, MIRBuilder);
+  if (!F || ID == Intrinsic::not_intrinsic) {
+    bool Result = translateCallBase(CI, MIRBuilder);
+    if (Result) {
+      diagnoseDontCall(CI);
+      return true;
+    }
+    return false;
+  }
 
   assert(ID != Intrinsic::not_intrinsic && "unknown intrinsic");
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index fb9eff942a464..4b5d8a584b8e2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1148,9 +1148,12 @@ bool FastISel::lowerCall(const CallInst *CI) {
   CLI.setCallee(RetTy, FuncTy, CI->getCalledOperand(), std::move(Args), *CI)
       .setTailCall(IsTailCall);
 
-  diagnoseDontCall(*CI);
+  if (lowerCallTo(CLI)) {
+    diagnoseDontCall(*CI);
+    return true;
+  }
 
-  return lowerCallTo(CLI);
+  return false;
 }
 
 bool FastISel::selectCall(const User *I) {
diff --git a/llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll b/llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll
new file mode 100644
index 0000000000000..b53def08ee84b
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll
@@ -0,0 +1,22 @@
+; RUN: not llc -mtriple=arm64ec-windows-msvc -filetype=null %s 2>&1 | FileCheck %s
+; RUN: not llc -mtriple=arm64ec-windows-msvc -filetype=null -global-isel=1 -global-isel-abort=0 %s 2>&1 | FileCheck %s
+
+define void @baz() #0 {
+  call void @foo()
+  ret void
+}
+
+define void @foo() #1 {
+  ret void
+}
+
+attributes #0 = { noinline optnone }
+attributes #1 = { "dontcall-error"="oh no foo" }
+
+; Regression test for `dontcall-error` for Arm64EC. Since this attribute is
+; checked both by FastISel and SelectionDAGBuilder, and FastISel was bailing for
+; Arm64EC AFTER doing the check, we ended up with duplicate copies of this
+; error.
+
+; CHECK: error: call to #foo marked "dontcall-error": oh no foo
+; CHECK-NOT: error:



More information about the llvm-commits mailing list