[PATCH] [PATCH] Proposed alternative to llvm::format()

kledzik at apple.com kledzik at apple.com
Wed Sep 17 19:34:34 PDT 2014


Hi rafael, silvas,

In using llvm::format() to dump columnar tables of data in my recent enhancements to llvm-objdump, I ran into some issues uncovered by the built bots that show how unsafe llvm::format() is.  The issues I hit where that the compiler did not check that %x match the integer size and that %s can match a StringRef but produce the wrong output.  %s is also ugly with StringRef values because you have to convert to a std::string then call c_str().

All I really needed was a way to generate fixed with hexadecimal (e.g. 0x00001234) and fixed with strings (e.g. right or left justified strings in a column).  I whipped up an alternative that is easy to use with the stream operator and generates fixed with output.  

If there is interest in this, I can clean it up and add some test cases.  Or perhaps there already is some good technique for fixed width formatting.  This patch also contains examples changes in llvm-objdump to use this new functionality.

http://reviews.llvm.org/D5390

Files:
  include/llvm/Support/Format.h
  include/llvm/Support/raw_ostream.h
  lib/Support/raw_ostream.cpp
  tools/llvm-objdump/MachODump.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5390.13817.patch
Type: text/x-patch
Size: 7946 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140918/844e08c2/attachment.bin>


More information about the llvm-commits mailing list