[LLVMdev] RFC: Exception Handling Proposal II

me22 me22.ca at gmail.com
Sun Nov 28 20:11:25 PST 2010


On Sun, Nov 28, 2010 at 13:57, Bill Wendling <wendling at apple.com> wrote:
> In other words, this is completely valid code with proper semantics:
>
> #include <iostream>
> extern void foo();
> int main() {
>  int x = 0;
>  try {
>    x = 37 + 927;
>    foo();
>  } catch (...) {
>    std::cout << x << '\n';
>  }
> }
>
> Any solution that violates this isn't a solution.
>

The obvious direct translation of that is still fine:

    entry:
        %x = alloca
        store %x, 0
        br try

    try: unwind catch
        %t = add 37, 927
        store %x, %t
        call foo
        br after

    catch:
        %y = load %x
        ... print %y ...
        br after

Since the result of the store isn't used in the catch block (only the
side effect).  It would be up to mem2reg to split the try block when
removing the alloca, the same as it's currently up to mem2reg to add
the phi node in the after block.




More information about the llvm-dev mailing list