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]

c++/104: Re: C++ optimization error



>Number:         104
>Category:       c++
>Synopsis:       C++ optimization error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          analyzed
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 13 01:05:59 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Mark van Doesburg <m.j.s.vandoesburg@student.utwente.nl>
>Release:        2.95.2
>Organization:
>Environment:
>Description:
 Date: Thu, 12 Aug 1999 00:04:25 +0200
 Original-Message-Id: <199908112204.AAA01573@poekie.test>

 The attached program compiles correctly without optimization. With
 optimizations the resulting a.out gives a segmentation fault.

 System:
 i586-pc-linux-gnulibc1, AMD k6-2, linux-2.2.11, libc-5.4.46

 gcc:
 Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/2.95.1/specs
 gcc version 2.95.1 19990809 (prerelease)
 (It also happens in gcc-2.95)

 Correct options: gcc test.ii
 Error options: gcc -O test.ii

 greetings,

 Mark.

 ---- original program ----------------------------------------------------

 #include <matrix.h>

 main()
 {
	 matrix<fract,3> M;		// when fract is changed to double
					 // a.out doesn't core dump with -O
	 M[0][0]=M[1][1]=M[2][2]=1;
	 M[0][1]=M[0][2]=M[1][0]=M[1][2]=M[2][0]=M[2][1]=0;
 }

 [MvL: The original report had a large preprocessor output attached, below
  is a simplified version that still generates wrong code in 2.96 20000309]
>How-To-Repeat:
class fract {
	int d; 
public:
	fract &operator=(fract f) { d=f.d; }
	fract &operator=(int f) { d=f; }
};


template<class T,int S> 
class coord {
	T c[S];
public: 
	T &operator[](int i) { return c[i]; }
};

main()
{
	coord<fract,2> M;
	M[0]=M[1]=1;
}
>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]