Bug 38466 - g++ segfaults when compiling with -O2
Summary: g++ segfaults when compiling with -O2
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-04-30 21:51 UTC by bastiaan
Modified: 2007-04-18 16:32 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-05-02 11:43:40 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2001:082 0 high SHIPPED_LIVE New version of GCC 2.96-RH available fixing several bugs 2001-06-14 04:00:00 UTC

Description bastiaan 2001-04-30 21:51:47 UTC
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)

Comment 1 bastiaan 2001-05-01 23:34:19 UTC
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 08:53:40 UTC
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 11:43:35 UTC
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.