9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Plan 9 "8c" compiler bug, with fix.
@ 1995-11-09  3:30 dhog
  0 siblings, 0 replies; 2+ messages in thread
From: dhog @ 1995-11-09  3:30 UTC (permalink / raw)


>I don't know whether the bug occurs in the other compilers.

I've tried mips and sparc, and they work correctly.






^ permalink raw reply	[flat|nested] 2+ messages in thread

* Plan 9 "8c" compiler bug, with fix.
@ 1995-11-08 23:52 haertel
  0 siblings, 0 replies; 2+ messages in thread
From: haertel @ 1995-11-08 23:52 UTC (permalink / raw)


The "8c" compiler sometimes loses track of side effects in expressions
whose values aren't used.  For example, the following program should
print "1" but in fact prints "0".

I don't know whether the bug occurs in the other compilers.  A proposed
fix is included at the end of this message.  I'm open to alternative
suggestions from people who know the compiler better than me.

The compiler self-bootstraps with the proposed fix installed.

-----beginning of bug example-----
#include <u.h>
#include <libc.h>

int inptr, insize;
char inbuf[100];

void
skipbyte()
{
	/*
	 * Due to a bug in 8c, the side effect to inptr gets lost.
	 */
	(inptr < insize ? inbuf[inptr++] : 0);
}

void
main()
{
	inptr = 0;
	insize = 100;
	skipbyte();
	print("inptr = %d\n", inptr);
}
-----end of bug example-----

Here is a proposed fix, as a diff against the CD-ROM source:

diff /sys/src/cmd/8c/cgen.c 8c/cgen.c
24a25,29
> 		else {
> 			regalloc(&nod, n, Z);
> 			gmove(n, &nod);
> 			regfree(&nod);
> 		}






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-11-09  3:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-11-09  3:30 Plan 9 "8c" compiler bug, with fix dhog
  -- strict thread matches above, loose matches on Subject: below --
1995-11-08 23:52 haertel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).