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++/103: Re: egcs-19990714 C++ -O Creates Wrong Code on SPARC



>Number:         103
>Category:       c++
>Synopsis:       egcs-19990714 C++ -O Creates Wrong Code on SPARC
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          analyzed
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 13 00:26:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Michael Arras <arras@intertv.com>
>Release:        2.95.2
>Organization:
>Environment:
>Description:
 Original-Message-ID: <378E3F17.77A12491@intertv.com>
 Date: Thu, 15 Jul 1999 16:05:43 -0400


 // The following C++ program demonstrates a bug in egcs-1990714
 // and egcs-1.1.2 on Solaris 2.5, 2.6 and 7 SPARC.
 //
 // To see bug compile with `g++ -O optbug.cxx'.  The output
 // should be "Catch 0" 4 times.  "Catch 1" should never be
 // printed.
 //
 // The bug does not occur with egcs compiled on IRIX 6.5 MIPS or
 // Linux 2.2 x86.
 //
 // When compiled with -O(1-3), value is set to true, even though
 // f2() always throws an exception.
 //
 // When compiled with -O3 -fno-delayed-branch (or no optimization
 // at all) the program works as it should.
 //
 // The loop and "++odd %2" are there so egcs does not optimize the
 // bug out.  The bug was discovered in production code.

 #include <iostream>
 #include <exception>

 int odd = 0;

 void f1(void) throw(exception)
 {
     if (++odd % 2)
	 throw exception();
 }

 void f2(void) throw(exception)
 {
     throw exception();     // Always
 }

 main(int c, char **v)
 {
     for (int i = 0; i < 4; i++)
     {
	 bool value = false;

	 try
	 {
	     f1();
	     f2();
	     // Should never get here
	     value = true;
	     cout << "Try ";
	 }
	 catch (...)
	 {
	     cout << "Catch ";
	 }

	 // value should never be true
	 cout << value << endl;
     }
 }

 [MvL retested with 2.95.2, 2.96 20000228]

>How-To-Repeat:
>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]