From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Wed, 8 Nov 1995 18:52:25 -0500 From: haertel@ichips.intel.com haertel@ichips.intel.com Subject: Plan 9 "8c" compiler bug, with fix. Topicbox-Message-UUID: 336fffe6-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19951108235225.7O-4gpM5lpSKf2CkU1ldUML-lVFr6pdAt998DHvG0VQ@z> 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 #include 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); > }