From Bugzilla Helper: User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.2-2 i686) g++ segfaults when compiling with '-O2'. Without optimization or with '-O', it compiles without problems. Reproducible: Always Steps to Reproduce: 1. cat << EOF > crashme.cc void someFunction(); struct ClassA { inline ClassA(int dummy) { someFunction(); }; inline ~ClassA() { try { someFunction(); } catch (...) { } }; }; struct ClassB { void methodA(bool flag); void methodB(); static ClassB* instance() { int dummy; ClassA classA(dummy); return (ClassB*)0; }; }; void ClassB::methodA(bool flag) { instance()->methodB(); } EOF 2. g++ -O2 crashme.cc Actual Results: $ g++ -O2 -c crash.cc crash.cc: In method `void ClassB::methodA (bool)': crash.cc:25: Internal error: Segmentation fault. Please submit a full bug report. See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions. Expected Results: It should have been compiled without any errors. $ g++ -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
The example I gave can be shortened to only 5 lines with the same results: struct CrashMe { CrashMe* self() { try { return this; } catch(...) {} }; void nuke(); }; void CrashMe::nuke() { self()->nuke(); }
Yeah, I've simplified it similarly. It is a sibling call optimization issue wrt. exception handling, compiling with -O2 -fno-optimize-sibling-calls should work. I'm debugging it ATM.
Should be fixed by http://gcc.gnu.org/ml/gcc-patches/2001-05/msg00082.html I'll put it into gcc-c++-2.96-83 if it passes all the tests.