www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/01/07/01:59:39

To: djgpp AT sun DOT soe DOT clarkson DOT edu
Cc: ESCHN705 AT RZ DOT Braunschweig DOT PTB DOT DBP DOT de
Subject: bug in -O2
Date: Thu, 07 Jan 93 16:37:31 +1000
From: Cameron Davidson <cjd AT brb DOT dmt DOT csiro DOT au>

I believe the recently discussed 'intermittent' bug with -O2 is real and always
present, and only the symptoms change from one system to another.
If the segmentation fault does not appear then actually only 4 elements
of the matrix are set to 1.0.
My version of the test code is attached below.

The problem appears to be related to the stack beginning at a mapped address of
about 7FFFFFFF and so the matrix is stored just below this address. When -O2
is used, one of the loop termination tests does a compare of two register
pointers then a JLE, which, according to the only text I can lay my hands on,
is a signed! test. Because of the nature of the optimised code the register
contents end up on either side of the 0x7FFFFFFF and the test either fails
prematurely, or fails to terminate.

Which  of the symptoms occurs depends on the starting address of the
stack frame, which for some mysterious reason is different on my 386/25 and
a 486/33 running the same code!??. It also changes if run under the debugger
so of course my first test program crashed under GO32 but did not
crash under DEBUG32!.

Can anyone suggest why the stack addresses differ from one machine to the next
and what range we could expect in practice?

I have reported this to bug-gcc.


/*-------------------------  example code  -------------------------------*/
**  compile with and without -O2
**  gcc -O2 test.c 
**                                                                        */

#include <stdio.h>

#ifndef PADDING
#	define PADDING 23
#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;
			}
		}

	   }
	}
   }

/*-----------------------------------------------------------------------*/

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 AT brb DOT dmt DOT csiro DOT au

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019