Skip to content

[win][arm64ec] Fix duplicate errors with the dontcall attribute #152810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented Aug 8, 2025

Since the dontcall-* attributes are checked both by FastISel/GlobalISel and SelectionDAGBuilder, and both FastISel and GlobalISel bail for calls on Arm64EC for AFTER doing the check, we ended up emitting duplicate copies of this error.

This change moves the checking for dontcall-* in FastISel and GlobalISel to after it has been successfully lowered.

@llvmbot llvmbot added backend:AArch64 llvm:SelectionDAG SelectionDAGISel as well labels Aug 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2025

@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-aarch64

Author: Daniel Paoliello (dpaoliello)

Changes

Since the dontcall-* attributes are checked both by FastISel and SelectionDAGBuilder, and FastISel bails for calls on Arm64EC for AFTER doing the check, we ended up emitting duplicate copies of this error.

This change moves the checking for dontcall-* in FastISel to after it has been successfully lowered.


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/FastISel.cpp (+5-3)
  • (added) llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll (+21)
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index fb9eff942a464..5bc158a660080 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1148,9 +1148,11 @@ bool FastISel::lowerCall(const CallInst *CI) {
   CLI.setCallee(RetTy, FuncTy, CI->getCalledOperand(), std::move(Args), *CI)
       .setTailCall(IsTailCall);
 
-  diagnoseDontCall(*CI);
-
-  return lowerCallTo(CLI);
+  if (lowerCallTo(CLI)) {
+    diagnoseDontCall(*CI);
+    return true;
+  } else
+    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..febb8997f3e37
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64ec-dont-call.ll
@@ -0,0 +1,21 @@
+; RUN: not llc -mtriple arm64ec-windows-msvc -o - %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:

@@ -0,0 +1,21 @@
; RUN: not llc -mtriple arm64ec-windows-msvc -o - %s 2>&1 | FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; RUN: not llc -mtriple arm64ec-windows-msvc -o - %s 2>&1 | FileCheck %s
; RUN: not llc -mtriple=arm64ec-windows-msvc -filetype=null %s 2>&1 | FileCheck %s

Comment on lines 1154 to 1155
} else
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else
return false;
}
return false;

No else after return

Comment on lines 2791 to 2792
bool Result = translateCallBase(CI, MIRBuilder);
if (Result) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool Result = translateCallBase(CI, MIRBuilder);
if (Result) {
if (translateCallBase(CI, MIRBuilder)) {

@dpaoliello dpaoliello merged commit c430e06 into llvm:main Aug 12, 2025
9 checks passed
@dpaoliello dpaoliello deleted the arm64ecdontcal branch August 12, 2025 18:05
@dpaoliello
Copy link
Contributor Author

Possible build break: https://lab.llvm.org/buildbot/#/builders/154/builds/20134

FAIL: Clang :: Frontend/backend-attribute-error-warning.c (7019 of 88313)
******************** TEST 'Clang :: Frontend/backend-attribute-error-warning.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/22/include -nostdsysteminc -verify=expected,enabled -emit-codegen-only /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c # RUN: at line 1
+ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/lib/clang/22/include -nostdsysteminc -verify=expected,enabled -emit-codegen-only /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c
error: diagnostics with 'error' severity expected but not seen: 
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 25 'expected-error': call to 'foo' declared with 'error' attribute: oh no foo
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 27 'expected-error': call to 'bar' declared with 'error' attribute: oh no bar
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 30 'expected-error': call to '__compiletime_assert_455' declared with 'error' attribute: demangle me
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 31 'expected-error': call to 'duplicate_errors' declared with 'error' attribute: two
error: diagnostics with 'warning' severity expected but not seen: 
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 29 'enabled-warning': call to 'quux' declared with 'warning' attribute: oh no quux
  File /home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/test/Frontend/backend-attribute-error-warning.c Line 32 'enabled-warning': call to 'duplicate_warnings' declared with 'warning' attribute: two
6 errors generated.

--

********************

Not sure why this change would mean NOT seeing the errors at all - is SelectionDAG finishing before it checks?

@dpaoliello
Copy link
Contributor Author

Possible build break: https://lab.llvm.org/buildbot/#/builders/154/builds/20134

Fixed: #153302

dpaoliello added a commit that referenced this pull request Aug 12, 2025
…astSelectInstruction (#153302)

Recently my change to avoid duplicate `dontcall` attribute errors
(#152810) caused the Clang `Frontend/backend-attribute-error-warning.c`
test to fail on Arm32:
<https://lab.llvm.org/buildbot/#/builders/154/builds/20134>

The root cause is that, if the default `IFastSel` path bails, then
targets are given the opportunity to lower instructions via
`fastSelectInstruction`. That's the path taken by Arm32 and since its
implementation of `selectCall` didn't call `diagnoseDontCall` no error
was emitted.

I've checked the other implementations of `fastSelectInstruction` and
the only other one that lowers call instructions in WebAssembly, so I've
fixed that too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants