Skip to content

[SelectionDAG] Use reportFatalUsageError() for invalid operand bundles #142613

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 2 commits into from
Jun 4, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jun 3, 2025

Replace the asserts with reportFatalUsageError(), as these can be reached with invalid user-provided IR.

Fixes #142531.

Replace the asserts with reportFatalUsageError(), as these can
be reached with invalid user-provided IR.
@nikic nikic requested review from arsenm and RKSimon June 3, 2025 14:39
@llvmbot llvmbot added backend:X86 llvm:SelectionDAG SelectionDAGISel as well labels Jun 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)

Changes

Replace the asserts with reportFatalUsageError(), as these can be reached with invalid user-provided IR.

Fixes #142531.


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

4 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+17-15)
  • (added) llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll (+10)
  • (added) llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll (+11)
  • (added) llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll (+19)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 84f600744fb39..907997d0aa752 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3275,12 +3275,13 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
 
   // Deopt and ptrauth bundles are lowered in helper functions, and we don't
   // have to do anything here to lower funclet bundles.
-  assert(!I.hasOperandBundlesOtherThan(
-             {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
-              LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
-              LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
-              LLVMContext::OB_clang_arc_attachedcall}) &&
-         "Cannot lower invokes with arbitrary operand bundles yet!");
+  if (I.hasOperandBundlesOtherThan(
+          {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
+           LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
+           LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
+           LLVMContext::OB_clang_arc_attachedcall}))
+    reportFatalUsageError(
+        "Cannot lower invokes with arbitrary operand bundles!");
 
   const Value *Callee(I.getCalledOperand());
   const Function *Fn = dyn_cast<Function>(Callee);
@@ -3380,9 +3381,10 @@ void SelectionDAGBuilder::visitCallBr(const CallBrInst &I) {
 
   // Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
   // have to do anything here to lower funclet bundles.
-  assert(!I.hasOperandBundlesOtherThan(
-             {LLVMContext::OB_deopt, LLVMContext::OB_funclet}) &&
-         "Cannot lower callbrs with arbitrary operand bundles yet!");
+  if (I.hasOperandBundlesOtherThan(
+          {LLVMContext::OB_deopt, LLVMContext::OB_funclet}))
+    reportFatalUsageError(
+        "Cannot lower callbrs with arbitrary operand bundles!");
 
   assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
   visitInlineAsm(I);
@@ -9549,12 +9551,12 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
   // Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
   // have to do anything here to lower funclet bundles.
   // CFGuardTarget bundles are lowered in LowerCallTo.
-  assert(!I.hasOperandBundlesOtherThan(
-             {LLVMContext::OB_deopt, LLVMContext::OB_funclet,
-              LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
-              LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
-              LLVMContext::OB_convergencectrl}) &&
-         "Cannot lower calls with arbitrary operand bundles!");
+  if (I.hasOperandBundlesOtherThan(
+          {LLVMContext::OB_deopt, LLVMContext::OB_funclet,
+           LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
+           LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
+           LLVMContext::OB_convergencectrl}))
+    reportFatalUsageError("Cannot lower calls with arbitrary operand bundles!");
 
   SDValue Callee = getValue(I.getCalledOperand());
 
diff --git a/llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll b/llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
new file mode 100644
index 0000000000000..493ffd85af74b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
@@ -0,0 +1,10 @@
+; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: Cannot lower calls with arbitrary operand bundles!
+
+declare void @g()
+
+define void @f(i32 %arg) {
+  call void @g() [ "foo"(i32 %arg) ]
+  ret void
+}
diff --git a/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll b/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
new file mode 100644
index 0000000000000..b7c5d71776089
--- /dev/null
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
@@ -0,0 +1,11 @@
+; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: Cannot lower callbrs with arbitrary operand bundles!
+
+define void @f(i32 %arg) {
+  callbr void asm "", ""() [ "foo"(i32 %arg) ]
+    to label %cont []
+
+cont:
+  ret void
+}
diff --git a/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll b/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
new file mode 100644
index 0000000000000..ddfa5d2f60da4
--- /dev/null
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
@@ -0,0 +1,19 @@
+; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: Cannot lower invokes with arbitrary operand bundles!
+
+declare void @g()
+declare i32 @__gxx_personality_v0(...)
+
+define void @f(i32 %arg) personality ptr @__gxx_personality_v0 {
+  invoke void @g() [ "foo"(i32 %arg) ]
+    to label %cont unwind label %lpad
+
+lpad:
+  %l = landingpad {ptr, i32}
+    cleanup
+  resume {ptr, i32} %l
+
+cont:
+  ret void
+}

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

Should these be IR verifier errors?

@nikic
Copy link
Contributor Author

nikic commented Jun 3, 2025

Should these be IR verifier errors?

I don't think so. From an IR perspective operand bundles are extensible.

@nikic nikic merged commit b3ce988 into llvm:main Jun 4, 2025
9 of 11 checks passed
@nikic nikic deleted the codegen-operand-bundle-error branch June 4, 2025 07:33
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
llvm#142613)

Replace the asserts with reportFatalUsageError(), as these can be
reached with invalid user-provided IR.

Fixes llvm#142531.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
llvm#142613)

Replace the asserts with reportFatalUsageError(), as these can be
reached with invalid user-provided IR.

Fixes llvm#142531.
ro-i added a commit to ro-i/llvm-project that referenced this pull request Jun 12, 2025
ro-i added a commit to ro-i/llvm-project that referenced this pull request Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[llc] Assertion `!I.hasOperandBundlesOtherThan(...) && "Cannot lower calls with arbitrary operand bundles!"' failed.
3 participants