[LLVMdev] "LLVM as a library" and signaling failures other than crashing

Mehdi Amini mehdi.amini at apple.com
Thu Jun 4 14:58:15 PDT 2015


Hi all,

LLVM, in the absence of exception, does not have currently any way of signaling error other than crashing (the client can register a handler but abort() is always called anyway.

For a user trying to use LLVM “as a library” (for JIT for instance), it seems a bit hostile to me to have to fork a process every time I want to make use of a library. 
Of course some errors might not be recoverable if the internal data structure are corrupted, but that should be the exception. Having the register allocator running out of registers/spill space should not need to tear down the whole process.
In general, I’d rather leave up to the client the decision on what to do on error. For instance the JIT javascript client can discard the compilation failure.

Since a new PassManager is being brought up (CC Chandler), I figured it might be a good time to raise this concern since the PassManager sits in the middle. 
A potential solution would be to have the ability for passes to return a “status” when run(). The PassManager can then early exit from the pipeline on errors from a Pass and propagate the status to the client as well.

To bring this up, Passes can be changed to always return a status “success”, which would match the existing behavior. We could then progressively wire places where report_fatal_error() is called to return an error instead.

Any thoughts/interest in evolving this aspect of LLVM?

Best,

— 
Mehdi





More information about the llvm-dev mailing list