Skip to content

Commit e074d5e

Browse files
committed
cmd/7g: fix x := a / (-1)
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.
1 parent 6dfc795 commit e074d5e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/cmd/7g/ggen.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ ginscall(Node *f, int proc)
198198
// ARM64 NOP is really HINT $0
199199
// Use the latter form because the NOP pseudo-instruction
200200
// would be removed by the linker.
201-
nodconst(&con, types[TINT], argsize(f->type));
202-
gins(AHINT, &con, N);
201+
nodreg(&reg, types[TINT], D_R0);
202+
gins(AMOV, &reg, &reg);
203203
}
204204
p = gins(ABL, N, f);
205205
afunclit(&p->to, f);
@@ -571,7 +571,8 @@ dodiv(int op, Node *nl, Node *nr, Node *res)
571571
p1 = gbranch(optoas(ONE, t), T, +1);
572572
if(op == ODIV) {
573573
// a / (-1) is -a.
574-
gins(optoas(OMINUS, t), N, &tl);
574+
nodconst(&nz, t, 0);
575+
gins(optoas(OMINUS, t), &nz, &tl);
575576
gmove(&tl, res);
576577
} else {
577578
// a % (-1) is 0.

0 commit comments

Comments
 (0)