🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #291

Bug in VAX SVR2 C compiler

#291
From: 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
Technical Details
Message-ID: <384@hropus.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!hropus!ka

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site hropus.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!hropus!ka
From: ka@hropus.UUCP (Kenneth Almquist)
Newsgroups: net.bugs.usg
Subject: Bug in VAX SVR2 C compiler
Message-ID: <384@hropus.UUCP>
Date: Sun, 30-Mar-86 22:22:28 EST
Article-I.D.: hropus.384
Posted: Sun Mar 30 22:22:28 1986
Date-Received: Tue, 1-Apr-86 07:54:55 EST
Organization: Bell Labs, Holmdel, NJ
Lines: 54