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

Reply via email to