From: Eric Backus Subject: Re: -O and -O2 To: jon AT halsp DOT hitachi DOT com Date: Tue, 8 Dec 92 14:26:52 PST Cc: ESCHN705 AT RZ DOT Braunschweig DOT PTB DOT DBP DOT de, djgpp AT sun DOT soe DOT clarkson DOT edu, bug-gcc AT prep DOT ai DOT mit DOT edu Mailer: Elm [revision: 66.25] > The following was posted to the djgpp mailing list by > ESCHN705 AT RZ DOT Braunschweig DOT PTB DOT DBP DOT de > I tried it using gcc 2.2.2, running under Iteractive Unix version 2.2. > It produces errors of essentially the same kind as ESCHN705 reported. > > When compiled with option -O it produces (the program is named fail.c): > $ fail > 0 Bus error > > When compiled with option -O2 it produces: > $ fail > 0 1 Bus error > > This looks like a bug in gcc; but I don't have time to do more than > report it. I don't think so. As I pointed out to the original poster, this program sometimes uses a negative index into the array, thus probably overwriting some other local variable. > for (lact=0; lact <= maxdim; ++lact) > { printf("%2d ",lact); fflush(stdout); > for (lm=0; lm <= 2*lact; ++lm) > for (ln=0; ln <= 2*lact; ++ln) morg[lm][ln] = 0; > > for (lm=0; lm <= lact; ++lm) > { morg[lm][lm] = > morg[2*lact-lm][2*lact-lm] = > -0.5*((2*lm+1)*lact-lm*lm)*(alpha1+alpha2) - > (lact-lm)*(lact-lm)*alpha3; > morg[lm][2+lm] = morg[2+lm][lm] = > morg[2*lact-lm][2*(lact-1)-lm] = morg[2*(lact-1)-lm][2*lact-lm] = The problem is here ---------^ and here ---------^ > -0.25*sqrt((lm+1.0)*(lm+2.0)*(2.0*lact-lm)*(2.0*lact-1.0-lm)); > } > } When lact = 0 and lm = 0, the index is -2. When lact = 1 and lm = 1, the index is -1. In both cases, something gets overwritten. -- Eric Backus ericb AT lsid DOT hp DOT com (206) 335-2495