Skip to content

Commit cd339d8

Browse files
committed
Add test for call.preallocated.arg and restore check
1 parent 708c018 commit cd339d8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5877,7 +5877,9 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
58775877
"Uses of llvm.call.preallocated.setup must be calls");
58785878
Intrinsic::ID IID = UseCall->getIntrinsicID();
58795879
if (IID == Intrinsic::call_preallocated_arg) {
5880-
auto *AllocArgIndex = cast<ConstantInt>(UseCall->getArgOperand(1));
5880+
auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5881+
Check(AllocArgIndex != nullptr,
5882+
"llvm.call.preallocated.alloc arg index must be a constant");
58815883
auto AllocArgIndexInt = AllocArgIndex->getValue();
58825884
Check(AllocArgIndexInt.sge(0) &&
58835885
AllocArgIndexInt.slt(NumArgs->getValue()),

llvm/test/Verifier/preallocated-invalid.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ define void @preallocated_setup_constant() {
7272
ret void
7373
}
7474

75+
; CHECK: llvm.call.preallocated.alloc arg index must be a constant
76+
define void @preallocated_arg_constant() {
77+
%ac = call i32 @blackbox()
78+
%cs = call token @llvm.call.preallocated.setup(i32 3)
79+
call token @llvm.call.preallocated.arg(token %cs, i32 %ac)
80+
ret void
81+
}
82+
7583
; CHECK: must be between 0 and corresponding
7684
define void @preallocated_setup_arg_index_in_bounds() {
7785
%cs = call token @llvm.call.preallocated.setup(i32 2)

0 commit comments

Comments
 (0)