[llvm] [SelectionDAG] improve error messages for invalid operator bundle (PR #148945)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 15 12:51:32 PDT 2025
https://github.com/fmayer created https://github.com/llvm/llvm-project/pull/148945
None
>From 624accf98158d26a7bedefa94ecf8350363fab14 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Tue, 15 Jul 2025 12:51:20 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
.../SelectionDAG/SelectionDAGBuilder.cpp | 68 +++++++++----------
.../X86/invalid-operand-bundle-call.ll | 2 +-
.../X86/invalid-operand-bundle-callbr.ll | 2 +-
3 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 4954e23f9846f..74c14ede24755 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -842,6 +842,26 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
}
}
+static void failForInvalidBundles(const CallBase &I, StringRef Name,
+ ArrayRef<uint32_t> AllowedBundles) {
+ if (I.hasOperandBundlesOtherThan(AllowedBundles)) {
+ std::string Error;
+ for (unsigned i = 0, e = I.getNumOperandBundles(); i != e; ++i) {
+ OperandBundleUse U = I.getOperandBundleAt(i);
+ bool First = true;
+ if (is_contained(AllowedBundles, U.getTagID()))
+ continue;
+ if (!First)
+ Error += ", ";
+ First = false;
+ Error += U.getTagName();
+ }
+ reportFatalUsageError(
+ Twine("cannot lower ", Name)
+ .concat(Twine(" with arbitrary operand bundles: ", Error)));
+ }
+}
+
RegsForValue::RegsForValue(const SmallVector<Register, 4> ®s, MVT regvt,
EVT valuevt, std::optional<CallingConv::ID> CC)
: ValueVTs(1, valuevt), RegVTs(1, regvt), Regs(regs),
@@ -3351,30 +3371,12 @@ 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.
- constexpr uint32_t kAllowedBundles[] = {
- 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,
- LLVMContext::OB_kcfi};
- if (I.hasOperandBundlesOtherThan(kAllowedBundles)) {
- std::string Error;
- for (unsigned i = 0, e = I.getNumOperandBundles(); i != e; ++i) {
- OperandBundleUse U = I.getOperandBundleAt(i);
- bool First = true;
- if (is_contained(kAllowedBundles, U.getTagID()))
- continue;
- if (!First)
- Error += ", ";
- First = false;
- Error += U.getTagName();
- }
- reportFatalUsageError(
- Twine("cannot lower invokes with arbitrary operand bundles: ", Error));
- }
+ failForInvalidBundles(I, "invokes",
+ {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,
+ LLVMContext::OB_kcfi});
const Value *Callee(I.getCalledOperand());
const Function *Fn = dyn_cast<Function>(Callee);
@@ -3474,10 +3476,8 @@ 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.
- if (I.hasOperandBundlesOtherThan(
- {LLVMContext::OB_deopt, LLVMContext::OB_funclet}))
- reportFatalUsageError(
- "cannot lower callbrs with arbitrary operand bundles!");
+ failForInvalidBundles(I, "callbrs",
+ {LLVMContext::OB_deopt, LLVMContext::OB_funclet});
assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
visitInlineAsm(I);
@@ -9585,12 +9585,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.
- 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!");
+ failForInvalidBundles(
+ I, "calls",
+ {LLVMContext::OB_deopt, LLVMContext::OB_funclet,
+ LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
+ LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
+ LLVMContext::OB_convergencectrl});
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 1f3a458ecf3a9..ac4963f1f79cc 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: foo
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 56157d205b1c1..79bddc0755415 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: foo
define void @f(i32 %arg) {
callbr void asm "", ""() [ "foo"(i32 %arg) ]
More information about the llvm-commits
mailing list