Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 38466 - g++ segfaults when compiling with -O2
g++ segfaults when compiling with -O2
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2001-04-30 17:51 EDT by bastiaan
Modified: 2007-04-18 12:32 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-05-02 07:43:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2001:082 high SHIPPED_LIVE New version of GCC 2.96-RH available fixing several bugs 2001-06-14 00:00:00 EDT

  None (edit)
Description bastiaan 2001-04-30 17:51:47 EDT
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 {
        } 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) {

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)
Comment 1 bastiaan 2001-05-01 19:34:19 EDT
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(); }
Comment 2 Jakub Jelinek 2001-05-02 04:53:40 EDT
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.
Comment 3 Jakub Jelinek 2001-05-02 07:43:35 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.