[LLVMdev] Error handling in LLVMObject library

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Jun 1 11:54:29 PDT 2015


On 1 June 2015 at 13:48, Reid Kleckner <rnk at google.com> wrote:
> Is it possible to use the error-handling pattern that we use for frontends
> for libobject? Both clang and the .ll parser do this kind of thing:
>
> Result *ParserClass::doSomething() {
>   if (Thingy >= EndOfBuffer) {
>     reportError("some message");
>     return nullptr;
>   }
>   return ...;
> }
> void useit() {
>   Result *R = Parser.doSomething();
>   if (!R)
>     return;
>   ...
> }
>

I really like any solution that splits the error handling and the
diagnostic handling. The above clang snippet is one way to do it.
Closer by is llvm's DiagnosticHandler. It is used now in the bitcode
reader and has quite a few nice characteristics:

* We only need 2 error codes: InvalidBitcodeSignature, CorruptedBitcode.
* We can provide detailed diagnostics
* It is library friendly but still supports simple users that just
want fatal errors.

The one annoyance is that it is somewhat tied in lib/IR. We need to
refactor parts of it into lib/Support.

Cheers,
Rafael



More information about the llvm-dev mailing list