When I compile a piece of C++ with exceptions into .ll I see that gcc frontend in some cases calls __cxa_end_catch with 'call' and in other cases with 'invoke' with termination in case of exception. clang++ always just calls __cxa_end_catch with 'call' instruction. Which way is correct? --- c.cpp --- #include <stdio.h> #include <stdlib.h> struct C { C(); ~C(); }; struct E { E(); ~E(); }; void mythrowing1(); void mythrowing2(); void mycatching(E *e); void myfunc() { try { C c; mythrowing1(); mythrowing2(); } catch (E *e) { mycatching(e); } } --- commands --- /usr/local/llvm/2.7/bin/c++ -O3 -fexceptions -emit-llvm -S -o c-gcc.ll c.cpp /usr/local/llvm/2.7/bin/clang++ -O3 -fexceptions -emit-llvm -S -o c-clang.ll c.cpp
Duncan Sands
2010-Jul-12 07:23 UTC
[LLVMdev] clang/g++ frontend: can __cxa_end_catch throw?
Hi Yuri,> When I compile a piece of C++ with exceptions into .ll I see that gcc > frontend in some cases calls __cxa_end_catch with 'call' and in other > cases with 'invoke' with termination in case of exception. clang++ > always just calls __cxa_end_catch with 'call' instruction.IIRC, __cxa_end_catch may throw an exception because it runs the destructor for the exception object, which can execute arbitrary user code and thus may throw an exception. This is why it is sometimes correct to use invoke for it. However in the case of your example it seems that llvm-gcc didn't optimize the code as well as it might, since the invoke is redundant. Ciao, Duncan.
On 07/12/2010 00:23, Duncan Sands wrote:> IIRC, __cxa_end_catch may throw an exception because it runs the destructor > for the exception object, which can execute arbitrary user code and thus may > throw an exception. This is why it is sometimes correct to use invoke for it. > However in the case of your example it seems that llvm-gcc didn't optimize the > code as well as it might, since the invoke is redundant. >But there are cases when the outcomes will be different. In case of gcc frontend terminate() will be called when the original exception's destructor throws an exception and in case of clang Unwind_Resume_or_Rethrow will be called which is different. I think one of these cases must be an incorrect behavior. Yuri
Maybe Matching Threads
- [LLVMdev] clang/g++ frontend: can __cxa_end_catch throw?
- [LLVMdev] clang/g++ frontend: can __cxa_end_catch throw?
- [LLVMdev] clang/g++ frontend: can __cxa_end_catch throw?
- [LLVMdev] clang/g++ frontend: can __cxa_end_catch throw?
- [LLVMdev] Build of C++ project with clang++ fails (local symbol 1: discarded in section `xxx')