Bug 19543 - G++ Generates incorrect code
Summary: G++ Generates incorrect code
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
high
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-10-22 11:22 UTC by Need Real Name
Modified: 2005-10-31 22:00 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-10-24 13:07:33 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2000:132 0 normal SHIPPED_LIVE Bug fixing update of GCC 2.96 2000-12-19 05:00:00 UTC

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.


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