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

Artem Tamazov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 23 06:46:39 PDT 2018


artem.tamazov added inline comments.


================
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);
----------------
dp wrote:
> timcorringham wrote:
> > 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.
> Could you add an assert?
> 
>   assert(Bytes.size() % sizeof(U32) == 0);
> 
> With this assert the assumption about section length will be clear. A relevant comment would be helpful too.
I am second to this. Let's make our assumptions (specifically, an assumption that DisassembleObject() truncates the section to a multiple of 4 bytes) **expliicit**.


Repository:
  rL LLVM

https://reviews.llvm.org/D44685





More information about the llvm-commits mailing list