C compiler bug (optimizer), Irix 3.3.1
Mike Gigante
mg at GODZILLA.CGL.RMIT.OZ.AU
Fri May 3 13:49:42 AEST 1991
In the following code:
void
drawbbox(struct bbox bb)
{
float v[7][3];
int i;
/*
* a close enough approximation...
*/
v[0][0] = bb.x1;
v[0][1] = bb.y1;
v[0][2] = bb.z1;
v[1][0] = bb.x2;
v[1][1] = bb.y1;
v[1][2] = bb.z1;
v[2][0] = bb.x2;
v[2][1] = bb.y2;
v[2][2] = bb.z1;
v[3][0] = bb.x1;
v[3][1] = bb.y2;
v[3][2] = bb.z1;
v[4][0] = bb.x1;
v[4][1] = bb.y2;
v[4][2] = bb.z2;
v[5][0] = bb.x2;
v[5][1] = bb.y2;
v[5][2] = bb.z2;
v[6][0] = bb.x2;
v[6][1] = bb.y1;
v[6][2] = bb.z2; (*)
v[7][0] = bb.x1;
v[7][1] = bb.y1;
v[7][2] = bb.z2; (**)
bgnclosedline();
for(i=0; i < 8; i++)
v3f(v[i]);
endclosedline();
}
I get an incorrectly draw bbox. Ok, so I did the following:
bgnclosedline();
for(i=0; i < 8; i++) {
v3f(v[i]);
printf("bbox: %f %f %f\n", v[i][0], v[i][1], v[i][2]);
}
endclosedline();
and lo and behold, it tells me that the Z value for the last point is
wrong while for the second last point, it is correct. A quick look at
the assignment code shows that in both positions, (see * & **), reveals
that this should *not* happen.
The cure was to declare v to be
volatile v[8][3];
and change the v3f call to
v3f((float *)v[i]);
An alternative solution is to use -O0, but that doesn't appeal for other
reasons :-)
Mike Gigante,
ACGC
Royal Melbourne Institute of Technology
More information about the Comp.sys.sgi
mailing list