🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #53217

Re: SUMMARY: egregious Sun optimizer bug

#53217
From: Manavendra K. Thakur
Date: Sat, 07 Mar 1992 08:15
59 lines
2299 bytes
Jay Plett <jay@princeton.edu> writes the following to the sun-managers
mailing list:

> One of my users found a bug in the Sun optimizer.  The bug can cause
> programs to perform incorrectly with no indication of failure.

[...]

> Incidentally, the bug is also present in older versions of gcc.


I have verified that gcc 2.0 with all optimizations turned on (-O2
-funroll-all-loops) does indeed handle your sample code correctly, at
least on a sparc machine running SunOS 4.1.1:

     zerkalo% cat testme.c
     #include <stdio.h>

     main()
     {
	     int     m, n, p;
	     int     mhold;
	     int     clunk;

     #ifdef NOBUG
	     clunk = &mhold - &m;
     #endif
	     p = 1;
	     for (m = 1; m <= 2; m++)
		     for (n = 1; n <= 2; n++, p++)
		     {       if (p == 1)
			     {       mhold = m;
				     printf("(p==1)");
			     }
			     printf("\tp=%d, mhold=%d, m=%d\n", p, mhold, m);
		     }
     }


     zerkalo% gcc -O2 -funroll-all-loops testme.c
     zerkalo% ./a.out
     (p==1)  p=1, mhold=1, m=1
	     p=2, mhold=1, m=1
	     p=3, mhold=1, m=2
	     p=4, mhold=1, m=2
     zerkalo%


According to your mail message, this is indeed the correct output.

So gcc 2.0 users, relax!  Your optimizer is doing the right thing!

I also checked gcc 1.40 on sparc and SunOS 4.1.1.  This too produces
the correct output, with -O specified as the optimize switch.

Manavendra K. Thakur			 Internet: thakur@zerkalo.harvard.edu
Systems Programmer, High Energy Division BITNET:   thakur@cfa.BITNET
Harvard-Smithsonian Center for		 DECNET:   CFA::thakur
Astrophysics				 UUCP:	   ...!uunet!mit-eddie!thakur
Technical Details
Message-ID: <9203070815.AA26886@zerkalo.harvard.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zerkalo.harvard.edu!thakur
References: <9203070519.AA25407@silence.princeton.nj.us>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,f397c0a3e96707c9,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-03-07 07:15:00 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zerkalo.harvard.edu!thakur
From: thakur@zerkalo.harvard.edu (Manavendra K. Thakur)
Subject: Re: SUMMARY: egregious Sun optimizer bug
Message-ID: <9203070815.AA26886@zerkalo.harvard.edu>
Sender: daemon@cis.ohio-state.edu
Organization: GNUs Not Usenet
References: <9203070519.AA25407@silence.princeton.nj.us>
Distribution: gnu
Date: Sat, 7 Mar 1992 08:15:40 GMT
Lines: 59