9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: haertel@ichips.intel.com haertel@ichips.intel.com
Subject: Plan 9 "8c" compiler bug, with fix.
Date: Wed,  8 Nov 1995 18:52:25 -0500	[thread overview]
Message-ID: <19951108235225.7O-4gpM5lpSKf2CkU1ldUML-lVFr6pdAt998DHvG0VQ@z> (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);
> 		}






             reply	other threads:[~1995-11-08 23:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-11-08 23:52 haertel [this message]
1995-11-09  3:30 dhog

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19951108235225.7O-4gpM5lpSKf2CkU1ldUML-lVFr6pdAt998DHvG0VQ@z \
    --to=haertel@ichips.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).