[PATCH] D114581: [RISCV] Fix a crash in decoding LMUL in VTYPE

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 29 03:06:30 PST 2021


benshi001 updated this revision to Diff 390296.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114581/new/

https://reviews.llvm.org/D114581

Files:
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/test/MC/RISCV/rvv/vsetvl-invalid.s


Index: llvm/test/MC/RISCV/rvv/vsetvl-invalid.s
===================================================================
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/vsetvl-invalid.s
@@ -0,0 +1,28 @@
+# RUN: llvm-mc -filetype=obj -triple=riscv32 %s \
+# RUN:     | llvm-objdump -d --mattr=+experimental-v - | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 %s \
+# RUN:     | llvm-objdump -d --mattr=+experimental-v - | FileCheck %s
+
+# CHECK: vsetvli a1, a0, e64, m1, tu, mu
+.word 0x018575d7
+
+# CHECK: <unknown>
+.word 0x01c575d7
+
+# CHECK: <unknown>
+.word 0x024575d7
+
+# CHECK: vsetvli a1, a0, e64, mf8, tu, mu
+.word 0x01d575d7
+
+# CHECK: vsetivli a1, 16, e8, m4, tu, mu
+.word 0xc02875d7
+
+# CHECK: <unknown>
+.word 0xc0c875d7
+
+# CHECK: <unknown>
+.word 0xc34875d7
+
+# CHECK: vsetivli a1, 16, e8, mf4, tu, mu
+.word 0xc06875d7
Index: llvm/lib/Target/RISCV/RISCVInstrInfoV.td
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfoV.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoV.td
@@ -28,7 +28,7 @@
 def VTypeIOp : Operand<XLenVT> {
   let ParserMatchClass = VTypeIAsmOperand;
   let PrintMethod = "printVTypeI";
-  let DecoderMethod = "decodeUImmOperand<11>";
+  let DecoderMethod = "decodeVTypeI";
 }
 
 def VMaskAsmOperand : AsmOperandClass {
Index: llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
===================================================================
--- llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -275,6 +275,15 @@
   return MCDisassembler::Success;
 }
 
+static DecodeStatus decodeVTypeI(MCInst &Inst, uint64_t Imm, int64_t Address,
+                                 const void *Decoder) {
+  // The encoding LMUL=4 is reserved and could be used for something
+  // completely different in the future.
+  if ((Imm & 7) == 4)
+    return MCDisassembler::Fail;
+  return decodeUImmOperand<11>(Inst, Imm, Address, Decoder);
+}
+
 template <unsigned N>
 static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint64_t Imm,
                                              int64_t Address,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114581.390296.patch
Type: text/x-patch
Size: 2162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211129/ccf57f1b/attachment.bin>


More information about the llvm-commits mailing list