Skip to content

Commit

Permalink
cmd/7g: fix x := a / (-1)
Browse files Browse the repository at this point in the history
Fixes golang#20
Fixes golang#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.
  • Loading branch information
davecheney committed Dec 17, 2014
1 parent 6dfc795 commit e074d5e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cmd/7g/ggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&reg, types[TINT], D_R0);
gins(AMOV, &reg, &reg);
}
p = gins(ABL, N, f);
afunclit(&p->to, f);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e074d5e

Please sign in to comment.