Possible gcc bug?

3 messages, 2 authors, 2000-06-11 · open the first message on its own page

Possible gcc bug?

From: Geoff Hutchison <hidden>
Date: 2000-06-11 05:03:26

Before I send this message off to gcc-bugs, I wanted to check with
the list to see if it's a problem with the particular gcc RPM I'm
using (Franz's latest of gcc-2.95.3-2a.src.rpm). I also need to pare
the code down a bit more to see if I can come up with a smaller
testcase.

       When compiled with optimization, x and y loops run correctly
           gcc -O -o loop-bug loop-bug.c -lm
       When compiled WITHOUT optimization, x and y loops run incorrectly
           gcc -o loop-bug loop-bug.c -lm

Here's the problem. I'm doing some numerical calculations and main
loop isn't being executed! It seems like something is clobbering one
of my const declarations internally. There are other strange problems
with other parts of my original code when optimization is turned on,
but I'd rather one step at a time.

If I'm being a complete moron and doing something silly, please let
me know and I'll eat my words.

Thanks,

Re: Possible gcc bug?

From: Martin Costabel <hidden>
Date: 2000-06-11 11:00:01

Geoff Hutchison wrote:
If I'm being a complete moron and doing something silly, please let
me know and I'll eat my words.
I think you do: You are passing over the array bounds. If I remember my
C basics (which I never really learned either) correctly,

double field[loopX][loopY];

allows indices running from 0 to loopX-1 and from 0 to loopY-1.

In your first loop

  /* Initialize arrays */
  for (x = 0; x <= loopX; x++)
    for (y = 0; y <= loopY; y++)
      {
      	field[x][y] = 0.0;
	points[maxX * x + y].ptX = x;
	points[maxX * x + y].ptY = y;
      }

you are clobbering random memory locations that may be different for
different compiler optimisation levels.

Replace "<=" by "<", and your errors will go away.

--
Martin

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

Re: Possible gcc bug?

From: Geoff Hutchison <hidden>
Date: 2000-06-11 14:08:14

At 1:00 PM +0200 6/11/00, Martin Costabel wrote:
I think you do: You are passing over the array bounds. If I remember my
C basics (which I never really learned either) correctly,

double field[loopX][loopY];
Doh! Yes, as I said, I'll eat my words. This should fix things.

Thanks,

--
-Geoff Hutchison
Williams Students Online
http://wso.williams.edu/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help