How do you get LLVM methods to return or throw an error to the caller's code rather than aborting the process? I'd like my compiler to be able to print diagnostic messages, including language source lines, whenever LLVM reports a problem.
On Aug 19, 2009, at 9:02 AM, Kenneth Uildriks wrote:> How do you get LLVM methods to return or throw an error to the > caller's code rather than aborting the process? I'd like my compiler > to be able to print diagnostic messages, including language source > lines, whenever LLVM reports a problem.Hi Kenneth, Recoverable errors are handled with llvm/Support/ErrorHandling.h. We use asserts for conditions that "cannot happen". These are internal errors and are not recoverable. The best way to not get one of these is for your compiler to not have bugs :) -Chris
On Aug 19, 2009, at 9:02 AM, Kenneth Uildriks wrote:> How do you get LLVM methods to return or throw an error to the > caller's code rather than aborting the process? I'd like my compiler > to be able to print diagnostic messages, including language source > lines, whenever LLVM reports a problem.Do you mean things like assert() and abort() calls? Those are abnormal situations and internal compiler errors, not indicators of a problem in the user's source. If you really want to catch them and do something, you could install a signal handler for SIGABRT, I suppose, and do whatever you want there. Regards, Jim
Please email llvmdev, not me directly. On Aug 19, 2009, at 9:37 AM, Kenneth Uildriks wrote:> So things like type mismatches, missing return statements, and whatnot > count as "internal errors"? I guess that makes sense... I'll just > have to do those check on my side then.Yes. The IR has to be well formed by your frontend. -Chris> > On Wed, Aug 19, 2009 at 11:29 AM, Chris Lattner<clattner at apple.com> > wrote: >> >> On Aug 19, 2009, at 9:02 AM, Kenneth Uildriks wrote: >> >>> How do you get LLVM methods to return or throw an error to the >>> caller's code rather than aborting the process? I'd like my >>> compiler >>> to be able to print diagnostic messages, including language source >>> lines, whenever LLVM reports a problem. >> >> Hi Kenneth, >> >> Recoverable errors are handled with llvm/Support/ErrorHandling.h. >> We use >> asserts for conditions that "cannot happen". These are internal >> errors and >> are not recoverable. The best way to not get one of these is for >> your >> compiler to not have bugs :) >> >> -Chris >>
On 19/08/2009, at 18.42, Chris Lattner wrote:> Please email llvmdev, not me directly.I have done that too recently. Did Mailman stop setting the ReplyTo header?
On Wednesday 19 August 2009 11:29, Chris Lattner wrote:> On Aug 19, 2009, at 9:02 AM, Kenneth Uildriks wrote: > > How do you get LLVM methods to return or throw an error to the > > caller's code rather than aborting the process? I'd like my compiler > > to be able to print diagnostic messages, including language source > > lines, whenever LLVM reports a problem. > > Hi Kenneth, > > Recoverable errors are handled with llvm/Support/ErrorHandling.h. We > use asserts for conditions that "cannot happen". These are internal > errors and are not recoverable. The best way to not get one of these > is for your compiler to not have bugs :)We're dealing with this, but it's not a particularly friendly way to operate. Most compilers have some kind of error reporting mechanism and it would be helpful if LLVM provided a way to turn asserts and aborts into hooks that could be plugged into an existing infrastructure. Signal handlers aren't the best solution. Like I said, we're dealing with it but it's something we should be aware of long-term. -Dave