Bug 19543 - G++ Generates incorrect code
G++ Generates incorrect code
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
high Severity high
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-10-22 07:22 EDT by Need Real Name
Modified: 2005-10-31 17:00 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-10-24 09:07:33 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2000-10-22 07:22:53 EDT
(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 03:53:47 EDT
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 07:10:47 EDT
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 09:07:30 EDT
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.