[llvm] [SelectionDAG] Use reportFatalUsageError() for invalid operand bundles (PR #142613)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 08:09:24 PDT 2025
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/142613
>From 7772327c84d0c3d81fcc2e15c4bcca69cdc16903 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 3 Jun 2025 16:36:30 +0200
Subject: [PATCH 1/2] [SelectionDAG] Use reportFatalUsageError() for invalid
operand bundles
Replace the asserts with reportFatalUsageError(), as these can
be reached with invalid user-provided IR.
---
.../SelectionDAG/SelectionDAGBuilder.cpp | 32 ++++++++++---------
.../X86/invalid-operand-bundle-call.ll | 10 ++++++
.../X86/invalid-operand-bundle-callbr.ll | 11 +++++++
.../X86/invalid-operand-bundle-invoke.ll | 19 +++++++++++
4 files changed, 57 insertions(+), 15 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
create mode 100644 llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
create mode 100644 llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
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
+}
>From 0d09b6975e4db1af5591a951f32e6f05068a586a Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 3 Jun 2025 17:08:16 +0200
Subject: [PATCH 2/2] lowercase
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 6 +++---
llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll | 2 +-
llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll | 2 +-
llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 907997d0aa752..2460c864b0815 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3281,7 +3281,7 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
LLVMContext::OB_clang_arc_attachedcall}))
reportFatalUsageError(
- "Cannot lower invokes with arbitrary operand bundles!");
+ "cannot lower invokes with arbitrary operand bundles!");
const Value *Callee(I.getCalledOperand());
const Function *Fn = dyn_cast<Function>(Callee);
@@ -3384,7 +3384,7 @@ void SelectionDAGBuilder::visitCallBr(const CallBrInst &I) {
if (I.hasOperandBundlesOtherThan(
{LLVMContext::OB_deopt, LLVMContext::OB_funclet}))
reportFatalUsageError(
- "Cannot lower callbrs with arbitrary operand bundles!");
+ "cannot lower callbrs with arbitrary operand bundles!");
assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
visitInlineAsm(I);
@@ -9556,7 +9556,7 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
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!");
+ 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
index 493ffd85af74b..1f3a458ecf3a9 100644
--- a/llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
@@ -1,6 +1,6 @@
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Cannot lower calls with arbitrary operand bundles!
+; CHECK: LLVM ERROR: cannot lower calls with arbitrary operand bundles!
declare void @g()
diff --git a/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll b/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
index b7c5d71776089..56157d205b1c1 100644
--- a/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
@@ -1,6 +1,6 @@
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Cannot lower callbrs with arbitrary operand bundles!
+; CHECK: LLVM ERROR: cannot lower callbrs with arbitrary operand bundles!
define void @f(i32 %arg) {
callbr void asm "", ""() [ "foo"(i32 %arg) ]
diff --git a/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll b/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
index ddfa5d2f60da4..8091a220a44c5 100644
--- a/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
+++ b/llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
@@ -1,6 +1,6 @@
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Cannot lower invokes with arbitrary operand bundles!
+; CHECK: LLVM ERROR: cannot lower invokes with arbitrary operand bundles!
declare void @g()
declare i32 @__gxx_personality_v0(...)
More information about the llvm-commits
mailing list