Skip to content

Commit fb25216

Browse files
authored
[AMDGPU] Enhance verification of amdgcn.cs.chain intrinsic (#128162)
Make sure that this intrinsic is being followed by unreachable. This LLVM defect was identified via the AMD Fuzzing project. Thanks to @rovka for helping me solve this issue!
1 parent 9546afe commit fb25216

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
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(isa_and_present<UnreachableInst>(Call.getNextNode()),
6371+
"llvm.amdgcn.cs.chain must be followed by unreachable", &Call);
63706372
break;
63716373
}
63726374
case Intrinsic::amdgcn_set_inactive_chain_arg: {

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

Lines changed: 7 additions & 0 deletions
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: llvm.amdgcn.cs.chain must be followed by 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

0 commit comments

Comments
 (0)