[PATCH] error_code for dynamically generated error messages

kledzik at apple.com kledzik at apple.com
Thu May 22 15:40:15 PDT 2014


Hi Bigcheese, ruiu, shankarke, atanasyan, silvas,

This proposed patch adds a new kind of error_code, one which allows arbitrary
message strings.

error_code is based on the model that errors are enumerable and you may want
to programmatically handle when some function called fails with some specific
error_code.

lld uses ErrorOr<> extensively which is based on error_code.  But the errors
that arise when parsing .o files or linking them are not usefully enumerable.
That is, there is nothing that can be programmatic done and you really want
an error message richer than “bad object format”.  For instance, a richer
message might be “relocation 14 contains invalid relocation type (23)”.

This patch creates a subclass of error_category which dynamically associcates
a value and string.  I hope this is not bending the error_code model too much.
If the idea is good, should this be pushed down from lld into llvm/Support?

As an example usage, I updated lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
to use make_dynamic_error_code().

http://reviews.llvm.org/D3881

Files:
  include/lld/Core/Error.h
  lib/Core/Error.cpp
  lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3881.9719.patch
Type: text/x-patch
Size: 5129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140522/5cfac09d/attachment.bin>


More information about the llvm-commits mailing list