diff options
| author | Philip Reames <preames@rivosinc.com> | 2023-06-26 11:42:31 -0700 |
|---|---|---|
| committer | Philip Reames <listmail@philipreames.com> | 2023-06-26 11:45:17 -0700 |
| commit | c6b56cec8b208801f84b030be24c1738089fe239 (patch) | |
| tree | f5a5963e7b7d6e6dcc6dd4ad38fa66757fa83e1b | |
| parent | dee1f5b32c3a6a5694c3bb2fbf68d162447a5970 (diff) | |
| download | llvm-c6b56cec8b208801f84b030be24c1738089fe239.zip llvm-c6b56cec8b208801f84b030be24c1738089fe239.tar.gz llvm-c6b56cec8b208801f84b030be24c1738089fe239.tar.bz2 | |
[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.
| -rw-r--r-- | llvm/lib/Target/RISCV/RISCVInstrInfo.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp index b7217ce..b88befe 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"; |
