[PATCH] D51705: [RISCV] Fix crash in decoding instruction with unknown floating point rounding mode
Ana Pazos via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 7 11:46:08 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341691: [RISCV] Fix crash in decoding instruction with unknown floating point rounding… (authored by apazos, committed by ).
Herald added subscribers: llvm-commits, jrtc27.
Changed prior to commit:
https://reviews.llvm.org/D51705?vs=164479&id=164482#toc
Repository:
rL LLVM
https://reviews.llvm.org/D51705
Files:
llvm/trunk/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
llvm/trunk/lib/Target/RISCV/RISCVInstrInfoF.td
llvm/trunk/test/MC/Disassembler/RISCV/invalid-fp-rounding-mode.txt
Index: llvm/trunk/lib/Target/RISCV/RISCVInstrInfoF.td
===================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVInstrInfoF.td
+++ llvm/trunk/lib/Target/RISCV/RISCVInstrInfoF.td
@@ -27,7 +27,7 @@
def frmarg : Operand<XLenVT> {
let ParserMatchClass = FRMArg;
let PrintMethod = "printFRMArg";
- let DecoderMethod = "decodeUImmOperand<3>";
+ let DecoderMethod = "decodeFRMArg";
}
//===----------------------------------------------------------------------===//
Index: llvm/trunk/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
===================================================================
--- llvm/trunk/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ llvm/trunk/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "MCTargetDesc/RISCVBaseInfo.h"
#include "MCTargetDesc/RISCVMCTargetDesc.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -243,6 +244,17 @@
return MCDisassembler::Success;
}
+static DecodeStatus decodeFRMArg(MCInst &Inst, uint64_t Imm,
+ int64_t Address,
+ const void *Decoder) {
+ assert(isUInt<3>(Imm) && "Invalid immediate");
+ if (!llvm::RISCVFPRndMode::isValidRoundingMode(Imm))
+ return MCDisassembler::Fail;
+
+ Inst.addOperand(MCOperand::createImm(Imm));
+ return MCDisassembler::Success;
+}
+
#include "RISCVGenDisassemblerTables.inc"
DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Index: llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
===================================================================
--- llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ llvm/trunk/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -104,6 +104,21 @@
.Case("dyn", RISCVFPRndMode::DYN)
.Default(RISCVFPRndMode::Invalid);
}
+
+inline static bool isValidRoundingMode(unsigned Mode) {
+ switch (Mode) {
+ default:
+ return false;
+ case RISCVFPRndMode::RNE:
+ case RISCVFPRndMode::RTZ:
+ case RISCVFPRndMode::RDN:
+ case RISCVFPRndMode::RUP:
+ case RISCVFPRndMode::RMM:
+ case RISCVFPRndMode::DYN:
+ return true;
+ }
+}
+
} // namespace RISCVFPRndMode
} // namespace llvm
Index: llvm/trunk/test/MC/Disassembler/RISCV/invalid-fp-rounding-mode.txt
===================================================================
--- llvm/trunk/test/MC/Disassembler/RISCV/invalid-fp-rounding-mode.txt
+++ llvm/trunk/test/MC/Disassembler/RISCV/invalid-fp-rounding-mode.txt
@@ -0,0 +1,9 @@
+# RUN: not llvm-mc -disassemble -triple=riscv32 -mattr=+f,+d < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -disassemble -triple=riscv64 -mattr=+f,+d < %s 2>&1 | FileCheck %s
+#
+# Test generated by a LLVM MC Disassembler Protocol Buffer Fuzzer
+# for the RISC-V assembly language.
+
+# This decodes as fadd.s ft0, ft0, ft0 with unknown floating point rounding mode
+[0x53 0x50 0x00 0x00]
+# CHECK: warning: invalid instruction encoding
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51705.164482.patch
Type: text/x-patch
Size: 3109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180907/46f41f8e/attachment.bin>
More information about the llvm-commits
mailing list