[llvm] [AMDGPU] Fix a decoder crash in disassembler (PR #214969)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 8 07:43:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Shilei Tian (shiltian)
<details>
<summary>Changes</summary>
Fixes #<!-- -->214915.
---
Full diff: https://github.com/llvm/llvm-project/pull/214969.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+2-1)
- (modified) llvm/test/MC/Disassembler/AMDGPU/decode-err.txt (+10)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 526d9f1bf8eb4..d8378895a7335 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -218,7 +218,8 @@ static DecodeStatus decodeDpp8FI(MCInst &Inst, unsigned Val, uint64_t Addr,
#define DECODE_SrcOp(Name, EncSize, OpWidth, EncImm) \
static DecodeStatus Name(MCInst &Inst, unsigned Imm, uint64_t /*Addr*/, \
const MCDisassembler *Decoder) { \
- assert(Imm < (1 << EncSize) && #EncSize "-bit encoding"); \
+ if (!isUInt<EncSize>(Imm)) \
+ return MCDisassembler::Fail; \
auto DAsm = static_cast<const AMDGPUDisassembler *>(Decoder); \
return addOperand(Inst, DAsm->decodeSrcOp(Inst, OpWidth, EncImm)); \
}
diff --git a/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt b/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt
index 6855d2e687951..71b6214eb6be3 100644
--- a/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt
+++ b/llvm/test/MC/Disassembler/AMDGPU/decode-err.txt
@@ -7,6 +7,16 @@
# GCN-ERR: [[@LINE+1]]:1: warning: invalid instruction encoding
0xdf,0x00,0x00,0x02
+# This is v_readfirstlane_b32 with an SGPR destination that does not fit the
+# 7-bit scalar register encoding of the 8-bit VOP1 vdst field.
+# GCN-ERR: [[@LINE+1]]:1: warning: invalid instruction encoding
+0x00,0x05,0xf4,0x7f
+
+# This is v_s_exp_f32 with an SGPR destination that does not fit the 7-bit
+# scalar register encoding of the 8-bit VOP3 vdst field.
+# GFX12-ERR: [[@LINE+1]]:1: warning: invalid instruction encoding
+0xfa,0x00,0x80,0xd6,0x01,0x00,0x01,0x02
+
# this is s_waitcnt_vscnt exec_hi, 0x1234, which is valid on gfx11, but not on gfx12
# GFX12-ERR: [[@LINE+1]]:1: warning: invalid instruction encoding
0x34,0x12,0x7f,0xbc
``````````
</details>
https://github.com/llvm/llvm-project/pull/214969
More information about the llvm-commits
mailing list