[llvm] c6b56ce - [RISCV] Check that SEW and policy operands are immediates in verifier
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 26 11:45:23 PDT 2023
Author: Philip Reames
Date: 2023-06-26T11:45:17-07:00
New Revision: c6b56cec8b208801f84b030be24c1738089fe239
URL: https://github.com/llvm/llvm-project/commit/c6b56cec8b208801f84b030be24c1738089fe239
DIFF: https://github.com/llvm/llvm-project/commit/c6b56cec8b208801f84b030be24c1738089fe239.diff
LOG: [RISCV] Check that SEW and policy operands are immediates in verifier
This converts a crash (due an assertion inside getImm) into a verifier failure. Much easier to debug when you have malformed instructions.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index b7217ce439c99..b88befe8fa690 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -1828,6 +1828,10 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
}
if (RISCVII::hasSEWOp(TSFlags)) {
unsigned OpIdx = RISCVII::getSEWOpNum(Desc);
+ if (!MI.getOperand(OpIdx).isImm()) {
+ ErrInfo = "SEW value expected to be an immediate";
+ return false;
+ }
uint64_t Log2SEW = MI.getOperand(OpIdx).getImm();
if (Log2SEW > 31) {
ErrInfo = "Unexpected SEW value";
@@ -1841,6 +1845,10 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
}
if (RISCVII::hasVecPolicyOp(TSFlags)) {
unsigned OpIdx = RISCVII::getVecPolicyOpNum(Desc);
+ if (!MI.getOperand(OpIdx).isImm()) {
+ ErrInfo = "Policy operand expected to be an immediate";
+ return false;
+ }
uint64_t Policy = MI.getOperand(OpIdx).getImm();
if (Policy > (RISCVII::TAIL_AGNOSTIC | RISCVII::MASK_AGNOSTIC)) {
ErrInfo = "Invalid Policy Value";
More information about the llvm-commits
mailing list