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

Duncan Sands baldrick at free.fr
Sat May 10 14:07:00 PDT 2008


Hi,

> What about logically breaking a (complex) SEH method into two logical
> methods, as per this pseudo-code as an example:
> 
> -----------------------
> 
> foo(parameter-list)
> {
>   leading-statements;
> 
>   try {
>     try-statements;
>   }
>   catch(Execption0 ex0) {
>     catch-0-statements;
>   }
>   .
>   catch(ExceptionN exN) {
>     catch-n-statements;
>   }
>   finally {
>     final-statemements
>   }
> 
>   tail-statements;
> } 

LLVM is completely "flat" - it has no local blocks at all.
So a big part of exception handling is flattening this kind
of code when outputting LLVM IR (which seems to be more or
less what you are suggesting).  This is done by llvm-g++ for
example.  Try compiling some C++ code with try-catch-finally
blocks with llvm-g++ with -S -emit-llvm -o - to see what I
mean.  Inevitably flattening occurs before LLVM even sees
the code, since there is no direct way of representing nested
blocks in LLVM.

Ciao,

Duncan.



More information about the llvm-dev mailing list