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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());

Expand Down
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/X86/invalid-operand-bundle-call.ll
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/X86/invalid-operand-bundle-callbr.ll
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/X86/invalid-operand-bundle-invoke.ll
Original file line number Diff line number Diff line change
@@ -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
}
Loading