Article View: gnu.gcc.bug
Article #1598apparent bug in GCC 2.2.2 with optimised 486 code.
From: Cameron Davidson
Date: Fri, 08 Jan 1993 01:52
Date: Fri, 08 Jan 1993 01:52
116 lines
3502 bytes
3502 bytes
GCC 2.2.2 version for DOS (DJGPP ver 1.08, and, I am told, 1.09 also)
GAS 1.38
MS-DOS V5.0 (HIMEM.SYS, no EMM )
The sample program below appears to work as expected when not optimised,
or when optimised with -O, but fails when compiled with -O2.
Failure is either:
1. segmentation fault during assignment of 1.0 when lact == 1, or
2. the check of initialised data (in verify) reveals that only
matrix elements [0][0] and [1][0] to [1][2] have been set to 1.0,
the remainder still being 0.0.
You should be able to reproduce either form by adding 376 to PADDING
(that value is ( 2 * MAXDIM + 1 ) * sizeof double )
I realise the code loop is eccentric to say the least, but I think it comes
from larger code reduced to the simplest form.
The cause of the problem appears to be due to the fact that the stack
starts just below 0x80000000 and the matrix begins at around 7fffb600. When
-O2 is used, the pointer value stored in %edi to check for the end of
final row in the loop:
for ( lm=...
will eventually exceed 0x80000000. Either than or edi will be close to
0x7fffff?? and ecx will be incremented from equal to edi to > 0x80000000.
The test for end of loop is:
cmpl %edi,%ecx
jle L27
which I believe is a signed comparison.
By changing the generated assembler source to use JBE instead of JLE the
code then worked.
/*-------------------------- Example code -----------------------------*/
/* Compile with */
/* gcc -O2 test.c -lm */
#include <stdio.h>
#ifndef PADDING
# define PADDING 1
#endif
#ifndef MAXDIM
# define MAXDIM 23
#endif
typedef double matrix[2*MAXDIM+1][2*MAXDIM+1];
void verify( matrix morg ),
runtest( void );
void main (argc,argv)
int argc;
char **argv;
{
char stack_padding[ PADDING ];
runtest();
}
void runtest( void )
{
matrix morg;
int lact, lm, ln;
printf( "\n matrix starts at %x and is %d(%x) bytes long\n",
&morg, sizeof morg, sizeof morg );
for (lact=0; lact <= MAXDIM; ++lact)
{
printf("\rlact=%5d ",lact); fflush(stdout);
for (lm=0; lm <= 2*lact; ++lm)
for (ln=0; ln <= 2*lact; ++ln)
morg[lm][ln] = 1.0;
}
verify( morg );
}
void verify( matrix morg )
{
int lm, ln, errcount = 0;
printf( "\ntesting results!\n" );
for (lm=0; lm <= 2*MAXDIM; ++lm)
{
for (ln=0; ln <= 2*MAXDIM; ++ln)
{
if ( morg[lm][ln] != 1.0)
{
printf( "\nmatrix[%3d][%3d] had %.3g ", lm, ln, morg[lm][ln] );
if ( ++errcount > 10 )
{
printf( " I give up\n" );
return;
}
}
}
}
}
/* -------------- end of example ---------------------------------------*/
Cameron Davidson,
CSIRO Division of Manufacturing Technology, Telephone: +61 7 212 4535
Qld Centre for Advanced Technologies, Facsimile: +61 7 212 4681
2643 Moggill Rd, Pinjarra Hills, Qld, 4069. Internet: cjd@brb.dmt.csiro.au
Technical Details
Message-ID:
<9301070552.AA00675@groucho.brb.dmt.csiro.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!brb.dmt.csiro.au!cjdShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!brb.dmt.csiro.au!cjd From: cjd@brb.dmt.csiro.au (Cameron Davidson) Subject: apparent bug in GCC 2.2.2 with optimised 486 code. Message-ID: <9301070552.AA00675@groucho.brb.dmt.csiro.au> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 8 Jan 1993 01:52:50 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 117