[PATCH] D44685: [AMDGPU] Improve disassembler error handling

Tim Corringham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 21 07:57:55 PDT 2018


timcorringham added inline comments.


================
Comment at: lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp:250
+  // if the opcode was not recognized we'll assume a Size of 4 bytes
+  Size = Res ? (MaxInstBytesNum - Bytes.size()) : 4;
   return Res;
----------------
This should return the minimum of 4 or the number of bytes remaining if the disassembly failed.


================
Comment at: tools/llvm-objdump/llvm-objdump.cpp:611
+      OS << format("\t.long 0x%08" PRIx32 " ",
+                   static_cast<uint32_t>(*reinterpret_cast<const U32*>(Bytes.data())));
+      OS.indent(42);
----------------
artem.tamazov wrote:
> What if there are less than 4 bytes left? Let's make sure that we are not getting into undefined behavior in such a case.
Currently there is code in DisassembleObject() - line 1475 - that truncates the section to a multiple of 4 bytes, so we won't encounter the case of having fewer than 4 bytes left here.
However, maybe we should rethink that behaviour as it would be possible for data to be  deliberately added to the end of a section that resulted in a non-multiple-of-4 length, and we could cope with that in the disassembly by using .byte directives.


Repository:
  rL LLVM

https://reviews.llvm.org/D44685





More information about the llvm-commits mailing list