ka@hropus.UUCP (Kenneth Almquist) (03/31/86)
There is a bug in the optimizing pass of the C compiler. I haven't figured out the cause, but here is a piece of code that will demon- strate it: int flag; int count; getch() { if (--count < 0) { while (flag); count--; } } The loop "while(flag);" is admittedly contrived, but you can get the same effect with a loop that actually does something. Without the optimizer, the generated code is: _fillbuf: .word .R1 jbr .L15 .L16: decl _count jgeq .L17 jbr .L19 .L20: .L19: tstl _flag jneq .L20 .L18: decl _count .L17: ret#0 .set .R1,0x0 .L15: jbr .L16 This is correct, if inefficient, code. However, running it through the C optimizer with the -O option produces: _fillbuf: .word .R1 jbr .L20000 .L19: tstl _flag jneq .L19 .L20000: decl _count ret In its eagerness to speed up the code it completely eliminates the test for count < 0. The while loop (which is compiled into the two statements following .L19) will never be executed. Kenneth Almquist