[comp.sys.ibm.pc] ** SERIOUS ** bug in MSC 5.1

wampler@unmvax.unm.edu (Bruce Wampler) (06/23/88)

I just discovered a *** SERIOUS *** optimization bug with
MSC 5.1. I think it probably only affects longs inside
of loops when you use loop optimization (-Ol or -Ox).

The following sample code demonstrates the problem. It doesn't
run, you have to look at the generated code to see the problem,
which is obvious if you do.

compile the following using: cl -Ox -Fc -c bug.c
then examine bud.cod.

long nxtchr, *lines;
int curlin;		/* don't know if these have to be globals or not */

  int bug()
  {
    int to;
    int nline;		/* we don't care if these are intialized, we're
			just looking at code */

    nline = curlin;	/* compiler now thinks nline == curlin */
    curlin = to + 1;	/* compiler doesn't seem to make curlin != nline */

    for ( ; nline < curlin ; ++nline)
      {
	*(lines+nline) = nxtchr++; /* generates WRONG code: *(lines+curlin)! */
	/* also bad loop termination since it thinks nline == curlin */
      }
  }

NOTE: this is for MSC 5.1 small model. If you change nxtchr and *lines to
      int, the problem goes away.

Bruce Wampler
... !unmvax!wampler
Reference Software, Inc.
(505) 281-3446