[PATCH] D73958: [AVR] Don't assert on an undefined operand

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 05:50:36 PST 2020


aykevl updated this revision to Diff 242574.
aykevl added a comment.

Added comments, as requested.

I agree, this makes it clearer why this check is there in the first place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73958

Files:
  llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp


Index: llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
===================================================================
--- llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
+++ llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.cpp
@@ -100,6 +100,16 @@
 
 void AVRInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
                                   raw_ostream &O) {
+  if (OpNo >= MI->size()) {
+    // Not all operands are correctly disassembled at the moment. This means
+    // that some machine instructions won't have all the necessary operands
+    // set.
+    // To avoid asserting, print <unknown> instead until the necessary support
+    // has been implemented.
+    O << "<unknown>";
+    return;
+  }
+
   const MCOperand &Op = MI->getOperand(OpNo);
   const MCOperandInfo &MOI = this->MII.get(MI->getOpcode()).OpInfo[OpNo];
 
@@ -125,6 +135,16 @@
 /// being encoded as a pc-relative value.
 void AVRInstPrinter::printPCRelImm(const MCInst *MI, unsigned OpNo,
                                    raw_ostream &O) {
+  if (OpNo >= MI->size()) {
+    // Not all operands are correctly disassembled at the moment. This means
+    // that some machine instructions won't have all the necessary operands
+    // set.
+    // To avoid asserting, print <unknown> instead until the necessary support
+    // has been implemented.
+    O << "<unknown>";
+    return;
+  }
+
   const MCOperand &Op = MI->getOperand(OpNo);
 
   if (Op.isImm()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73958.242574.patch
Type: text/x-patch
Size: 1464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200205/7375daaa/attachment.bin>


More information about the llvm-commits mailing list