9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] mulgen botch
@ 2014-03-20 19:45 cinap_lenrek
  2014-03-20 20:19 ` cinap_lenrek
  0 siblings, 1 reply; 5+ messages in thread
From: cinap_lenrek @ 2014-03-20 19:45 UTC (permalink / raw)
  To: 9fans

multiplication by the constant 0 yields an
"mulgen botch" error in 6c and 8c.

this is probably a very rare case mostly used during debugging...
would this be worth fixing? and if yes, would the fix
below be in the right place?

theres a patch:

--- a/sys/src/cmd/6c/cgen.c	Wed Mar 19 21:15:43 2014 +0100
+++ b/sys/src/cmd/6c/cgen.c	Thu Mar 20 19:59:20 2014 +0100
@@ -309,6 +309,11 @@
 				/* fall thru */
 			case OMUL:
 			case OLMUL:
+				if((o == OMUL || o == OLMUL) && (r->vconst == 0)){
+					cgen(l, Z);
+					zeroregm(nn);
+					goto done;
+				}
 				regalloc(&nod, l, nn);
 				cgen(l, &nod);
 				switch(o) {
@@ -621,6 +626,13 @@
 					reglcgen(&nod2, l, Z);
 				else
 					nod2 = *l;
+				if((o == OASMUL || o == OASLMUL) && (r->vconst == 0)){
+					cgen(&nod2, Z);
+					zeroregm(&nod2);
+					if(nn != Z)
+						zeroregm(nn);
+					goto done;
+				}
 				regalloc(&nod, l, nn);
 				cgen(&nod2, &nod);
 				switch(o) {

test program:

#include <u.h>
#include <libc.h>

int bar(int a)
{
	a *= 0;
	return a;
}
int foo(int a)
{
	return bar(a) * 0;
}

void
main(int argc, char *argv[])
{
	foo(1);
}

--
cinap



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

end of thread, other threads:[~2014-03-20 23:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-20 19:45 [9fans] mulgen botch cinap_lenrek
2014-03-20 20:19 ` cinap_lenrek
2014-03-20 21:50   ` erik quanstrom
2014-03-20 21:54     ` erik quanstrom
2014-03-20 23:10       ` cinap_lenrek

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).