[PATCH] expose install_fatal_error_handler() through the C API

Andrew Trick atrick at apple.com
Wed Oct 16 17:49:09 PDT 2013


On Oct 16, 2013, at 4:46 PM, Filip Pizlo <fpizlo at apple.com> wrote:

> Hi!
> 
> If LLVM encounters badness it may call report_fatal_error().  The default behavior of this function is to call exit(1).  That doesn’t work out so great if LLVM is being used as a library in pretty much anything other than a command-line tool.  For example, if LLVM is in a daemon or in a UI app, calling exit(1) will bypass any stack trace or error reporting that the system would normally do for “fatal” conditions.
> 
> Hence being able to override the behavior of report_fatal_error(), like what install_fatal_error_handler() does, is critical enough that it should be exposed via the C API.
> 
> This patch does that.
> 
> I expose the API with some caveats:
> 
> - The C++ API involves a traditional void* opaque pointer for the fatal error callback.  The C API doesn’t do this.  I don’t think that the void* opaque pointer makes any sense since this is a global callback - there will only be one of them.  So if you need to pass some data to your callback, just put it in a global variable.
> 
> - The bindings will ignore the gen_crash_diag boolean.  I ignore it because (1) I don’t know what it does, (2) it’s not documented AFAIK, and (3) I couldn’t imagine any use for it.  I made the gut call that it probably wasn’t important enough to expose through the C API.

It is obvious we need to expose this API. LGTM.

I don’t know how important gen_crash_diag is. It looks like an IDE feature to me for failures that are not really the compiler’s fault. Unless someone else has an opinion, I’m ok leaving it out based on the very low probability of it ever being used.

-Andy



More information about the llvm-commits mailing list