🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Kenneth Almquist Mon, 31 Mar 1986 03:22
Bug in VAX SVR2 C compiler
#291
Author: Kenneth Almquist
Date: Mon, 31 Mar 1986 03:22
54 lines
1585 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads