From e074d5e383d377b284802eaa3d63bd4a809ab8ca Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Wed, 17 Dec 2014 04:13:59 +0000 Subject: [PATCH] cmd/7g: fix x := a / (-1) Fixes #20 Fixes #19 Also includes a fix for the compiler segfault. Minux says that MOV R0, R0 might get eaten by the peep opt, which is probably true, but I'm not sure if the defer magic happens before peep or not. --- src/cmd/7g/ggen.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/7g/ggen.c b/src/cmd/7g/ggen.c index 7ba8d9a68549ac..bfdd6c99202ba1 100644 --- a/src/cmd/7g/ggen.c +++ b/src/cmd/7g/ggen.c @@ -198,8 +198,8 @@ ginscall(Node *f, int proc) // ARM64 NOP is really HINT $0 // Use the latter form because the NOP pseudo-instruction // would be removed by the linker. - nodconst(&con, types[TINT], argsize(f->type)); - gins(AHINT, &con, N); + nodreg(®, types[TINT], D_R0); + gins(AMOV, ®, ®); } p = gins(ABL, N, f); afunclit(&p->to, f); @@ -571,7 +571,8 @@ dodiv(int op, Node *nl, Node *nr, Node *res) p1 = gbranch(optoas(ONE, t), T, +1); if(op == ODIV) { // a / (-1) is -a. - gins(optoas(OMINUS, t), N, &tl); + nodconst(&nz, t, 0); + gins(optoas(OMINUS, t), &nz, &tl); gmove(&tl, res); } else { // a % (-1) is 0.