Skip to content

Commit b3ce988

Browse files
authored
[SelectionDAG] Use reportFatalUsageError() for invalid operand bundles (#142613)
Replace the asserts with reportFatalUsageError(), as these can be reached with invalid user-provided IR. Fixes #142531.
1 parent c95189f commit b3ce988

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,12 +3275,13 @@ void SelectionDAGBuilder::visitInvoke(const InvokeInst &I) {
32753275

32763276
// Deopt and ptrauth bundles are lowered in helper functions, and we don't
32773277
// have to do anything here to lower funclet bundles.
3278-
assert(!I.hasOperandBundlesOtherThan(
3279-
{LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
3280-
LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
3281-
LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
3282-
LLVMContext::OB_clang_arc_attachedcall}) &&
3283-
"Cannot lower invokes with arbitrary operand bundles yet!");
3278+
if (I.hasOperandBundlesOtherThan(
3279+
{LLVMContext::OB_deopt, LLVMContext::OB_gc_transition,
3280+
LLVMContext::OB_gc_live, LLVMContext::OB_funclet,
3281+
LLVMContext::OB_cfguardtarget, LLVMContext::OB_ptrauth,
3282+
LLVMContext::OB_clang_arc_attachedcall}))
3283+
reportFatalUsageError(
3284+
"cannot lower invokes with arbitrary operand bundles!");
32843285

32853286
const Value *Callee(I.getCalledOperand());
32863287
const Function *Fn = dyn_cast<Function>(Callee);
@@ -3380,9 +3381,10 @@ void SelectionDAGBuilder::visitCallBr(const CallBrInst &I) {
33803381

33813382
// Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
33823383
// have to do anything here to lower funclet bundles.
3383-
assert(!I.hasOperandBundlesOtherThan(
3384-
{LLVMContext::OB_deopt, LLVMContext::OB_funclet}) &&
3385-
"Cannot lower callbrs with arbitrary operand bundles yet!");
3384+
if (I.hasOperandBundlesOtherThan(
3385+
{LLVMContext::OB_deopt, LLVMContext::OB_funclet}))
3386+
reportFatalUsageError(
3387+
"cannot lower callbrs with arbitrary operand bundles!");
33863388

33873389
assert(I.isInlineAsm() && "Only know how to handle inlineasm callbr");
33883390
visitInlineAsm(I);
@@ -9549,12 +9551,12 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
95499551
// Deopt bundles are lowered in LowerCallSiteWithDeoptBundle, and we don't
95509552
// have to do anything here to lower funclet bundles.
95519553
// CFGuardTarget bundles are lowered in LowerCallTo.
9552-
assert(!I.hasOperandBundlesOtherThan(
9553-
{LLVMContext::OB_deopt, LLVMContext::OB_funclet,
9554-
LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
9555-
LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
9556-
LLVMContext::OB_convergencectrl}) &&
9557-
"Cannot lower calls with arbitrary operand bundles!");
9554+
if (I.hasOperandBundlesOtherThan(
9555+
{LLVMContext::OB_deopt, LLVMContext::OB_funclet,
9556+
LLVMContext::OB_cfguardtarget, LLVMContext::OB_preallocated,
9557+
LLVMContext::OB_clang_arc_attachedcall, LLVMContext::OB_kcfi,
9558+
LLVMContext::OB_convergencectrl}))
9559+
reportFatalUsageError("cannot lower calls with arbitrary operand bundles!");
95589560

95599561
SDValue Callee = getValue(I.getCalledOperand());
95609562

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: LLVM ERROR: cannot lower calls with arbitrary operand bundles!
4+
5+
declare void @g()
6+
7+
define void @f(i32 %arg) {
8+
call void @g() [ "foo"(i32 %arg) ]
9+
ret void
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: LLVM ERROR: cannot lower callbrs with arbitrary operand bundles!
4+
5+
define void @f(i32 %arg) {
6+
callbr void asm "", ""() [ "foo"(i32 %arg) ]
7+
to label %cont []
8+
9+
cont:
10+
ret void
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: not llc -mtriple=x86_64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: LLVM ERROR: cannot lower invokes with arbitrary operand bundles!
4+
5+
declare void @g()
6+
declare i32 @__gxx_personality_v0(...)
7+
8+
define void @f(i32 %arg) personality ptr @__gxx_personality_v0 {
9+
invoke void @g() [ "foo"(i32 %arg) ]
10+
to label %cont unwind label %lpad
11+
12+
lpad:
13+
%l = landingpad {ptr, i32}
14+
cleanup
15+
resume {ptr, i32} %l
16+
17+
cont:
18+
ret void
19+
}

0 commit comments

Comments
 (0)