[LLVMdev] Using asserts in LLVM

Gordon Henriksen gordonhenriksen at mac.com
Wed Jun 18 11:10:36 PDT 2008

This is the right way to go about this.

> I would like LLVM to raise an exception which the python wrapper  
> could catch and pass to my program. I know that the current LLVM  
> code does not use exceptions. Also, the current stl "cassert.h"  
> implementation is sufficient for 99% of the developers which write C+ 
> + code. [...] Another way would be to get around this is to place a  
> hook over 'abort' in runtime. This is ugly as sin and may not always  
> work.

LLVM does not use exceptions. This is in order to reduce footprint,  
and since there are no valid failure cases for 95%+ of the compiler  
anyhow. Given that there are no exception tables, there is no way to  
safely unwind the stack and recover from a failure; assert has no  
option but to abort the program.

> Would you consider changing the implementation of 'assert' so that  
> it would throw exceptions rather then abort the program ?

No, sorry.

> One way of solving this is to rewrite all of the asserts in Python  
> before calling the C++ code. This means  duplication of a ton of code.

Aside from writing correct programs :), this is the best option.

— Gordon

More information about the llvm-dev mailing list