home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!dhinds
- From: dhinds@leland.Stanford.EDU (David Hinds)
- Subject: Optimization problem with 3.1 compilers
- Message-ID: <1992Aug19.000616.8590@leland.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: DSG, Stanford University, CA 94305, USA
- Date: Wed, 19 Aug 92 00:06:16 GMT
- Lines: 48
-
- I have a program that compiles and executes reliably with the MIPS 2.1
- compilers under Irix 4.0.1, but core dumps with a segmentation violation
- when a particular function is compiled at -O2 or above with the 3.1
- compilers and Irix 4.0.5A. Here is a short example with the problem:
-
- > #include <stdio.h>
- > #define MAXP 12
- >
- > void main(void)
- > {
- > int *i, *j, step[MAXP+1], k;
- > double sum;
- > float all2[MAXP+1];
- >
- > for (k = 0; k < MAXP+1; k++) {
- > step[k] = k; all2[k] = 2.0;
- > }
- >
- > sum = 0.0; k = 2;
- > for (i = &step[2]; i <= &step[MAXP]; i++, k++) {
- > printf("k = %d\n", k);
- > for (j = &step[1]; j != i; j++)
- > sum += all2[*j] - 1;
- > }
- > printf("Sum = %f\n", sum);
- > }
-
- When I compile this with 'cc -O2 bug.c' and run a.out, I get:
-
- > k = 2
- > k = 3
- > k = 4
- > k = 5
- > k = 6
- > Segmentation fault (core dumped)
-
- Compiled -O1, the program runs to completion (k=12). There are some
- funny interactions in the code: if I change 'sum' to float, then the
- -O2 code terminates "normally", but at k=7 instead of k=12. I can't
- see anything obviously wrong in the compiler output, but reading MIPS
- assembly language gives me a headache. I'm reasonably confident that
- there are no bugs in this code fragment, and the program it is based
- on works reliably on several other platforms (including SGI's with
- pre-3.1 compilers).
-
- - David Hinds
- dhinds@allegro.stanford.edu
-
-