Bug 19543

Summary: G++ Generates incorrect code
Product: [Retired] Red Hat Linux Reporter: Need Real Name <oneill>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: high Docs Contact:
Priority: high    
Version: 7.0   
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: 2000-10-24 13:07:33 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 Need Real Name 2000-10-22 11:22:53 UTC
(Checked for gcc-2.96-54, gcc-2.96-60 and CVS mainline gcc version 2.97
20001009 (experimental), but not a bug in 2.95.2)

The enclosed code (which is little more than a "Hello World" program)
generates incorrect code when compiled with -O2.  For some reason,
g++ is generating code that tramples that function arguments.
Because the code doesn't seem to be particularly unusual or arcane,
this seems like a very serious bug.

rh7% g++ -O -o not-buggy buggy.cc && ./not-buggy
* Shouldn't segfault *
rh7% g++ -O2 -DAVOID_BUG -o not-buggy buggy.cc && ./not-buggy
* Shouldn't segfault *
rh7% g++ -O2 -o buggy buggy.cc && ./buggy
Segmentation fault

I hope this one won't be too hard to find and fix...

    M.E.O.

Enc.

#include <iostream>

ostream& put (char * str, ostream& out) {
    #if !AVOID_BUG
	return out << "* " << str << " *\n";
    #else
	out << "* " << str << " *\n";
	return out;
    #endif
}

int main () {
    put("Shouldn't segfault", cout);
}

Comment 1 Jakub Jelinek 2000-10-23 07:53:47 UTC
Reproduced (it works well even with -O2 -fno-schedule-insns2), looking into it.
Seems like it is scheduled wrongly after reload.

Comment 2 Jakub Jelinek 2000-10-23 11:10:47 UTC
Actually, it was related to sibling call optimization (-fno-optimize-sibling-calls
also cured it).
I've submitted a fix to gcc-patches, am waiting for peer review.

Comment 3 Jakub Jelinek 2000-10-24 13:07:30 UTC
Commited into CVS head, is fixed in gcc-2.96-61.