[llvm] [SelectionDAG] Use reportFatalUsageError() for invalid operand bundles (PR #142613)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 07:39:47 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
@llvm/pr-subscribers-backend-x86
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
Replace the asserts with reportFatalUsageError(), as these can be reached with invalid user-provided IR.
Fixes https://github.com/llvm/llvm-project/issues/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
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/142613
More information about the llvm-commits
mailing list