This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/6189: Regression from 3.0.x: g++ -O3 generates wrong code



>Number:         6189
>Category:       optimization
>Synopsis:       Regression from 3.0.x: g++ -O3 generates wrong code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 05 07:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Volker Reichelt
>Release:        gcc version 3.1 20020325 (prerelease)
>Organization:
>Environment:
i686-pc-linux-gnu, mips-sgi-irix6.5
>Description:
The following small C++-program should return 1,
but compiling the code with "g++ -O3" I get 0 as a result.

----------------------------snip here---------------------
class A
{
  private:
    int x[2];

  public:
    int& GetFirst() { return x[0]; }
};


A foo ()
{ 
    A a;
    a.GetFirst()=1;
    return a;
}


int main()
{
    A b=foo();
    return b.GetFirst();
}
----------------------------snip here---------------------

With less optimization the problem disappears.
It even disappears when I replace "private" by "public".

The bug is a regression from gcc 3.0.x.
>How-To-Repeat:
g++ -O3 bug.cpp; a.out; echo $?
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]