Skip to content

Commit cccb6ad

Browse files
committed
[AMDGPU] Enhance verification of amdgcn.cs.chain intrinsic
Make sure that this intrinsic is being followed by unreachable. This LLVM defect was identified via the AMD Fuzzing project.
1 parent 12f8ed5 commit cccb6ad

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6367,6 +6367,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
63676367
"SGPR arguments must have the `inreg` attribute", &Call);
63686368
Check(!Call.paramHasAttr(3, Attribute::InReg),
63696369
"VGPR arguments must not have the `inreg` attribute", &Call);
6370+
Check(dyn_cast_or_null<UnreachableInst>(Call.getNextNode()),
6371+
"amdgcn_cs_chain must precede unreachable", &Call);
63706372
break;
63716373
}
63726374
case Intrinsic::amdgcn_set_inactive_chain_arg: {

llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-cs-chain.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ define amdgpu_cs_chain void @bad_exec(ptr %fn, i32 %exec, <4 x i32> inreg %sgpr,
3232
unreachable
3333
}
3434

35+
define amdgpu_cs_chain void @not_unreachable(ptr %fn, i32 %exec, <4 x i32> inreg %sgpr, { ptr, <3 x i32> } %vgpr) {
36+
; CHECK: amdgcn_cs_chain must precede unreachable
37+
; CHECK-NEXT: @llvm.amdgcn.cs.chain
38+
call void(ptr, i32, <4 x i32>, { ptr, <3 x i32> }, i32, ...) @llvm.amdgcn.cs.chain(ptr %fn, i32 %exec, <4 x i32> inreg %sgpr, { ptr, <3 x i32> } %vgpr, i32 0)
39+
ret void
40+
}
41+
3542
define void @bad_caller_default_cc(ptr %fn, i32 %exec, <4 x i32> inreg %sgpr, { ptr, <3 x i32> } %vgpr) {
3643
; CHECK: Intrinsic can only be used from functions with the amdgpu_cs_chain or amdgpu_cs_chain_preserve calling conventions
3744
; CHECK-NEXT: @llvm.amdgcn.set.inactive.chain.arg
@@ -117,4 +124,4 @@ define amdgpu_cs_chain void @set_inactive_chain_arg_inreg(ptr addrspace(1) %out,
117124
%tmp = call i32 @llvm.amdgcn.set.inactive.chain.arg(i32 %active, i32 inreg %inactive) #0
118125
store i32 %tmp, ptr addrspace(1) %out
119126
ret void
120-
}
127+
}

0 commit comments

Comments
 (0)