User account creation filtered due to spam.

Bug 6189 - Regression from 3.0.x: g++ -O3 generates wrong code
Summary: Regression from 3.0.x: g++ -O3 generates wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-04-05 07:56 UTC by Volker Reichelt
Modified: 2003-07-25 17:33 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2002-04-05 07:56:00 UTC
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.

Release:
gcc version 3.1 20020325 (prerelease)

Environment:
i686-pc-linux-gnu, mips-sgi-irix6.5

How-To-Repeat:
g++ -O3 bug.cpp; a.out; echo $?
Comment 1 Jason Merrill 2002-04-09 17:02:00 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6189
Date: 9 Apr 2002 17:02:00 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2002-04-09 10:02:00
 
 Modified files:
 	gcc/cp         : ChangeLog semantics.c 
 
 Log message:
 	PR optimization/6189
 	* semantics.c (genrtl_start_function): Don't free
 	DECL_SAVED_FUNCTION_DATA for inline functions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2763&r2=1.2764
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.258&r2=1.259
 

Comment 2 Jason Merrill 2002-04-09 17:02:33 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6189
Date: 9 Apr 2002 17:02:33 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_1-branch
 Changes by:	jason@gcc.gnu.org	2002-04-09 10:02:33
 
 Modified files:
 	gcc/cp         : ChangeLog semantics.c 
 
 Log message:
 	PR optimization/6189
 	* semantics.c (genrtl_start_function): Don't free
 	DECL_SAVED_FUNCTION_DATA for inline functions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_1-branch&r1=1.2685.2.47&r2=1.2685.2.48
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_1-branch&r1=1.252.2.3&r2=1.252.2.4
 

Comment 3 Jason Merrill 2002-04-09 17:02:43 UTC
From: jason@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/6189
Date: 9 Apr 2002 17:02:43 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	jason@gcc.gnu.org	2002-04-09 10:02:43
 
 Added files:
 	gcc/testsuite/g++.dg/opt: nrv3.C 
 
 Log message:
 	PR optimization/6189
 	* semantics.c (genrtl_start_function): Don't free
 	DECL_SAVED_FUNCTION_DATA for inline functions.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/nrv3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 

Comment 4 Jason Merrill 2002-06-10 15:06:07 UTC
From: Jason Merrill <jason@redhat.com>
To: Reichelt <reichelt@igpm.rwth-aachen.de>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: optimization/6189: Regression from 3.0.x: g++ -O3 generates
 wrong code
Date: Mon, 10 Jun 2002 15:06:07 +0100

 >>>>> "Reichelt" == Reichelt  <reichelt@igpm.rwth-aachen.de> writes:
 
 > Is there any reason why you did not close the PR? The problem seems to
 > be fixed in gcc 3.1 as well as in mainline (gcc 3.2 20020610).
 
 Because I thought we might want to fix it in a hypothetical 3.0.5 release.
 
 Jason
Comment 5 Volker Reichelt 2002-06-10 15:25:24 UTC
From: Reichelt <reichelt@igpm.rwth-aachen.de>
To: jason@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: optimization/6189: Regression from 3.0.x: g++ -O3 generates wrong code
Date: Mon, 10 Jun 2002 15:25:24 +0200

 Hi Jason,
 
 thanks for fixing the bug.
 
 Is there any reason why you did not close the PR? The problem seems to
 be fixed in gcc 3.1 as well as in mainline (gcc 3.2 20020610).
 
 By the way, the link for the new testcase
   http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/nrv3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
 doesn't work (at least not for me). However, the following works fine:
   http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/nrv3.C?rev=1.1
 Could you please update it?
 
 Greetings,
 Volker Reichelt
 
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6189
 
 

Comment 6 Volker Reichelt 2002-10-28 13:22:20 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed.