[gnu.gcc.bug] GCC v 1.28 bug

nuth@WHEATIES.AI.MIT.EDU (Peter Nuth) (09/21/88)

/* Program fail.c - to demonstrate bug in GNU C compiler version 1.28 */
/* by nuth@wheaties.ai.mit.edu */
/* Compile using "gcc fail.c " */
/* Works correctly if you use "gcc -O fail.c" */
/* Compiled on sun-3 in the MIT AI lab. */

/* Generates incorrect assembly code -  */
/*   "gcc -S fail.c" shows this */

struct foober {
  int x;
  struct small *a;
};

struct small {
  int x;
  unsigned char t[50];
  unsigned char d[50];
};

struct foober afoob;
struct small asmall;

int main()
{
  struct foober *m;
  int rt, rd, offset = 12;	/* Assigning chars to ints should work */
  unsigned char nrt;
  m = &afoob;
  m->a = &asmall;
  m->a->t[offset] = 30;
				/* Bug here in code generation */
  rt = (int) m->a->t[offset] ;	/* rt does not get assigned */

  nrt = m->a->t[offset] ;
  printf("rt = %x ", rt);
  printf("nrt = %x ", nrt);
  printf("should be rt = %x\n", m->a->t[offset]) ;
}