home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / sgi / 12573 < prev    next >
Encoding:
Text File  |  1992-08-18  |  1.8 KB  |  59 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!dhinds
  3. From: dhinds@leland.Stanford.EDU (David Hinds)
  4. Subject: Optimization problem with 3.1 compilers
  5. Message-ID: <1992Aug19.000616.8590@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: DSG, Stanford University, CA 94305, USA
  8. Date: Wed, 19 Aug 92 00:06:16 GMT
  9. Lines: 48
  10.  
  11. I have a program that compiles and executes reliably with the MIPS 2.1
  12. compilers under Irix 4.0.1, but core dumps with a segmentation violation
  13. when a particular function is compiled at -O2 or above with the 3.1
  14. compilers and Irix 4.0.5A.   Here is a short example with the problem:
  15.  
  16. > #include <stdio.h>
  17. > #define MAXP 12
  18. > void main(void)
  19. >   {
  20. >   int *i, *j, step[MAXP+1], k;
  21. >   double sum;
  22. >   float all2[MAXP+1];
  23. >
  24. >   for (k = 0; k < MAXP+1; k++) {
  25. >     step[k] = k; all2[k] = 2.0;
  26. >     }
  27. >
  28. >   sum = 0.0; k = 2;
  29. >   for (i = &step[2]; i <= &step[MAXP]; i++, k++) {
  30. >     printf("k = %d\n", k);
  31. >     for (j = &step[1]; j != i; j++)
  32. >       sum += all2[*j] - 1;
  33. >     }
  34. >   printf("Sum = %f\n", sum);
  35. >   }
  36.  
  37. When I compile this with 'cc -O2 bug.c' and run a.out, I get:
  38.  
  39. > k = 2
  40. > k = 3
  41. > k = 4
  42. > k = 5
  43. > k = 6
  44. > Segmentation fault (core dumped)
  45.  
  46. Compiled -O1, the program runs to completion (k=12).  There are some
  47. funny interactions in the code: if I change 'sum' to float, then the
  48. -O2 code terminates "normally", but at k=7 instead of k=12.  I can't
  49. see anything obviously wrong in the compiler output, but reading MIPS
  50. assembly language gives me a headache.  I'm reasonably confident that
  51. there are no bugs in this code fragment, and the program it is based
  52. on works reliably on several other platforms (including SGI's with
  53. pre-3.1 compilers).
  54.  
  55.         - David Hinds
  56.           dhinds@allegro.stanford.edu
  57.  
  58.