Bug 38466

Summary: g++ segfaults when compiling with -O2
Product: [Retired] Red Hat Linux Reporter: bastiaan
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: high Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-05-02 11:43:40 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.