www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000003

When Created: 06/27/1995 11:21:49
Against DJGPP version: 2.00.beta1
By whom: marks@anomlay.nnc.edu
Abstract: Peculiar optimization flag error
This problem is a bit strange... it only occurs when an optimization
flag (i.e. -O2, -O3...) is set along with the compiler directive
-funroll-loops.  The following code fragment chokes with an 'Abort!'

------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

static unsigned char pts[256];
static float value[256];

void InitNoise()
{
 unsigned char j,k;
 int l;

 printf("Calculating Noise Tables...\n");
 
 for(l=0; l<256; l++)          // Set up look-up lattice
  pts[l]=(unsigned char) l;

 srandom(42);                  // THE magic number
 for(l=0; l<256; l++)          // Generate pseudo-random noise -1 to 1
  value[l]=1.0-2.0*((random()&0x7fffffff)/0x7fffffff);

 for(l=256; l>0; l-=2) {       // Shuffle the lattice
  k=pts[l];
  pts[l]=pts[j=random()%256];
  pts[j]=k; 
 }
 
}
-----------------------------------------------------------------------------

It compiles fine with DJGPPv1.0.  By removing either the
middle loop or the last loop, (or simplifying the middle loop) the problem is
resolved.  Perhaps the code optimizing routines get confused?

Workaround added: 06/27/1995 11:23:26
By whom: marks@anomaly.nnc.edu
This problem can be circumvented if the compiler optimization flag is
not set, or if the -funroll-loops option is not used, or if the
expression in the loop is simplified...

Note added: 07/06/1995 18:37:10
By whom: terra@diku.dk
I could be sleepy, but doesn't that last loop do out-of-bounds
access to the array?  If so, then the behaviour is undefined
and you are lucky to get abort().  [It is not clear to me whether
it is the _compiler_ that does abort().  If it is, then it is
certainly a bug.]

Closed on 07/08/1995 23:38:01: user claims it's a user error, would be gcc bug anyway
By whom: dj@delorie.com



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010