[LLVMdev] How to handle divide-by-zero exception?

Mike Stump mrs at apple.com
Sat May 10 17:14:10 PDT 2008


On May 8, 2008, at 7:17 PM, Talin wrote:
> Currently it states in the language manual that the results of  
> division
> by zero are undefined. However, I'm curious as to how you would  
> normally
> handle either divide by zero or other "hardware" exceptions (null
> pointer dereference and so on) and turn them into LLVM exceptions.

See Java and Ada in gcc for an example of how this is done.   
Essentially, you install a trap handler on the OS for the traps your  
interested in and have them create an exception.  The inline code is  
`normal', no special funniness to it, other than exception tables and  
unwind tables that explain what to do.  This scheme can even be made  
to work for asynchronous events as well.



More information about the llvm-dev mailing list