home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / gcc / bug / 3130 < prev    next >
Encoding:
Text File  |  1993-01-07  |  3.3 KB  |  130 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!brb.dmt.csiro.au!cjd
  3. From: cjd@brb.dmt.csiro.au (Cameron Davidson)
  4. Subject: apparent bug in GCC 2.2.2 with optimised 486 code.
  5. Message-ID: <9301070552.AA00675@groucho.brb.dmt.csiro.au>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Fri, 8 Jan 1993 01:52:50 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 117
  12.  
  13. GCC 2.2.2 version for DOS (DJGPP ver 1.08, and, I am told, 1.09 also)
  14. GAS 1.38
  15. MS-DOS V5.0 (HIMEM.SYS, no EMM )
  16.  
  17. The sample program below appears to work as expected when not optimised,
  18. or when optimised with -O, but fails when compiled with -O2.
  19. Failure is either:
  20.     1. segmentation fault during assignment of 1.0 when lact == 1, or
  21.     2. the check of initialised data (in verify) reveals that only
  22. matrix elements [0][0] and [1][0] to [1][2] have been set to 1.0,
  23. the remainder still being 0.0.
  24. You should be able to reproduce either form by adding 376 to PADDING
  25. (that value is ( 2 * MAXDIM + 1 ) * sizeof double )
  26.  
  27. I realise the code loop is eccentric to say the least, but I think it comes
  28. from larger code reduced to the simplest form.
  29.  
  30. The cause of the problem appears to be due to the fact that the stack
  31. starts just below 0x80000000 and the matrix begins at around 7fffb600. When
  32. -O2 is used, the pointer value stored in %edi to check for the end of
  33. final row in the loop:
  34.  
  35.     for ( lm=...
  36.  
  37. will eventually exceed 0x80000000. Either than or edi will be close to
  38. 0x7fffff?? and ecx will be incremented from equal to edi to > 0x80000000.
  39. The test for end of loop is:
  40.     cmpl %edi,%ecx
  41.     jle  L27
  42. which I believe is a signed comparison.
  43. By changing the generated assembler source to use JBE instead of JLE the
  44. code then worked.
  45.  
  46.  
  47.  
  48. /*--------------------------  Example code  -----------------------------*/
  49. /*  Compile with                                                   */
  50. /*  gcc -O2 test.c -lm                                             */
  51.  
  52. #include <stdio.h>
  53.  
  54. #ifndef PADDING
  55. #    define PADDING 1
  56. #endif
  57.  
  58. #ifndef MAXDIM
  59. #    define MAXDIM 23
  60. #endif
  61.  
  62. typedef double matrix[2*MAXDIM+1][2*MAXDIM+1];
  63.  
  64. void    verify( matrix morg ),
  65.     runtest( void );
  66.  
  67.  
  68. void main (argc,argv)
  69.  
  70. int argc;
  71. char **argv;
  72.  
  73.    {
  74.    char stack_padding[ PADDING ];
  75.  
  76.    runtest();
  77.    }
  78.  
  79. void runtest( void )
  80.    {
  81.    matrix morg;
  82.    int lact, lm, ln;
  83.  
  84.    printf( "\n matrix starts at %x and is %d(%x) bytes long\n",
  85.         &morg, sizeof morg, sizeof morg );
  86.  
  87.    for (lact=0; lact <= MAXDIM; ++lact)
  88.     {
  89.     printf("\rlact=%5d ",lact); fflush(stdout);
  90.  
  91.     for (lm=0; lm <= 2*lact; ++lm)
  92.         for (ln=0; ln <= 2*lact; ++ln)
  93.             morg[lm][ln] = 1.0;
  94.        }
  95.    verify( morg );
  96.    }
  97.  
  98. void     verify( matrix morg )
  99.    {
  100.    int lm, ln, errcount = 0;
  101.  
  102.    printf( "\ntesting results!\n" );
  103.  
  104.     for (lm=0; lm <= 2*MAXDIM; ++lm)
  105.      {
  106.          for (ln=0; ln <= 2*MAXDIM; ++ln)
  107.        {
  108.            if ( morg[lm][ln] != 1.0)
  109.         {
  110.         printf( "\nmatrix[%3d][%3d] had %.3g ", lm, ln, morg[lm][ln] );
  111.         if ( ++errcount > 10 )
  112.             {
  113.             printf( " I give up\n" );
  114.             return;
  115.             }
  116.         }
  117.  
  118.        }
  119.     }
  120.    }
  121.  
  122. /* --------------  end of example ---------------------------------------*/
  123.  
  124.  
  125. Cameron Davidson,
  126. CSIRO Division of Manufacturing Technology,   Telephone: +61 7 212 4535
  127. Qld Centre for Advanced Technologies,         Facsimile: +61 7 212 4681
  128. 2643 Moggill Rd, Pinjarra Hills, Qld, 4069.   Internet:  cjd@brb.dmt.csiro.au
  129.  
  130.